Repository navigation
Do not run distributed-plan rewrites on the child plans of a Merge table - #113636
alexey-milovidov wants to merge 6 commits into
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]>
|
Workflow [PR], commit [be64272] Summary: ✅
AI ReviewSummaryThis PR fixes two closely related constness mismatches: distributed-plan-only set-operation materialization was being applied to Final Verdict✅ Approve LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 26/26 (100.00%) · Uncovered code |
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]>
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, 32 s compile time in total, 8 of them have a recent master baseline. |
…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.
…n-distributed-const-mismatch
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=113636&sha=19599f4bece8181932b7946020cbd5c03f49f9f9&name_0=PR&name_1=Integration%20tests%20%28amd_asan_ubsan%2C%20db%20disk%2C%20old%20analyzer%2C%204%2F6%29 and provide a fix in a separate PR. If the fix is already in progress, link it here.
|
|
Investigated. Confirmed unrelated to this PR, but it is not an image or runner problem: it is a fork deadlock in the test's own process, and the test is mine (added in #113430), so I own it. The stack proves no JVM was ever launched. The deepest frame is
Why the fork can hang. Reproduced both directions locally (parent with one sibling thread holding a lock at fork time, then Why only this test. It is the only test in the tree that kills the gateway JVM and makes Fix, verified both directions: translate that trivial One correction to a reading on a sibling thread: the #113430 fix is present in these builds ( I will open the separate PR and link it here. The same failure on #110479 and #113697 has this same single cause, so it will be one PR for all three. |
|
The fix PR is #113870. It replaces pyspark's
Also for the record on scope: I checked whether the two suites that were missing the safe launcher had ever hit this. Over 30 days |
…n-distributed-const-mismatch
|
🕵 Both remaining CI failures on
The AI review verdict on this head is ✅ Approve and the single review thread is resolved, so this PR is ready for a human review/merge. |
…ame column A predicate typed against a view header (e.g. `information_schema.tables`, where `engine` is `Nullable(String)`) could be pushed down to the underlying storage (`system.tables`, where `engine` is `String`) and evaluated over a block with the mismatched column type, failing with a logical error `Unexpected return type from toString. Expected Nullable(String). Got String`. Two fixes: - `buildFilterActionsDAG`: skip a name-based input replacement when it would change the input type. Parent `FUNCTION` nodes are rebuilt with their existing `function_base`, so a differently-typed input made the rebuilt DAG (including the DAG captured inside `indexHint`) internally inconsistent. - `canEvaluateSubtree` in `VirtualColumnUtils`: match the allowed inputs by type as well as by name, so a mismatched predicate subtree is not pushed down (the filter is still applied upstream). Found by the AST fuzzer: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=113636&sha=bea222ed980b6db96146b4fe56dc968fa2280dd1&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%29 on ClickHouse#113636 Closes: ClickHouse#113982 Co-Authored-By: Claude Fable 5 <[email protected]>
…n-distributed-const-mismatch
|
🕵 Merged
The merge did not disturb this PR's diff: AI review verdict on the previous head was ✅ Approve with no unresolved review threads; awaiting fresh CI and a human merge. |
|
🕵 Superseded by #114753, which ports the reviewed fix onto current |
…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 ClickHouse#113636: a `Buffer`
child over a `Distributed` destination next to a non-distributed sibling.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Fix a logical error (
Block structure mismatch) when reading from aMergetable over children with internal set operations (e.g. aBuffertable) withmake_distributed_planenabled.A child plan of
ReadFromMergethat acquired no exchange steps is united into the parent pipeline in the same process and is never serialized as a distributed fragment. Withmake_distributed_plan = 1, the plan optimization still ranmaterializeConstantsForSetOperationBrancheson every plan: it materialized the constants of theUnioninside aBufferchild (destination table + buffers), while a sibling child kept them const. That broke the equal-headers invariant across the children ofReadFromMergeand failed with a logical error at pipeline assembly (Block structure mismatch in Pipe stream: different columns), or withCannot convert column ... because it is non constant in source stream but must be constant in resultfor a singleBufferchild.The fix gates
materializeConstantsForSetOperationBrancheson the plan actually containing logical exchange steps. The rewrite exists because plan serialization stores only column names and types, so constness is re-derived per step after a fragment is deserialized — and a plan with no exchanges is never split into serialized fragments (convertToDistributedkeeps it as a single stage executed in the same process), so it must keep its constants. Distributed planning of the child plans themselves is untouched: aMergetable overDistributedtables intentionally converts each child plan to a distributed plan on its own (see #108401 and04367_distributed_plan_merge_scatter_multishard).Minimal reproducer:
Found by the AST fuzzer on #100173: AST fuzzer (amd_debug, targeted) report.
Additionally, the review surfaced an adjacent pre-existing bug, fixed here as well: reading the destination table of a
Buffertable can return a full column where the plan over the buffers keeps it constant (constants come back materialized from aDistributeddestination), and a full column cannot be converted back to a constant, so such reads failed withILLEGAL_COLUMN(Cannot convert column ... because it is non constant in source stream but must be constant in result) — with or withoutmake_distributed_plan, and with or without aMergetable on top:StorageBuffer::readnow materializes such constants in the buffers branch and unites the branches on the materialized header. This also covers the mixed local/distributedReadFromMergechild shape raised in the review (aBufferchild over aDistributeddestination next to a non-distributed sibling), which failed at child plan creation insideStorageBuffer::read— before the plan-level guard is ever reached.Related: #100173