Repository navigation
Conversation
…a join On a distributed-plan worker, a `ReadFromMergeTree` of a bucketed distributed read (`getDistributedReadBucketCount() > 0`) reads only the marks of its bucket. They arrive as a task parameter and are pinned into `parts_with_ranges` in `initializePipeline`. The worker runs the regular plan optimizations on its fragment, including `optimizeJoinByShards` (`query_plan_join_shard_by_pk_ranges`, on by default). For a non-spilling `HashJoin` whose join key is a primary-key prefix of both sides it split ALL local parts into layers (`split_parts`), and `readByLayers` reads those layers instead of `parts_with_ranges`. So every reader task read the whole table and the result was multiplied by the number of tasks: with 4 tasks, `SELECT count() FROM t WHERE EXISTS (SELECT 1 FROM s WHERE s.k = t.k)` returned 80 instead of 20. Found by the AST fuzzer TLP oracle (exists / not exists / isNull arms summed to 4x the table count). Refuse such a read in `findReadingStep`, as the other worker-side passes that rebuild a read from its analysis already do (`optimizeLazyFinal`, projections, trivial count from text index). The join then runs unsharded inside the task, as it does with the default spill settings, where the join is a `SpillingHashJoin` and is never sharded. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 1 finding) plus my own review (1 nit).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-9:20261105-011400 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-40:20261105-000203 |
|
Workflow [PR], commit [781ccbf] Summary: ✅
AI ReviewSummaryPR #129420, reviewed at Missing context / blind spots
Final VerdictStatus: ✅ Approve. No code changes requested; normal CI completion remains pending. |
|
cc @davenger @KochetovNicolai, could you review this and add the |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 16 s compile time in total, 7 of them have a recent master baseline. |
|
This also fixes No random join order is needed: two tables |
|
This also fixes With |
|
Superseded by #130887 (merged 2026-11-12), which adds the same check in |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
With
make_distributed_planandenable_cascades_optimizer, a join over a bucketed distributed read of a MergeTree table no longer returns its rows multiplied by the number of reader tasks whenquery_plan_join_shard_by_pk_rangesshards the join by primary-key ranges.Description
Found by the AST fuzzer TLP oracle: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=112805&sha=8c15f2c48f9d60fd977139bdc49ed302255dceb6&name_0=PR&name_1=AST%20fuzzer%20%28amd_release%2C%20oracle%29 (the
exists/not exists/isNullarms of a correlatedEXISTSsummed to 4x the table count). No related open issue found.On a distributed-plan worker, a bucketed
ReadFromMergeTree(getDistributedReadBucketCount() > 0) reads only its bucket's marks, whichinitializePipelinepins intoparts_with_ranges. The worker runs the regular optimizations on its fragment, andoptimizeJoinByShardssplit all local parts into layers for a non-spillingHashJoinon a primary-key prefix;readByLayersreads those layers, notparts_with_ranges, so every task read the whole table. With 4 tasks,SELECT count() FROM t_orders WHERE EXISTS (SELECT 1 FROM t_lineitem WHERE l_orderkey = o_orderkey)returned 80 instead of 20 (needsmax_bytes_before_external_join = 0andmax_bytes_ratio_before_external_join = 0; with the default ratio the join is aSpillingHashJoin, which is never sharded).findReadingStepnow refuses such a read, like the other worker-side passes that rebuild a read from its analysis (optimizeLazyFinal#112493, projections #108256, trivial count from a text index). The join then runs unsharded inside the task.Validation: the new test
05510_distributed_plan_join_by_pk_ranges_bucketed_readfails on master (80, 3920, 80, 80 vs 20, 980, 20, 20) in 20/20 randomized runs and passes 50/50 with the fix; the 202 stateless tests that usemake_distributed_plangive the same results before and after, apart from the new test.Workflow [PR]
Sync PR [sync-upstream/pr/129420]