File tree Expand file tree Collapse file tree 3 files changed +63
-3
lines changed Expand file tree Collapse file tree 3 files changed +63
-3
lines changed Original file line number Diff line number Diff line change @@ -694,9 +694,9 @@ make_outerjoininfo(PlannerInfo *root,
694
694
* For a lower OJ in our RHS, if our join condition does not use the
695
695
* lower join's RHS and the lower OJ's join condition is strict, we
696
696
* can interchange the ordering of the two OJs; otherwise we must add
697
- * lower OJ's full syntactic relset to min_righthand. Here , we must
698
- * preserve ordering anyway if either the current join is a semijoin,
699
- * or the lower OJ is either a semijoin or an antijoin.
697
+ * the lower OJ's full syntactic relset to min_righthand. Also , we
698
+ * must preserve ordering anyway if either the current join or the
699
+ * lower OJ is either a semijoin or an antijoin.
700
700
*
701
701
* Here, we have to consider that "our join condition" includes any
702
702
* clauses that syntactically appeared above the lower OJ and below
@@ -713,6 +713,7 @@ make_outerjoininfo(PlannerInfo *root,
713
713
{
714
714
if (bms_overlap (clause_relids , otherinfo -> syn_righthand ) ||
715
715
jointype == JOIN_SEMI ||
716
+ jointype == JOIN_ANTI ||
716
717
otherinfo -> jointype == JOIN_SEMI ||
717
718
otherinfo -> jointype == JOIN_ANTI ||
718
719
!otherinfo -> lhs_strict || otherinfo -> delay_upper_joins )
Original file line number Diff line number Diff line change @@ -2277,6 +2277,48 @@ WHERE d.f1 IS NULL;
2277
2277
9999
2278
2278
(3 rows)
2279
2279
2280
+ --
2281
+ -- regression test for proper handling of outer joins within antijoins
2282
+ --
2283
+ create temp table tt4x(c1 int, c2 int, c3 int);
2284
+ explain (costs off)
2285
+ select * from tt4x t1
2286
+ where not exists (
2287
+ select 1 from tt4x t2
2288
+ left join tt4x t3 on t2.c3 = t3.c1
2289
+ left join ( select t5.c1 as c1
2290
+ from tt4x t4 left join tt4x t5 on t4.c2 = t5.c1
2291
+ ) a1 on t3.c2 = a1.c1
2292
+ where t1.c1 = t2.c2
2293
+ );
2294
+ QUERY PLAN
2295
+ ---------------------------------------------------------
2296
+ Hash Anti Join
2297
+ Hash Cond: (t1.c1 = t2.c2)
2298
+ -> Seq Scan on tt4x t1
2299
+ -> Hash
2300
+ -> Merge Right Join
2301
+ Merge Cond: (t5.c1 = t3.c2)
2302
+ -> Merge Join
2303
+ Merge Cond: (t4.c2 = t5.c1)
2304
+ -> Sort
2305
+ Sort Key: t4.c2
2306
+ -> Seq Scan on tt4x t4
2307
+ -> Sort
2308
+ Sort Key: t5.c1
2309
+ -> Seq Scan on tt4x t5
2310
+ -> Sort
2311
+ Sort Key: t3.c2
2312
+ -> Merge Left Join
2313
+ Merge Cond: (t2.c3 = t3.c1)
2314
+ -> Sort
2315
+ Sort Key: t2.c3
2316
+ -> Seq Scan on tt4x t2
2317
+ -> Sort
2318
+ Sort Key: t3.c1
2319
+ -> Seq Scan on tt4x t3
2320
+ (24 rows)
2321
+
2280
2322
--
2281
2323
-- regression test for problems of the sort depicted in bug #3494
2282
2324
--
Original file line number Diff line number Diff line change @@ -443,6 +443,23 @@ LEFT JOIN (
443
443
) AS d ON (a .f1 = d .f1 )
444
444
WHERE d .f1 IS NULL ;
445
445
446
+ --
447
+ -- regression test for proper handling of outer joins within antijoins
448
+ --
449
+
450
+ create temp table tt4x(c1 int , c2 int , c3 int );
451
+
452
+ explain (costs off)
453
+ select * from tt4x t1
454
+ where not exists (
455
+ select 1 from tt4x t2
456
+ left join tt4x t3 on t2 .c3 = t3 .c1
457
+ left join ( select t5 .c1 as c1
458
+ from tt4x t4 left join tt4x t5 on t4 .c2 = t5 .c1
459
+ ) a1 on t3 .c2 = a1 .c1
460
+ where t1 .c1 = t2 .c2
461
+ );
462
+
446
463
--
447
464
-- regression test for problems of the sort depicted in bug #3494
448
465
--
You can’t perform that action at this time.
0 commit comments