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 @@ -680,9 +680,9 @@ make_outerjoininfo(PlannerInfo *root,
680680 * For a lower OJ in our RHS, if our join condition does not use the
681681 * lower join's RHS and the lower OJ's join condition is strict, we
682682 * can interchange the ordering of the two OJs; otherwise we must add
683- * lower OJ's full syntactic relset to min_righthand. Here , we must
684- * preserve ordering anyway if either the current join is a semijoin,
685- * or the lower OJ is either a semijoin or an antijoin.
683+ * the lower OJ's full syntactic relset to min_righthand. Also , we
684+ * must preserve ordering anyway if either the current join or the
685+ * lower OJ is either a semijoin or an antijoin.
686686 *
687687 * Here, we have to consider that "our join condition" includes any
688688 * clauses that syntactically appeared above the lower OJ and below
@@ -699,6 +699,7 @@ make_outerjoininfo(PlannerInfo *root,
699699 {
700700 if (bms_overlap (clause_relids , otherinfo -> syn_righthand ) ||
701701 jointype == JOIN_SEMI ||
702+ jointype == JOIN_ANTI ||
702703 otherinfo -> jointype == JOIN_SEMI ||
703704 otherinfo -> jointype == JOIN_ANTI ||
704705 !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;
22772277 9999
22782278(3 rows)
22792279
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+
22802322--
22812323-- regression test for problems of the sort depicted in bug #3494
22822324--
Original file line number Diff line number Diff line change @@ -443,6 +443,23 @@ LEFT JOIN (
443443) AS d ON (a .f1 = d .f1 )
444444WHERE d .f1 IS NULL ;
445445
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+
446463--
447464-- regression test for problems of the sort depicted in bug #3494
448465--
You can’t perform that action at this time.
0 commit comments