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 @@ -1165,9 +1165,9 @@ make_outerjoininfo(PlannerInfo *root,
11651165 * For a lower OJ in our RHS, if our join condition does not use the
11661166 * lower join's RHS and the lower OJ's join condition is strict, we
11671167 * can interchange the ordering of the two OJs; otherwise we must add
1168- * lower OJ's full syntactic relset to min_righthand. Here , we must
1169- * preserve ordering anyway if either the current join is a semijoin,
1170- * or the lower OJ is either a semijoin or an antijoin.
1168+ * the lower OJ's full syntactic relset to min_righthand. Also , we
1169+ * must preserve ordering anyway if either the current join or the
1170+ * lower OJ is either a semijoin or an antijoin.
11711171 *
11721172 * Here, we have to consider that "our join condition" includes any
11731173 * clauses that syntactically appeared above the lower OJ and below
@@ -1184,6 +1184,7 @@ make_outerjoininfo(PlannerInfo *root,
11841184 {
11851185 if (bms_overlap (clause_relids , otherinfo -> syn_righthand ) ||
11861186 jointype == JOIN_SEMI ||
1187+ jointype == JOIN_ANTI ||
11871188 otherinfo -> jointype == JOIN_SEMI ||
11881189 otherinfo -> jointype == JOIN_ANTI ||
11891190 !otherinfo -> lhs_strict || otherinfo -> delay_upper_joins )
Original file line number Diff line number Diff line change @@ -2283,6 +2283,48 @@ WHERE d.f1 IS NULL;
22832283 9999
22842284(3 rows)
22852285
2286+ --
2287+ -- regression test for proper handling of outer joins within antijoins
2288+ --
2289+ create temp table tt4x(c1 int, c2 int, c3 int);
2290+ explain (costs off)
2291+ select * from tt4x t1
2292+ where not exists (
2293+ select 1 from tt4x t2
2294+ left join tt4x t3 on t2.c3 = t3.c1
2295+ left join ( select t5.c1 as c1
2296+ from tt4x t4 left join tt4x t5 on t4.c2 = t5.c1
2297+ ) a1 on t3.c2 = a1.c1
2298+ where t1.c1 = t2.c2
2299+ );
2300+ QUERY PLAN
2301+ ---------------------------------------------------------
2302+ Hash Anti Join
2303+ Hash Cond: (t1.c1 = t2.c2)
2304+ -> Seq Scan on tt4x t1
2305+ -> Hash
2306+ -> Merge Right Join
2307+ Merge Cond: (t5.c1 = t3.c2)
2308+ -> Merge Join
2309+ Merge Cond: (t4.c2 = t5.c1)
2310+ -> Sort
2311+ Sort Key: t4.c2
2312+ -> Seq Scan on tt4x t4
2313+ -> Sort
2314+ Sort Key: t5.c1
2315+ -> Seq Scan on tt4x t5
2316+ -> Sort
2317+ Sort Key: t3.c2
2318+ -> Merge Left Join
2319+ Merge Cond: (t2.c3 = t3.c1)
2320+ -> Sort
2321+ Sort Key: t2.c3
2322+ -> Seq Scan on tt4x t2
2323+ -> Sort
2324+ Sort Key: t3.c1
2325+ -> Seq Scan on tt4x t3
2326+ (24 rows)
2327+
22862328--
22872329-- regression test for problems of the sort depicted in bug #3494
22882330--
Original file line number Diff line number Diff line change @@ -447,6 +447,23 @@ LEFT JOIN (
447447) AS d ON (a .f1 = d .f1 )
448448WHERE d .f1 IS NULL ;
449449
450+ --
451+ -- regression test for proper handling of outer joins within antijoins
452+ --
453+
454+ create temp table tt4x(c1 int , c2 int , c3 int );
455+
456+ explain (costs off)
457+ select * from tt4x t1
458+ where not exists (
459+ select 1 from tt4x t2
460+ left join tt4x t3 on t2 .c3 = t3 .c1
461+ left join ( select t5 .c1 as c1
462+ from tt4x t4 left join tt4x t5 on t4 .c2 = t5 .c1
463+ ) a1 on t3 .c2 = a1 .c1
464+ where t1 .c1 = t2 .c2
465+ );
466+
450467--
451468-- regression test for problems of the sort depicted in bug #3494
452469--
You can’t perform that action at this time.
0 commit comments