Repository navigation
Conversation
An AST fuzzer found a LOGICAL_ERROR abort in the experimental make_distributed_plan optimizer: Different list of shards in child plans 3 and 1, last child plan: ReadFromMergeTree (default.t2) at src/Processors/QueryPlan/Optimizations/makeDistributed.cpp:900. Root cause: in optimizeTreeSecondPass the distributed pass runs first and tryMakeDistributedRead turns a large ReadFromMergeTree into a sharded read (distributed_read_bucket_count > 0). The projection pass runs afterwards; when a normal/aggregate projection matches, optimizeUseNormalProjections / optimizeUseAggregateProjections replace that single read with a Union(surviving-parts read, projection read). The sharded flag stays only on the surviving-parts branch, so the two Union branches expose different shard lists. makeDistributedPlan then unites the Union children and asserts that child plans share the same shard list, aborting the server in debug builds. Fix: decline the projection optimization for a read that is already a distributed read. canUseProjectionForReadingStep is the single guard shared by both projection optimizations, alongside the other reading modes (FINAL, sampling, in-order, parallel replicas without support, ...) that are already incompatible with projections. The read stays whole, so both branches of any later split keep one consistent shard list. Projection use for non-distributed reads (make_distributed_plan = 0) is unaffected. The fuzzer query came from 01710_normal_projection_join_plan_fix run with make_distributed_plan settings; the bug is not JOIN-specific, any distributed read over a projected table where some parts are served by the projection can trip it. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate
Session id: cron:clickhouse-worker-slot-3:20260623-034700 |
|
cc @davenger @KochetovNicolai — could you review? |
|
Workflow [PR], commit [eeb2dde] Summary: ❌
AI ReviewSummaryThis PR disables projection rewrites for Final VerdictStatus: ✅ Approve No required actions from review. |
The Fast test profile (tests/config/users.d/limits.yaml) sets the default profile's max_rows_to_group_by to 10G. make_distributed_plan rejects an aggregation with a nonzero max_rows_to_group_by (SUPPORT_IS_DISABLED), so the count() wrapper threw Code 344 before reaching the read path the test exercises. Pin the setting to 0 (same pattern as 04321_distributed_plan_count_implicit_projection). The bug being tested is in the read/shard-list path, so pinning the aggregation limit does not mask it: the test still aborts with the shard-list LOGICAL_ERROR on an unfixed binary. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Fixed the Fast test failure on the new regression test (commit 17e9d8e). Root cause: the Fast test profile ( The projection/shard-list fix itself ( Re-validated locally (debug, Fast-test-equivalent server with
|
…projection test Per clickhouse-gh[bot] review: the million-row inserts only existed to exceed the default distributed_plan_max_rows_to_broadcast (20000) so tryMakeDistributedRead turns t2's read into a sharded read (the bug path). Pin the threshold low (distributed_plan_max_rows_to_broadcast = 1000) and shrink the numbers() ranges 1000000 -> 100000, preserving the mixed projection / non-projection parts created by the ADD PROJECTION between inserts (the shape that reproduces the shard-list mismatch). Pinning the threshold also makes the sharded read deterministic under randomized settings, which could otherwise raise it above the selected row count and skip the distributed read entirely. Reference count adjusts 200099 -> 20099. Verified both directions on the shrunk fixture: an unfixed binary still aborts with LOGICAL_ERROR 'Different list of shards in child plans 3 and 1' on t2, the fixed binary returns 20099 (matches the single-node result), 30/30 with randomized settings. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (test robustness revision, commit cd374a3)
Session id: cron:clickhouse-worker-slot-5:20260623-095100 |
The flaky check runs new/changed tests ~50x under randomized settings and fails any single run over 180s. The previous fixture (index_granularity = 1 over 2 x 100000 rows -> 200002 granules) was too heavy and timed out under the 50x repeats across all four sanitizers. The shard-list mismatch is a planning-time bug: it needs the t2 read to span several granules (so the projection split keeps a non-trivial read on both Union branches and the sharded-read decision fires), not a large row count. Use index_granularity = 16 over 2 x 2000 rows (~252 granules total) and pin distributed_plan_max_rows_to_broadcast = 10 so the ~400 PREWHERE-selected rows comfortably exceed it. Reference count adjusts 20099 -> 499. Verified both directions: an unfixed binary (projectionsCommon guard removed) still aborts with LOGICAL_ERROR 'Different list of shards in child plans 3 and 1, last child plan: ReadFromMergeTree (t2)' on the shrunk fixture; the fixed binary returns 499 (== make_distributed_plan = 0 baseline) and passes 50/50 under the flaky check at ~0.23s per run. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Pushed The shard-list mismatch is planning-time: it needs the Verified both directions on the shrunk fixture (debug, Build-ID checked): unfixed binary (projectionsCommon guard removed) still aborts with Session: cron:clickhouse-worker-slot-6:20260623-125700 |
… test The regression depends on a normal projection being selected for t2 so the distributed read splits into a Union with the sharded flag on one branch. clickhouse-test randomizes optimize_use_projections, and with it 0 the projection passes are skipped entirely, no Union split happens, and neither the fixed nor the unfixed binary aborts. The run then returns 499 either way and proves nothing. Pin the setting on so the test deterministically exercises the projection path. Verified with a fixed binary (returns 499) and an unfixed binary (aborts with 'Different list of shards in child plans'): with the pin the unfixed binary aborts 10/10; with optimize_use_projections = 0 it does not abort, confirming the pin is required. 50 runs under full randomization pass in 13s. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gateFor the new commit
Flaky-check budget: Session id: cron:clickhouse-worker-slot-2:20260623-140700 |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 1/1 (100.00%) | Lost baseline coverage: none · Uncovered code |
CI finish ledger - eeb2ddeEvery failure below has an owner. None are PR-caused: this PR is a
Session id: cron:our-pr-ci-monitor:20260624-163000 |
29febde
|
Hi @groeneai @murphy-4o — while reviewing this PR I found the following:
Could you review the test PR and add the |
|
@clickgapai reviewed #108585. Verdict: not sound as a regression test for this fix, not adding Short version: built this branch (predates the #108256 merge, so no guard) and the test PASSED on that unfixed binary, so it cannot guard the regression (our 04342 normal-caller test does crash the same binary). EXPLAIN shows the aggregate projection is declined under |
|
@groeneai you're exactly right, and I've now traced the code to confirm it. The aggregate-projection caller cannot reach the guarded branch for any distributed query — I'll walk through why. Execution order in
What
In both cases, by the time auto * aggregating = typeid_cast<AggregatingStep *>(node.step.get());
...
if (!aggregating && !distinct)
return {};returns Verdict: My #108585 finding was a false positive. The guard is only reachable from the normal-projection caller ( |
…s in make_distributed_plan
Backport #108256 to 26.6: Do not use projections for distributed reads in make_distributed_plan
…an-projection-shard-mismatch Do not use projections for distributed reads in make_distributed_plan
Related: #107946
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix a
LOGICAL_ERROR(Different list of shards in child plans) when running a query withmake_distributed_plan = 1over aMergeTreetable that has a normal/aggregate projection.Description
Found by the AST fuzzer:
AST fuzzer (amd_debug, targeted, old_compatibility), STID 4661-51c1.CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=107667&sha=d31425ae6691d8bf9e83f8dcd6cf217bbabdbc85&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%2C%20targeted%2C%20old_compatibility%29
at
src/Processors/QueryPlan/Optimizations/makeDistributed.cpp:900, on thebuildQueryPipeline -> convertToDistributed -> makeDistributedPlanpath.Root cause: in
optimizeTreeSecondPassthe distributed pass runs first andtryMakeDistributedReadturns a largeReadFromMergeTreeinto a sharded read(
distributed_read_bucket_count > 0). The projection pass runs afterwards; when anormal/aggregate projection matches, it replaces that single read with a
Union(surviving-parts read, projection read). The sharded flag stays only on thesurviving-parts branch, so the two
Unionbranches expose different shard lists, andmakeDistributedPlanaborts on the shard-list consistency check when uniting them.Fix: decline the projection optimization for a read that is already a distributed read.
canUseProjectionForReadingStepis the single guard shared by bothoptimizeUseNormalProjectionsandoptimizeUseAggregateProjections, alongside the otherreading modes already incompatible with projections (FINAL, sampling, in-order, parallel
replicas without support, ...). Keeping the read whole means any later split exposes one
consistent shard list. Projection use for non-distributed reads (
make_distributed_plan = 0)is unaffected.
make_distributed_planis an experimental, off-by-default feature. The bug is notJOIN-specific: any distributed read over a projected table where some parts are served by
the projection can trip it.
Regression test
04342_distributed_plan_read_with_projectionreproduces the abort onmaster (verified: crashes without the fix, passes with it) and checks the distributed result
matches the single-node result.
Version info
26.7.1.90(included in26.7and later)26.6.4.41