File tree 3 files changed +63
-3
lines changed 3 files changed +63
-3
lines changed Original file line number Diff line number Diff line change @@ -1162,9 +1162,9 @@ make_outerjoininfo(PlannerInfo *root,
1162
1162
* For a lower OJ in our RHS, if our join condition does not use the
1163
1163
* lower join's RHS and the lower OJ's join condition is strict, we
1164
1164
* can interchange the ordering of the two OJs; otherwise we must add
1165
- * lower OJ's full syntactic relset to min_righthand. Here , we must
1166
- * preserve ordering anyway if either the current join is a semijoin,
1167
- * or the lower OJ is either a semijoin or an antijoin.
1165
+ * the lower OJ's full syntactic relset to min_righthand. Also , we
1166
+ * must preserve ordering anyway if either the current join or the
1167
+ * lower OJ is either a semijoin or an antijoin.
1168
1168
*
1169
1169
* Here, we have to consider that "our join condition" includes any
1170
1170
* clauses that syntactically appeared above the lower OJ and below
@@ -1181,6 +1181,7 @@ make_outerjoininfo(PlannerInfo *root,
1181
1181
{
1182
1182
if (bms_overlap (clause_relids , otherinfo -> syn_righthand ) ||
1183
1183
jointype == JOIN_SEMI ||
1184
+ jointype == JOIN_ANTI ||
1184
1185
otherinfo -> jointype == JOIN_SEMI ||
1185
1186
otherinfo -> jointype == JOIN_ANTI ||
1186
1187
!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