[SPARK-57648][SQL] Spread unmatchable left outer join rows across shuffle partitions#56719
Draft
sunchao wants to merge 1 commit into
Draft
[SPARK-57648][SQL] Spread unmatchable left outer join rows across shuffle partitions#56719sunchao wants to merge 1 commit into
sunchao wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why are the changes needed?
A shuffled
LEFT OUTERequi-join can retain a residualONpredicate that references only the preserved left input:Rows where
l.eligibleis false or null cannot match any right-side row, but the join must still emit them as unmatched rows. Spark currently shuffles only byk, so a common non-null key can funnel all such rows into one reducer even though they do not need to be co-located.This addresses SPARK-57648.
What changes were proposed in this PR?
For shuffled left outer joins, when
spark.sql.shuffle.spreadNullJoinKeys.enabledis enabled, this PR recognizes a conservative subset of deterministic residual predicates that reference only the left input.For eligible joins it appends a physical guard key:
IF(residual_condition, TRUE, NULL)TRUERows for which the residual is true retain normal hash co-location. Rows for which it is false or null receive a null guard and use the existing
NullAwareHashPartitioningpath, allowing them to spread across reducers. The original residual remains on the join.A tag on the synthetic guard makes the shuffled join require every physical join key, preventing an existing partitioning on only the original equi-join keys from bypassing the guard. Ordinary null-aware joins keep their existing distribution behavior.
How was this PR tested?
./build/sbt "sql/testOnly org.apache.spark.sql.JoinSuite -- -z SPARK-57648"— 3 tests passed../build/sbt "sql/testOnly org.apache.spark.sql.connector.KeyGroupedPartitioningSuite -- -z SPARK-42038"— 9 tests passed../build/sbt "sql/testOnly org.apache.spark.sql.execution.joins.OuterJoinSuite -- -z ordinary"— 8 tests passed../build/sbt "sql/testOnly org.apache.spark.sql.execution.joins.ExistenceJoinSuite -- -z ordinary"— 3 tests passed../dev/lint-scala— Scalastyle and Scalafmt passed.git diff --checkDoes this PR introduce any user-facing change?
Yes, on
masteronly whenspark.sql.shuffle.spreadNullJoinKeys.enabledis enabled. Eligible shuffled left outer joins may distribute provably unmatchable rows across multiple shuffle partitions. Query results are unchanged, and the configuration remains disabled by default.Was this patch authored or co-authored using generative AI tooling?
Generated-by: Codex GPT-5