@@ -286,8 +286,9 @@ add_paths_to_joinrel(PlannerInfo *root,
286286 * 2. Consider paths where the outer relation need not be explicitly
287287 * sorted. This includes both nestloops and mergejoins where the outer
288288 * path is already ordered. Again, skip this if we can't mergejoin.
289- * (That's okay because we know that nestloop can't handle right/full
290- * joins at all, so it wouldn't work in the prohibited cases either.)
289+ * (That's okay because we know that nestloop can't handle
290+ * right/right-anti/full joins at all, so it wouldn't work in the
291+ * prohibited cases either.)
291292 */
292293 if (mergejoin_allowed )
293294 match_unsorted_outer (root , joinrel , outerrel , innerrel ,
@@ -1261,14 +1262,15 @@ sort_inner_and_outer(PlannerInfo *root,
12611262 * If the joinrel is parallel-safe, we may be able to consider a partial
12621263 * merge join. However, we can't handle JOIN_UNIQUE_OUTER, because the
12631264 * outer path will be partial, and therefore we won't be able to properly
1264- * guarantee uniqueness. Similarly, we can't handle JOIN_FULL and
1265- * JOIN_RIGHT , because they can produce false null extended rows. Also,
1266- * the resulting path must not be parameterized.
1265+ * guarantee uniqueness. Similarly, we can't handle JOIN_FULL, JOIN_RIGHT
1266+ * and JOIN_RIGHT_ANTI , because they can produce false null extended rows.
1267+ * Also, the resulting path must not be parameterized.
12671268 */
12681269 if (joinrel -> consider_parallel &&
12691270 save_jointype != JOIN_UNIQUE_OUTER &&
12701271 save_jointype != JOIN_FULL &&
12711272 save_jointype != JOIN_RIGHT &&
1273+ save_jointype != JOIN_RIGHT_ANTI &&
12721274 outerrel -> partial_pathlist != NIL &&
12731275 bms_is_empty (joinrel -> lateral_relids ))
12741276 {
@@ -1663,10 +1665,10 @@ match_unsorted_outer(PlannerInfo *root,
16631665
16641666 /*
16651667 * Nestloop only supports inner, left, semi, and anti joins. Also, if we
1666- * are doing a right or full mergejoin, we must use *all* the mergeclauses
1667- * as join clauses, else we will not have a valid plan. (Although these
1668- * two flags are currently inverses, keep them separate for clarity and
1669- * possible future changes.)
1668+ * are doing a right, right-anti or full mergejoin, we must use *all* the
1669+ * mergeclauses as join clauses, else we will not have a valid plan.
1670+ * (Although these two flags are currently inverses, keep them separate
1671+ * for clarity and possible future changes.)
16701672 */
16711673 switch (jointype )
16721674 {
@@ -1678,6 +1680,7 @@ match_unsorted_outer(PlannerInfo *root,
16781680 useallclauses = false;
16791681 break ;
16801682 case JOIN_RIGHT :
1683+ case JOIN_RIGHT_ANTI :
16811684 case JOIN_FULL :
16821685 nestjoinOK = false;
16831686 useallclauses = true;
@@ -1849,13 +1852,14 @@ match_unsorted_outer(PlannerInfo *root,
18491852 * handle JOIN_UNIQUE_OUTER, because the outer path will be partial, and
18501853 * therefore we won't be able to properly guarantee uniqueness. Nor can
18511854 * we handle joins needing lateral rels, since partial paths must not be
1852- * parameterized. Similarly, we can't handle JOIN_FULL and JOIN_RIGHT,
1853- * because they can produce false null extended rows.
1855+ * parameterized. Similarly, we can't handle JOIN_FULL, JOIN_RIGHT and
1856+ * JOIN_RIGHT_ANTI, because they can produce false null extended rows.
18541857 */
18551858 if (joinrel -> consider_parallel &&
18561859 save_jointype != JOIN_UNIQUE_OUTER &&
18571860 save_jointype != JOIN_FULL &&
18581861 save_jointype != JOIN_RIGHT &&
1862+ save_jointype != JOIN_RIGHT_ANTI &&
18591863 outerrel -> partial_pathlist != NIL &&
18601864 bms_is_empty (joinrel -> lateral_relids ))
18611865 {
@@ -2228,11 +2232,13 @@ hash_inner_and_outer(PlannerInfo *root,
22282232 * total inner path will also be parallel-safe, but if not, we'll
22292233 * have to search for the cheapest safe, unparameterized inner
22302234 * path. If doing JOIN_UNIQUE_INNER, we can't use any alternative
2231- * inner path. If full or right join, we can't use parallelism
2232- * (building the hash table in each backend) because no one
2233- * process has all the match bits.
2235+ * inner path. If full, right, or right-anti join, we can't use
2236+ * parallelism (building the hash table in each backend) because
2237+ * no one process has all the match bits.
22342238 */
2235- if (save_jointype == JOIN_FULL || save_jointype == JOIN_RIGHT )
2239+ if (save_jointype == JOIN_FULL ||
2240+ save_jointype == JOIN_RIGHT ||
2241+ save_jointype == JOIN_RIGHT_ANTI )
22362242 cheapest_safe_inner = NULL ;
22372243 else if (cheapest_total_inner -> parallel_safe )
22382244 cheapest_safe_inner = cheapest_total_inner ;
@@ -2256,10 +2262,10 @@ hash_inner_and_outer(PlannerInfo *root,
22562262 * Returns a list of RestrictInfo nodes for those clauses.
22572263 *
22582264 * *mergejoin_allowed is normally set to true, but it is set to false if
2259- * this is a right/full join and there are nonmergejoinable join clauses.
2260- * The executor's mergejoin machinery cannot handle such cases, so we have
2261- * to avoid generating a mergejoin plan. (Note that this flag does NOT
2262- * consider whether there are actually any mergejoinable clauses. This is
2265+ * this is a right/right-anti/ full join and there are nonmergejoinable join
2266+ * clauses. The executor's mergejoin machinery cannot handle such cases, so
2267+ * we have to avoid generating a mergejoin plan. (Note that this flag does
2268+ * NOT consider whether there are actually any mergejoinable clauses. This is
22632269 * correct because in some cases we need to build a clauseless mergejoin.
22642270 * Simply returning NIL is therefore not enough to distinguish safe from
22652271 * unsafe cases.)
@@ -2305,8 +2311,8 @@ select_mergejoin_clauses(PlannerInfo *root,
23052311 {
23062312 /*
23072313 * The executor can handle extra joinquals that are constants, but
2308- * not anything else, when doing right/full merge join. (The
2309- * reason to support constants is so we can do FULL JOIN ON
2314+ * not anything else, when doing right/right-anti/ full merge join.
2315+ * (The reason to support constants is so we can do FULL JOIN ON
23102316 * FALSE.)
23112317 */
23122318 if (!restrictinfo -> clause || !IsA (restrictinfo -> clause , Const ))
@@ -2349,6 +2355,7 @@ select_mergejoin_clauses(PlannerInfo *root,
23492355 switch (jointype )
23502356 {
23512357 case JOIN_RIGHT :
2358+ case JOIN_RIGHT_ANTI :
23522359 case JOIN_FULL :
23532360 * mergejoin_allowed = !have_nonmergeable_joinclause ;
23542361 break ;
0 commit comments