Adapt existing partitioning for unsatisfied inputs in co-partitioned joins - #24600
Merged
Conversation
27 tasks
stuhood
force-pushed
the
stuhood.three-way-range
branch
from
August 24, 2026 17:15
3c6f07b to
d5744a3
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #24600 +/- ##
==========================================
+ Coverage 81.38% 81.50% +0.11%
==========================================
Files 1116 1123 +7
Lines 397973 405013 +7040
Branches 397973 405013 +7040
==========================================
+ Hits 323893 330092 +6199
- Misses 55118 55602 +484
- Partials 18962 19319 +357 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
stuhood
force-pushed
the
stuhood.three-way-range
branch
from
August 24, 2026 18:53
d5744a3 to
7213baa
Compare
stuhood
force-pushed
the
stuhood.three-way-range
branch
from
August 24, 2026 19:14
7213baa to
cb8faec
Compare
stuhood
marked this pull request as ready for review
August 24, 2026 20:33
Contributor
Author
kosiew
approved these changes
Aug 28, 2026
kosiew
left a comment
Contributor
There was a problem hiding this comment.
Thanks for working on this. The approach looks good overall, especially preserving an existing compatible partitioning instead of falling back to repartitioning both sides.
I have one non-blocking test suggestion below.
Contributor
|
🚀 |
Contributor
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.
Which issue does this PR close?
Rationale for this change
When multi-child operators (such as
HashJoinExecorSortMergeJoinExec) declare co-partitioning requirements viaInputDistributionRequirements, all children must share a compatible partitioning scheme on their respective join keys.Prior to this change, joining an unpartitioned stream with an input that was already partitioned (such as
Partitioning::RangeorPartitioning::Hashfrom a pre-sorted/partitioned data source scan):ensure_distribution, the unpartitioned input failed itsDistribution::KeyPartitionedrequirement and was wrapped inRepartitionExec: Hash(keys, target_partitions).enforce_distribution_relationshipsinspected both children, it saw a layout mismatch betweenHashandRange. The code would only createHashpartitionings, and so it discarded the existing nativeRangepartitioning on the second child and wrapped both children inRepartitionExec: Hash, forcing a double shuffle.What changes are included in this PR?
This PR adjusts
enforce_distribution_relationshipsto recognize when one of the children in a co-partitioned group already satisfies its distribution requirement, selecting it as a reference partitioning and adapting unsatisfied peer inputs to match:input_distributions.child_satisfaction().RepartitionExecexchange nodes (since their statistics and partition balance are more likely to be accurate).PlanSize(total_byte_size, thennum_rowscomputed viaStatisticsContext) and select the strictly largest input.RangePartitioning: If the satisfied reference child hasPartitioning::Range(ref_range), adaptref_range'ssplit_pointsand sort options to the unsatisfied child's join expressions after verifying that expression data types match split point scalar values viasplit_points_match_expr_types.HashPartitioning: If the reference child hasPartitioning::Hash(_, count), adapt toPartitioning::Hash(exprs, count).RepartitionExecduring Phase 1, replace its input directly rather than nesting redundantRepartitionExecnodes.Are these changes tested?
Yes, integration tests in
datafusion/core/tests/physical_optimizer/enforce_distribution.rs:range_hash_join_repartitions_unsatisfied_side_to_match_range: verifies unsatisfied range input adapts to peer reference range partitioning.range_hash_join_repartitions_unpartitioned_side_to_match_range: verifies unpartitioned scan input adapts directly to peer range partitioning without modifying the partitioned side.range_hash_join_rehashes_incompatible_data_type: verifies type mismatch (Int32vsInt64) safely falls back to two-sided hash repartitioning.Are there any user-facing changes?
No API changes.