]> granicus.if.org Git - postgresql/commitdiff
Check we don't misoptimize a NOT IN where the subquery returns no rows.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 1 Mar 2019 22:57:20 +0000 (17:57 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 1 Mar 2019 22:57:20 +0000 (17:57 -0500)
Future-proofing against a common mistake in attempts to optimize NOT IN.
We don't have such an optimization right now, but attempts to do so
are in the works, and some of 'em are buggy.  Add a regression test case
covering the point.

David Rowley

Discussion: https://postgr.es/m/CAKJS1f90E9agVZryVyUpbHQbjTt5ExqS2Fsodmt5_A7E_cEyVA@mail.gmail.com

src/test/regress/expected/subselect.out
src/test/regress/sql/subselect.sql

index cc3f5f3737d528ced05d3c787aee15cbe4abc5ed..fe5fc6448032e1239f1862d9eabb7d293b1287bb 100644 (file)
@@ -830,6 +830,19 @@ explain (verbose, costs off)
                  One-Time Filter: ("*VALUES*".column1 = "*VALUES*".column1)
 (8 rows)
 
+--
+-- Check we don't misoptimize a NOT IN where the subquery returns no rows.
+--
+create temp table notinouter (a int);
+create temp table notininner (b int not null);
+insert into notinouter values (null), (1);
+select * from notinouter where a not in (select b from notininner);
+ a 
+---
+  
+ 1
+(2 rows)
+
 --
 -- Check we behave sanely in corner case of empty SELECT list (bug #8648)
 --
index 8bca1f5d55ef8772b38a42e775b35575f936ef0d..b5931ee700e41d187ebbb97050ce9922bc80fee1 100644 (file)
@@ -466,6 +466,15 @@ explain (verbose, costs off)
   select x, x from
     (select (select random() where y=y) as x from (values(1),(2)) v(y)) ss;
 
+--
+-- Check we don't misoptimize a NOT IN where the subquery returns no rows.
+--
+create temp table notinouter (a int);
+create temp table notininner (b int not null);
+insert into notinouter values (null), (1);
+
+select * from notinouter where a not in (select b from notininner);
+
 --
 -- Check we behave sanely in corner case of empty SELECT list (bug #8648)
 --