Re: Allowing NOT IN to use ANTI joins - Mailing list pgsql-hackers

From Marti Raudsepp
Subject Re: Allowing NOT IN to use ANTI joins
Date
Msg-id CABRT9RDtE+E0=VWm_aFvhfaQ1R+g54OOxs85y+KeYEgQmuYgWQ@mail.gmail.com
Whole thread Raw
In response to Allowing NOT IN to use ANTI joins  (David Rowley <dgrowleyml@gmail.com>)
Responses Re: Allowing NOT IN to use ANTI joins  (David Rowley <dgrowleyml@gmail.com>)
Re: Allowing NOT IN to use ANTI joins  (David Rowley <dgrowleyml@gmail.com>)
List pgsql-hackers
On Sun, Jun 8, 2014 at 3:36 PM, David Rowley <dgrowleyml@gmail.com> wrote:
> Currently pull_up_sublinks_qual_recurse only changes the plan for NOT EXISTS
> queries and leaves NOT IN alone. The reason for this is because the values
> returned by a subquery in the IN clause could have NULLs.

There's a bug in targetListIsGuaranteedNotToHaveNulls, you have to
drill deeper into the query to guarantee the nullability of a result
column. If a table is OUTER JOINed, it can return NULLs even if the
original column specification has NOT NULL.

This test case produces incorrect results with your patch:

create table a (x int not null);
create table b (x int not null, y int not null);
insert into a values(1);
select * from a where x not in (select y from a left join b using (x));

Unpatched version correctly returns 0 rows since "y" will be NULL.
Your patch returns the value 1 from a.

Regards,
Marti



pgsql-hackers by date:

Previous
From: Marti Raudsepp
Date:
Subject: Re: Allowing NOT IN to use ANTI joins
Next
From: David Rowley
Date:
Subject: Re: Allowing NOT IN to use ANTI joins