Repository navigation
refactor: split join selection into two subrules - #27979
Open
2010YOUY01 wants to merge 2 commits into
Open
2010YOUY01 wants to merge 2 commits into
2010YOUY01 wants to merge 2 commits into
Conversation
2010YOUY01
commented
Dec 3, 2026
| @@ -1925,6 +1925,10 @@ DROP TABLE dynamic_filter_recursive; | |||
| # recursive iterations (#26641). Each iteration looks up a different key; the | |||
| # EXPLAIN ANALYZE below checks that the filter is reset and republished, so the | |||
| # probe scan prunes rows on every iteration. | |||
| # Keep the work table on the build side so the parquet scan receives the filter. | |||
Member
Author
There was a problem hiding this comment.
For all slt changes, see PR description test section.
2010YOUY01
marked this pull request as ready for review
December 3, 2026 02:34
Codecov Report❌ Patch coverage is
Flags with carried forward coverage won't be shown. Click here to find out more. @@ Coverage Diff @@
## main #27979 +/- ##
==========================================
+ Coverage 83.44% 83.71% +0.26%
==========================================
Files 1060 1061 +1
Lines 475307 507452 +32145
Branches 475307 507452 +32145
==========================================
+ Hits 396642 424837 +28195
- Misses 54124 58110 +3986
+ Partials 24541 24505 -36
... and 119 files with indirect coverage changes 🚀 New features to boost your workflow:
|
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?
cleanup for #27980
Rationale for this change
Hash join selection currently makes two decisions in a single optimizer tree traversal:
These decisions are spread across tightly coupled utility functions in the operator and optimizer. I think the existing implementation reflects patches accumulated over time rather than a deliberate design. The two-pass approach is already implicit in the logic, but making it explicit produces a simpler implementation.
This PR simplifies the implementation by giving each layer a clear responsibility:
HashJoinExec::choose_partition_modeencapsulates the partition-mode decision in a single, self-contained function on the operator.For example:
The two passes handle this in order:
Separating the two also also provides a clearer extension point for future cost-based join optimization (CBO): CBO could focus on join ordering, while partition-mode selection remains a separate, heuristic-based subrule. This would make join CBO easier to implement and extend.
Related: #18249.
What changes are included in this PR?
Suggested reading order:
datafusion/physical-optimizer/src/join_selection.rs—JoinSelectionruns separate bottom-up passes for input swapping and partition-mode selection, after handling unbounded inputs.datafusion/physical-plan/src/joins/hash_join/exec/optimizations.rs— atomicHashJoinExecmutator for swapping input, and choosing partition mode.What is the testing strategy for this PR?
Existing tests.
Notes on changes on
slts in this PR, the diffs are all improving the plan:This case it's better to swap the side, to let knwon-small right side broadcast, but some plan shape missed this optimization in the existing implementation.
For 3 updated files:
Are there any user-facing changes?
No behavior change, some query get optimized differently