@@ -286,8 +286,9 @@ add_paths_to_joinrel(PlannerInfo *root,
286
286
* 2. Consider paths where the outer relation need not be explicitly
287
287
* sorted. This includes both nestloops and mergejoins where the outer
288
288
* 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.)
291
292
*/
292
293
if (mergejoin_allowed )
293
294
match_unsorted_outer (root , joinrel , outerrel , innerrel ,
@@ -1261,14 +1262,15 @@ sort_inner_and_outer(PlannerInfo *root,
1261
1262
* If the joinrel is parallel-safe, we may be able to consider a partial
1262
1263
* merge join. However, we can't handle JOIN_UNIQUE_OUTER, because the
1263
1264
* 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.
1267
1268
*/
1268
1269
if (joinrel -> consider_parallel &&
1269
1270
save_jointype != JOIN_UNIQUE_OUTER &&
1270
1271
save_jointype != JOIN_FULL &&
1271
1272
save_jointype != JOIN_RIGHT &&
1273
+ save_jointype != JOIN_RIGHT_ANTI &&
1272
1274
outerrel -> partial_pathlist != NIL &&
1273
1275
bms_is_empty (joinrel -> lateral_relids ))
1274
1276
{
@@ -1663,10 +1665,10 @@ match_unsorted_outer(PlannerInfo *root,
1663
1665
1664
1666
/*
1665
1667
* 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.)
1670
1672
*/
1671
1673
switch (jointype )
1672
1674
{
@@ -1678,6 +1680,7 @@ match_unsorted_outer(PlannerInfo *root,
1678
1680
useallclauses = false;
1679
1681
break ;
1680
1682
case JOIN_RIGHT :
1683
+ case JOIN_RIGHT_ANTI :
1681
1684
case JOIN_FULL :
1682
1685
nestjoinOK = false;
1683
1686
useallclauses = true;
@@ -1849,13 +1852,14 @@ match_unsorted_outer(PlannerInfo *root,
1849
1852
* handle JOIN_UNIQUE_OUTER, because the outer path will be partial, and
1850
1853
* therefore we won't be able to properly guarantee uniqueness. Nor can
1851
1854
* 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.
1854
1857
*/
1855
1858
if (joinrel -> consider_parallel &&
1856
1859
save_jointype != JOIN_UNIQUE_OUTER &&
1857
1860
save_jointype != JOIN_FULL &&
1858
1861
save_jointype != JOIN_RIGHT &&
1862
+ save_jointype != JOIN_RIGHT_ANTI &&
1859
1863
outerrel -> partial_pathlist != NIL &&
1860
1864
bms_is_empty (joinrel -> lateral_relids ))
1861
1865
{
@@ -2228,11 +2232,13 @@ hash_inner_and_outer(PlannerInfo *root,
2228
2232
* total inner path will also be parallel-safe, but if not, we'll
2229
2233
* have to search for the cheapest safe, unparameterized inner
2230
2234
* 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.
2234
2238
*/
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 )
2236
2242
cheapest_safe_inner = NULL ;
2237
2243
else if (cheapest_total_inner -> parallel_safe )
2238
2244
cheapest_safe_inner = cheapest_total_inner ;
@@ -2256,10 +2262,10 @@ hash_inner_and_outer(PlannerInfo *root,
2256
2262
* Returns a list of RestrictInfo nodes for those clauses.
2257
2263
*
2258
2264
* *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
2263
2269
* correct because in some cases we need to build a clauseless mergejoin.
2264
2270
* Simply returning NIL is therefore not enough to distinguish safe from
2265
2271
* unsafe cases.)
@@ -2305,8 +2311,8 @@ select_mergejoin_clauses(PlannerInfo *root,
2305
2311
{
2306
2312
/*
2307
2313
* 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
2310
2316
* FALSE.)
2311
2317
*/
2312
2318
if (!restrictinfo -> clause || !IsA (restrictinfo -> clause , Const ))
@@ -2349,6 +2355,7 @@ select_mergejoin_clauses(PlannerInfo *root,
2349
2355
switch (jointype )
2350
2356
{
2351
2357
case JOIN_RIGHT :
2358
+ case JOIN_RIGHT_ANTI :
2352
2359
case JOIN_FULL :
2353
2360
* mergejoin_allowed = !have_nonmergeable_joinclause ;
2354
2361
break ;
0 commit comments