fix(query): avoid serial distribution contagion in joins - #20353
Open
dqhl76 wants to merge 8 commits into
Open
Conversation
Member
Author
|
follow-up idea: The existing fallback explicitly notes that redistribution could be enforced here: databend/src/query/sql/src/planner/plans/join.rs Lines 904 to 912 in ff30e51 This PR addresses the safe and common case where a small |
dqhl76
force-pushed
the
codex/hashjoin-skew-rca
branch
from
August 21, 2026 13:43
837ef0f to
3eaf677
Compare
dqhl76
force-pushed
the
codex/hashjoin-skew-rca
branch
from
August 27, 2026 02:49
0673526 to
32a9499
Compare
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.
I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/
Summary
Fix distributed join planning when the build side already has
Serialdistribution.Previously, the heuristic distributed optimizer returned
Serialrequirements for both join inputs as soon as either input was Serial. A small build produced by a scalar aggregate or another single-produced source therefore forced a large distributed probe throughExchange(Merge). This concentrated probe processing and join memory on one node even when broadcasting the small build was substantially cheaper.This PR allows an eligible small Serial build to be redistributed with
Broadcastwhile keeping the probe requirement asAny. The existing fragment scheduler already handles both resulting physical shapes:Exchange(Merge)is marked withhas_merge_input; only the coordinator executes its real input, while other Broadcast destinations retain empty receiver actions.No new coordinator-placement flag or scheduler production-code change is needed.
Changes
Scalar Aggregate
Before:
A small Serial aggregate forced the large probe to merge onto one node.
After:
Only the one-row aggregate result is broadcast; the large probe remains distributed.
Sort / TopN
Before:
A small Serial sorted result forced the large probe to merge onto one node.
After:
Tests
Validation:
Type of change
Risk
The behavior change is limited to the heuristic distributed optimizer when the build is Serial, the probe is not Serial, the join supports a broadcast build, and the existing broadcast cost or enforcement settings select Broadcast. Large builds and unsupported joins retain the previous Serial fallback.
Fragment scheduling behavior is unchanged. Regression tests cover the two relevant existing paths: direct Merge inputs use
has_merge_inputfor coordinator placement, while single-row source fragments use normal source partition redistribution.AI assistance
This change is