Repository navigation
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## den-55 #232 +/- ##
==========================================
+ Coverage 81.28% 81.33% +0.05%
==========================================
Files 1111 1112 +1
Lines 390523 391774 +1251
Branches 390523 391774 +1251
==========================================
+ Hits 317453 318666 +1213
- Misses 54448 54458 +10
- Partials 18622 18650 +28 ☔ View full report in Codecov by Harness. 🚀 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.
Why
A hash join loads one input (the build side) fully into memory and streams the other (the probe side) through it.
JoinSelectionpicks the build side at planning time from input statistics. Those statistics are row counts from before filters run. A heavily filtered join can therefore choose a very large input as the build side, while the other input yields only a small amount of data at runtime. The build side then exhausts the memory pool and the query fails with an out-of-memory error onHashJoinInput. More planner rules that pattern-match these query shapes would be fragile, because the planner still cannot see post-filter sizes.After this change, an opt-in setting lets an eligible partitioned hash join measure both inputs at runtime before building. If the planned build side is too large and the planned probe side turns out small, the join swaps roles in-stream and builds the small side. Query results and the output schema are unchanged. With the setting off, hash joins behave exactly as before.
What changed
One new execution setting.
datafusion.execution.hash_join_adaptive_build_side_threshold_bytes(default0, which turns the feature off). It is the byte budget for each side's sample, summed across all partitions of the join. It is session-level and can be changed withSET.Only a narrow, safe set of joins is eligible.
PartitionMode::Partitionedand have dynamic filter pushdown enabled. This guarantees a shared build accumulator exists (the object that collects every partition's build result into one dynamic filter).fetchlimit, no required output ordering, no null-aware anti semantics (NOT IN), and no probe-side buffering (hash_join_buffering_capacity = 0).join_reorderingmust be enabled.Inner,Left,LeftSemi,RightSemi, andLeftAnti. Every other join takes the existing path and reports no adaptive metrics.All partitions of a join decide together.
AdaptiveBuildCoordinator) moves through four phases:SampleLeft→ReleasingFilter→SampleRight→Decided.SampleLeft: every partition buffers the planned left (build) side. The right side is not read. If the whole left side fits within the threshold, the join builds it as usual (left_small).SampleRight: if the left side crosses the threshold, every partition samples the right side. The join swaps only when every partition's right side ends within the threshold. If the right side also crosses the threshold (right_crossed), errors (right_error), or a partition is dropped (abandoned), the join keeps the left side.batch_sizerows per partition (summed join-wide), so tiny or zero-byte batches cannot hold the decision open.The dynamic filter is released before the right side is read.
wait_complete()). Reading it before that filter exists could deadlock.ReleasingFilter. One partition marks every pending accumulator slot as canceled and waits until this join's dynamic filter is final as a pass-throughtrue. Only then isSampleRightpublished.Fix a lost-wakeup race in
DynamicFilterPhysicalExpr.wait_complete()checkedis_complete, then subscribed to the watch channel. Amark_complete()call between those two steps was missed, and the waiter could hang. It now re-checksis_completeafter subscribing.update()andmark_complete()now publish withsend_replacewhile holding the write lock. The channel always keeps the latest state, even with zero receivers, and a laterupdate()cannot move a completed filter back to in-progress.The swap happens inside the join stream.
LeftbecomesRight) and the join filter. It also flips the side recorded for each output column, so output columns keep their planned order and noProjectionExecis added.New metrics (shown in
EXPLAIN ANALYZE).adaptive_build_swapped,adaptive_right_sampled,adaptive_sampled_left_bytes,adaptive_sampled_right_bytes, andadaptive_sample_poll_time(time spent polling the sampler, excluding time parked between polls).adaptive_decision_wall_time(from the first partition starting to the decision) andadaptive_decision_reason_*with reasonsswap_right,left_small,right_crossed,right_error,abandoned, andduplicate(the same partition was executed twice).Tests.
DynamicFilterPhysicalExpr: completion with zero receivers is kept in the watch channel, and a two-thread race betweenmark_complete()andwait_complete()never hangs.SampleRightis published, waiting for a competing finalizer, and an abandon during the release not being overwritten.execute()errors, errors in each phase, the decision wall-time metric being recorded once, and every ineligible configuration.Diff breakdown (~74% tests).
+1,632 / -152lines (25.9%of additions).+4,669 / -1lines (74.1%of additions).+1line.Scope, rollout & caveats
0, merging this changes nothing until a session enables it.true, not the exact hash-table filter it would build today. Results are identical; only the pruning is lost.DynamicFilterPhysicalExpr. Waiters could then be unblocked during sampling, and the real filter could still be pushed later.Right,RightAnti,Full,LeftMark, andRightMarkjoins, andCollectLeftjoins.Verification
cargo fmt --all -- --check: passed (0 diffs).cargo clippy -p datafusion-common -p datafusion-physical-expr -p datafusion-physical-plan --all-targets -- -D warnings: passed (0 warnings).cargo test -p datafusion-common --lib config::: 14/14 passed.cargo test -p datafusion-physical-expr --lib dynamic_filters: 24/24 passed.cargo test -p datafusion-physical-plan --lib joins::: 1,071/1,071 passed, including all 38 adaptive tests.datafusion-sqllogictest(information_schema.slt) and the extended workspace / full-feature clippy suites: CI only (not run locally).