refactor: simplify null-aware and join-type branching in hash join - #24957
Merged
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #24957 +/- ##
==========================================
- Coverage 81.62% 81.62% -0.01%
==========================================
Files 1123 1124 +1
Lines 409524 412193 +2669
Branches 409524 412193 +2669
==========================================
+ Hits 334294 336437 +2143
- Misses 55594 55939 +345
- Partials 19636 19817 +181 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
xudong963
reviewed
Sep 6, 2026
| JoinType::Inner | ||
| | JoinType::LeftSemi | ||
| | JoinType::RightSemi | ||
| | JoinType::Right |
Member
There was a problem hiding this comment.
here says everything not emitting unmatched build rows is emitted incrementally. LeftSemi emits matched build rows from the final bitmap, not incrementally.
Contributor
Author
There was a problem hiding this comment.
Good catch! I'll open an issue or a PR for this.
xudong963
approved these changes
Sep 6, 2026
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
HashJoinExeccarries anull_aware: boolthat is only legal for three(join_type, partition_mode)combinations. Because the flag and the join typewere tracked separately, every use site had to re-derive which combination it
was in, with conditions like
self.null_aware && self.join_type == JoinType::LeftAntiscattered across the builder and the stream.
process_probe_batchandprocess_unmatched_build_batchwere interrupted five times by such blocks, sothe main probe path was hard to follow, and the builder validated the legal
combinations with a five-clause hand-written truth table.
Separately, several predicates over
JoinTypewere spelled as hand-maintainedlists of variants (
maintains_input_order, theEmissionTypematch, theswap-inputs projection check). Each list has to be revisited whenever a variant
is added, as happened when
RightMarklanded, and none of them says why avariant belongs in the list.
What changes are included in this PR?
Two related cleanups, no behavior change:
NullAwareModeenum (hash_join/exec.rs,hash_join/stream.rs)pub(super) enum NullAwareMode { LeftAnti, RightAnti, LeftMark { correlated: bool } },with a single
try_newholding the whole legality table. The builder'svalidation becomes one call; the error messages are byte-identical.
HashJoinExec::null_awarestays a publicbool, so there is no API change.The mode is derived once in
executeand passed down.collect_left_inputtakes oneOption<NullAwareMode>instead of twoseparately derived booleans, which also lets a now-unfulfilled
clippy::fn_params_excessive_boolsexpectation be dropped.(
null_aware_skip_probe_batch,drop_null_probe_keys,null_aware_left_anti_final_indices,null_aware_left_mark_column), eachdocumenting the three-valued-logic rule it implements. The probe path now
reads top to bottom, and the final stage is a single
matchon the mode.Named predicates instead of variant lists (
joins/utils.rs)emits_unmatched_left_rowsdrives theEmissionTypedecision.is_existence_joindrives the swap-inputs projection check.maintains_input_orderbecomes!need_produce_result_in_final(join_type),whose complement was exactly the old hand-written list, with a comment
explaining that emitting rows from the build-side bitmap breaks probe order.
lr_is_preservedis left alone; it already reads as a clear truth table.Note for reviewers:
emits_unmatched_left_rowsdeliberately excludesLeftSemiso the
EmissionTyperesult is unchanged, even though the hash join does emitLeftSemirows from the bitmap in the final stage. That inconsistency ispre-existing and out of scope here.
What is the testing strategy for this PR?
No new tests: the change is behavior-preserving, so the value is in the existing
coverage continuing to pass.
cargo test -p datafusion-physical-plan --lib hash_joinnull_aware_anti_join.slt,null_aware_mark_join.slt,joins.slt,subquery.sltcargo clippy --all-targets --all-features -- -D warningsandcargo fmt --allThe builder validation tests in
hash_join/exec.rsalready assert on the exactnull-aware error strings, which are unchanged, so they cover
NullAwareMode::try_new.Are there any user-facing changes?
No. No public API changes, and
EXPLAINoutput is unchanged. The threeJoinTypepredicates were each verified to cover exactly the same set ofvariants as the lists they replace.