Re: NOT IN subquery optimization

David Rowley <david.rowley@2ndquadrant.com>

From: David Rowley <david.rowley@2ndquadrant.com>
To: "Li, Zheng" <zhelli@amazon.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>, "Finnerty, Jim" <jfinnert@amazon.com>, PostgreSQL-development <pgsql-hackers@postgresql.org>
Date: 2019-02-27T00:48:08Z
Lists: pgsql-hackers
On Wed, 27 Feb 2019 at 13:41, Li, Zheng <zhelli@amazon.com> wrote:
> We still check for inner side's nullability, when it is nullable we
> append a "var is NULL" to the anti join condition. So every outer
> tuple is going to evaluate to true on the join condition when there
> is indeed a null entry in the inner.

That's possible, at least providing the var is NULL is an OR
condition, but the problem there is that you force the plan into a
nested loop join. That's unfortunately not going to perform very well
when the number of rows to process is large.

-- 
 David Rowley                   http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services


Commits

  1. Check we don't misoptimize a NOT IN where the subquery returns no rows.