Since 383eb21 conversion planner can change query results when the
uncorrelated RHS subquery has a volatile filter and the join plan
rescans that side.

Repro:


CREATE TABLE notin_volatile_outer (a int NOT NULL);
INSERT INTO notin_volatile_outer VALUES (1), (2), (3);
CREATE TABLE notin_volatile_inner (v int NOT NULL);
INSERT INTO notin_volatile_inner VALUES (2);
CREATE SEQUENCE notin_volatile_seq START 1;

SET enable_hashjoin = off;
SET enable_mergejoin = off;
SET enable_material = off;

SELECT array_agg(a ORDER BY a)
FROM notin_volatile_outer
WHERE a NOT IN
  (SELECT v FROM notin_volatile_inner
   WHERE nextval('notin_volatile_seq') % 3 <> 1);

SELECT last_value, is_called FROM notin_volatile_seq;

On master, query returns {1,3} and advances the sequence to 3.

Attached reject convert_ANY_sublink_to_join conversion if sublink
contains volatile functions.




-- 
Best regards,
Kirill Reshke

Attachment: fix-notin-volatile-source.patch
Description: Binary data

Reply via email to