Skip to content

Commit 4328d2f

Browse files
author
kongfanshen
committed
Adapt "Right Semi Join" backport for Apache Cloudberry MPP
This commit carries the Cloudberry/Greenplum-specific changes needed on top of the two cherry-picked upstream commits (aa86129, 5668a85), which only touch the upstream PostgreSQL planner/executor files. - nodes.h: move JOIN_RIGHT_SEMI to the END of the JoinType enum. Upstream places it next to JOIN_RIGHT_ANTI, but in the Cloudberry tree that shifts the integer values of the GPDB-specific JOIN_DEDUP_SEMI/REVERSE and JOIN_UNIQUE_* codes. Value-dependent code then corrupts MPP motion planning, producing a degenerate plan ("Gather Motion 0:1" / "Redistribute Motion 1:0") that crashes with SIGSEGV in setupCdbProcessList() during dispatch. Appending keeps every pre-existing enum value stable. - cdbpath.c (cdbpath_motion_for_join, both the serial and parallel switch): handle JOIN_RIGHT_SEMI like JOIN_RIGHT/JOIN_RIGHT_ANTI. A right-semi join emits inner (build-side) rows, so the inner side must not be replicated, otherwise matched inner rows could be emitted more than once. Without this the new join type would hit the switch default and elog(ERROR, "unexpected join type") at plan time. Note: this feature is only exercised by the PostgreSQL planner (optimizer=off); GPORCA does not generate JOIN_RIGHT_SEMI.
1 parent e810621 commit 4328d2f

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

src/backend/cdb/cdbpath.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1469,7 +1469,13 @@ cdbpath_motion_for_join(PlannerInfo *root,
14691469
outer.ok_to_replicate = false;
14701470
break;
14711471
case JOIN_RIGHT:
1472+
case JOIN_RIGHT_SEMI:
14721473
case JOIN_RIGHT_ANTI:
1474+
/*
1475+
* GPDB: A right-semi join emits inner (build-side) rows, so just
1476+
* like JOIN_RIGHT/JOIN_RIGHT_ANTI the inner side must not be
1477+
* replicated, or matched inner rows could be emitted more than once.
1478+
*/
14731479
inner.ok_to_replicate = false;
14741480
break;
14751481
case JOIN_FULL:
@@ -3220,6 +3226,7 @@ cdbpath_motion_for_parallel_join(PlannerInfo *root,
32203226
case JOIN_UNIQUE_OUTER:
32213227
case JOIN_UNIQUE_INNER:
32223228
case JOIN_RIGHT:
3229+
case JOIN_RIGHT_SEMI:
32233230
case JOIN_RIGHT_ANTI:
32243231
case JOIN_FULL:
32253232
outer.ok_to_replicate = false;

src/include/nodes/nodes.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,6 @@ typedef enum JoinType
10261026
JOIN_LASJ_NOTIN, /* Left Anti Semi Join with Not-In semantics:
10271027
If any NULL values are produced by inner side,
10281028
return no join results. Otherwise, same as LASJ */
1029-
JOIN_RIGHT_SEMI, /* 1 copy of each RHS row that has match(es) */
10301029
JOIN_RIGHT_ANTI, /* 1 copy of each RHS row that has no match */
10311030

10321031
/*
@@ -1046,7 +1045,19 @@ typedef enum JoinType
10461045
* moving the larger of the two relations.
10471046
*/
10481047
JOIN_DEDUP_SEMI, /* inner join, LHS path must be made unique afterwards */
1049-
JOIN_DEDUP_SEMI_REVERSE /* inner join, RHS path must be made unique afterwards */
1048+
JOIN_DEDUP_SEMI_REVERSE, /* inner join, RHS path must be made unique afterwards */
1049+
1050+
/*
1051+
* JOIN_RIGHT_SEMI (backported from upstream commit aa86129e1) is an
1052+
* executor-supported join type, but it is deliberately placed at the END
1053+
* of this enum rather than next to JOIN_RIGHT_ANTI where upstream puts it.
1054+
* Inserting it in the middle would shift the integer values of the
1055+
* GPDB-specific JOIN_DEDUP_SEMI/REVERSE (and JOIN_UNIQUE_*) codes, which
1056+
* breaks value-dependent code elsewhere and corrupts MPP motion planning
1057+
* (observed as a SIGSEGV during dispatch on semijoins over non-partitioned
1058+
* loci). Appending here keeps every pre-existing value stable.
1059+
*/
1060+
JOIN_RIGHT_SEMI /* 1 copy of each RHS row that has match(es) */
10501061

10511062
/*
10521063
* We might need additional join types someday.

0 commit comments

Comments
 (0)