Repository navigation
refactor: simplify null-aware and join-type branching in hash join - #24957
Merged
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
discord9
added a commit
to GreptimeTeam/datafusion
that referenced
this pull request
Nov 10, 2026
…tion saw NULL RE-IMPLEMENTATION, not a faithful cherry-pick. apache#25076 (5747e87) does not apply here: this fork's base predates the null-aware branching refactor (apache#24957, `NullAwareMode`) and the chunked final emission (apache#25028, `EmitUnmatchedBuildRowsState`), and `git show 5747e87 | git apply --check` fails on `exec.rs`, `stream.rs` and the three manifests. The semantics below are the upstream ones; the shape is this fork's. The bug: the final stage read the shared "probe side saw NULL" flag and only then decremented the probe-partition counter, so a partition could read `false`, let a sibling record a NULL and finish, then become the last partition itself and emit build rows that `NOT IN` must suppress. The counter also decremented with `Relaxed`, so nothing ordered a sibling's store before the last partition's load. Changes: - New `hash_join/probe_completion.rs`, ported nearly verbatim: `ProbeCompletion` owns the probe-partition counter and the two shared flags, `report_completed()` decrements with `AcqRel` and returns a `ProbeSideSummary` only to the last partition, so the final stage cannot read the flags before its own decrement. Its sequential unit tests and the `--cfg datafusion_loom` model-checked tests come along with the workspace `loom` dependency and the `cfg(datafusion_loom)` check-cfg registration. - `JoinLeftData` holds one `ProbeCompletion` instead of `probe_threads_counter`/`probe_side_non_empty`/`probe_side_has_null`. The probe phase records through `record_probe_batch()` and keeps a best-effort `probe_side_has_null_hint()` early exit. - `process_unmatched_build_batch` decrements first and hands the resulting summary to the new `null_aware_left_anti_final_indices`, which holds the `LeftAnti` rules: a probe NULL seen by any partition suppresses every build row; otherwise a NULL build key is dropped unless the probe side was empty. - This fork has no null-aware `LeftMark`, so the mark half of the upstream PR has no counterpart here. Tests (`hash_join/exec.rs`): - `test_null_aware_anti_join_probe_null_in_other_partition`: two probe partitions, only partition 0 sees the NULL, drained in both finishing orders; no rows may be emitted. - `test_null_aware_anti_join_probe_logical_null_in_other_partition`: the same with a dictionary key whose NULL is logical only. - `test_null_aware_anti_join_empty_probe_keeps_null_build_key`: pins `NULL NOT IN (empty) = TRUE` (added here; upstream covers it via slt only). (backport of apache#25076, 5747e87) Signed-off-by: discord9 <[email protected]> (cherry picked from commit 3fb9a3084e39781b90d5dbffa01f2664f64dcc2d)
discord9
added a commit
to GreptimeTeam/datafusion
that referenced
this pull request
Nov 10, 2026
…results RE-IMPLEMENTATION, not a faithful cherry-pick. apache#25339 (95bb0a0) builds on the correlated null-aware machinery of apache#21585/apache#24957 (correlation scope maps, `NullAwareMode`, `null_indices_bitmap`, shared null-mark buffers), none of which exists here; `git show 95bb0a0 | git apply --check` fails on `exec.rs`, `stream.rs` and `join_selection.rs`, and it also edits benchmark files this fork does not have. The bug: a correlated `NOT IN` whose correlation cannot become an equi-join key leaves a residual join filter, and the executor ignored that filter when deciding whether a NULL on the subquery side makes `NOT IN` UNKNOWN, so a NULL the filter excludes still poisoned every outer row. Same semantics for the shapes this fork can plan (`on[0]` is the `NOT IN` value key and the residual correlation lives in the join filter; the null-aware validation still requires a single join key, where upstream also accepted `on[1..]` scope keys): - `JoinLeftData` gains the shared `null_indices_bitmap` of build rows whose `NOT IN` is UNKNOWN, allocated with the build side for correlated joins. - A correlated null-aware join (one with a join filter) no longer lets a probe NULL poison the whole join: `mark_null_candidates_for_probe_batch` records, per build row, whether a NULL that the residual filter keeps makes `NOT IN` UNKNOWN - case 1, a NULL build key with a probe row that passes the filter; case 2, a probe row with a NULL key that passes the filter. Without scope keys both cases are cross products, already-marked build rows are skipped, and the filter is not re-evaluated for them. - The final stage drops the marked build rows instead of consulting the probe-side flags, so outer rows whose subquery is empty keep `NOT IN (empty) = TRUE`. - The uncorrelated probe-side NULL check now uses logical nulls too, so dictionary keys are covered on both paths. Tests: - `hash_join/exec.rs`: `test_null_aware_left_anti_filter_only` (a `LeftAnti` with a second-column `>` filter and no scope keys; only the rows with an empty subquery result are emitted), from the upstream PR. - `sqllogictest/test_files/null_aware_anti_join.slt`: new correlated-residual section - the query from the upstream issue, an `EXPLAIN` assertion that the shape stays `LeftAnti ... filter=..., null_aware` on a single equi key, and the case where the residual leaves the subquery empty for every outer row. (backport of apache#25339, 95bb0a0) Signed-off-by: discord9 <[email protected]> (cherry picked from commit 163cc1d5fb8a8565825a13ebfc82c010bc8750fa)
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.