Repository navigation
Do not shard a join by primary-key ranges over bucketed distributed reads - #130887
Conversation
…eads `optimizeJoinByShards` (`query_plan_join_shard_by_pk_ranges`) re-splits the reads of a merge join into primary-key layers, taking the ranges from `selectRangesToRead`, which covers the whole table. On a worker of a distributed plan, a `ReadFromMergeTree` with distributed read buckets must read only the marks pinned to its bucket, so every task of the parallel (probe) side of a broadcast join read all rows, and the result was multiplied by the number of tasks. Skip such reads, like other plan optimizations do. The test `04502_distributed_plan_one_bucket_exchange` hit this with randomized `query_plan_optimize_join_order_randomize`: the randomized estimates make the cascades optimizer choose a broadcast merge join instead of a local join. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=64868e0d5c8e0c8c3cac1d2fed24489d30c4c5d4&name_0=MasterCI&name_1=Stateless%20tests%20%28amd_release%2C%20parallel%2C%202%2F2%29 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Workflow [PR], commit [4ff302c] Summary: ✅
AI ReviewSummaryThe change prevents Final VerdictStatus: ✅ Approve. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Slowest function optimization changes (ThinLTO)Median per-function time ratio to the master baseline:
Compile time of recompiled translation units7 translation units recompiled, 16 s compile time in total, 7 of them have a recent master baseline. |
optimizeJoinByShards(query_plan_join_shard_by_pk_ranges, enabled by default) re-splits the reads of a merge join into primary-key layers, taking the ranges fromselectRangesToRead, which covers the whole table. On a worker of a distributed plan (make_distributed_plan), aReadFromMergeTreewith distributed read buckets must read only the marks pinned to its bucket. So every task of the parallel (probe) side of a broadcast join read all rows, and the join result was multiplied by the number of tasks. NowoptimizeJoinByShardsskips bucketed reads, like the projection, lazyFINALand text index optimizations already do.04502_distributed_plan_one_bucket_exchangefailed on master because of this whenquery_plan_optimize_join_order_randomizewas randomized: the randomized estimates make the cascades optimizer pick a broadcast merge join (ParallelRead⋈ReplicatedRead) instead of a local join. The query returned27445000instead of13722500.CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=64868e0d5c8e0c8c3cac1d2fed24489d30c4c5d4&name_0=MasterCI&name_1=Stateless%20tests%20%28amd_release%2C%20parallel%2C%202%2F2%29
Checked with
clickhouse local: the new test returns1500rows instead of500on master64868e0d5c8with 3 workers, and the correct result with the fix.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix duplicated rows from a merge join of a distributed query plan (
make_distributed_plan) whenquery_plan_join_shard_by_pk_rangesis enabled.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/130887]
Version info
26.11.1.2096-master(included in26.11and later)