Repository navigation
Do not run distributed-plan rewrites on unsplit plans - #114753
Conversation
A child plan of `ReadFromMerge` is united into the parent pipeline in the
same process and is never serialized as a distributed fragment. With
`make_distributed_plan` enabled, `QueryPlan::buildQueryPipeline` (and the
`optimize` calls on the child plans) still ran distributed-plan-only
rewrites on it — `materializeConstantsForSetOperationBranches` materialized
the constants of the `Union` inside a `Buffer` child (destination table +
buffers), while a sibling child kept them const, breaking the equal-headers
invariant across the children of `ReadFromMerge`:
Logical error: Block structure mismatch in Pipe stream: different columns:
9223372036854775806_UInt64 UInt64 UInt64(size = 0)
9223372036854775806_UInt64 UInt64 Const(size = 0, UInt64(size = 1))
Found by the AST fuzzer on #100173:
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=100173&sha=22dee0374690f4c09727a81023ef38fe4e515785&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%2C%20targeted%29
Co-Authored-By: Claude Fable 5 <[email protected]>
The previous commit cleared `make_distributed_plan` in the optimization settings of the child plans of `ReadFromMerge`, but that disabled the whole distributed planning of the children, and a `Merge` table over `Distributed` tables intentionally converts each child plan to a distributed plan on its own (see #108401). This failed the `Fast test` on 04367_distributed_plan_merge_scatter_multishard: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=113636&sha=d2b378e20bfae32ba1ace67846ff6c59f235f8be&name_0=PR&name_1=Fast%20test Fix it at the actual defect instead: `materializeConstantsForSetOperationBranches` exists because plan serialization stores only names and types, so constness is re-derived per step after a fragment is deserialized. A plan with no logical exchange steps is never split into serialized fragments (`convertToDistributed` keeps it as a single stage executed in this process), so the rewrite must not touch it. Gate the rewrite on `planContainsLogicalExchange`, and restore the plain optimization settings for the child plans of `ReadFromMerge`. Verified locally: 04812_merge_children_distributed_plan_const_mismatch fails with `Block structure mismatch` on the unpatched binary and passes with this change; 04367_distributed_plan_merge_scatter_multishard, 04613_distributed_plan_merge_broadcast_join and 04319_distributed_plan_set_operation_const_columns (and the rest of the distributed_plan family, 22 tests) pass. Co-Authored-By: Claude Fable 5 <[email protected]>
…rns full columns
Reading the destination table of a `Buffer` table can return a full column
where the plan over the buffers keeps it constant: constants come back
materialized from a `Distributed` destination. `StorageBuffer::read`
converted the destination plan to the buffers header by name, and a full
column cannot be converted back to a constant, so such reads failed with
`ILLEGAL_COLUMN` ("Cannot convert column ... because it is non constant in
source stream but must be constant in result") - with or without
`make_distributed_plan`, with or without a `Merge` table on top.
Materialize such constants in the buffers branch instead and unite the
branches of the `Buffer` read on the materialized header. This also covers
the mixed local/distributed child shape of `ReadFromMerge` raised in the
review of #113636: a `Buffer`
child over a `Distributed` destination next to a non-distributed sibling.
|
Workflow [PR], commit [cef900b] Summary: ✅
AI ReviewSummaryThis PR narrows the distributed-plan constant-materialization rewrite to plans that actually contain logical exchanges and normalizes Final Verdict✅ No blocking or major issues found. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 26/26 (100.00%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Compile time of recompiled translation units8 translation units recompiled, 33 s compile time in total, 8 of them have a recent master baseline. |
Supersedes #113636 and ports Alexey Milovidov's fix onto current
master.Avoid materializing set-operation constants in distributed-plan candidates without logical exchanges, and normalize a
Bufferread when its distributed destination materializes constants. This preserves matching headers forMergechildren.Related: #113636
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix a logical error (
Block structure mismatch) when reading aMergetable withmake_distributed_planenabled over children with internal set operations.