Repository navigation
Conversation
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-0:20260716-201600 |
|
cc @KochetovNicolai @davenger — could you review this? |
|
Workflow [PR], commit [bb35bed] Summary: ❌
AI ReviewSummaryThis PR hardens Findings❌ Blockers
Final Verdict
|
…gent aggregate state types Rewrites that push a step (Expression/Distinct lift-up in liftUpUnion, filter push-down in filterPushDown) through a UnionStep clone that step into every branch, assuming the union forwards each branch unchanged. That assumption breaks when a branch column matches the union output only loosely: two AggregateFunction columns can share the same state representation yet print different type names (e.g. quantileExactTuple vs quantilesExactTuple(0.9)), so blocksHaveEqualStructure treats them as equal and the union output takes the first branch's type. The union coerces the diverging branch at runtime via a converting step; pushing the step down bypasses that coercion and produces branch headers that no longer match, tripping the post-optimization 'Block structure mismatch' LOGICAL_ERROR (server abort in debug/sanitizer builds). Factor the precondition into canPushStepThroughUnion (every branch input header identical, same name and type name, to the union output) and apply it to both the liftUpUnion rewrites and the tryPushDownFilter Filter -> Union rewrite. Co-Authored-By: Claude Opus 4.8 <[email protected]>
fc5a9a8 to
9063d53
Compare
|
Addressed in 9063d53. Factored the precondition into a shared helper `canPushStepThroughUnion(const UnionStep &)` (returns true only when every branch input header is identical, same name and type name, to the union output) and applied it to both `tryLiftUpUnion` (Expression and Distinct lift-up) and `tryPushDownFilter` (Filter -> Union at filterPushDown.cpp). Audited the other UnionStep sites: only these two clone a step into each branch off the union output header. `limitPushDown` inserts a per-branch LimitStep built from each branch's own output header (no rebuilt union, no coercion bypass), so it is not affected; the remaining sites (applyOrder, enableMemoryBoundMerging, considerEnablingParallelReplicas, makeDistributed, optimizeReadInOrder) do not push a step through the union. Extended the regression test with the Filter -> Union shape you described. It reproduces the crash at `after optimization pushDownFilter` on the pristine binary and passes with the fix:
Confirmed the guard does not over-block: filter push-down and both lift-up rewrites still fire for genuine same-type unions. |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-3:20260717-015300 |
|
Done in the current head (9063d53), pushed after this review was posted against fc5a9a8. The predicate is now a shared helper
Regression Verified on a debug binary both directions: with the |
CI finish ledger — 9063d53Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only
Session id: cron:our-pr-ci-monitor:20260717-070000 |
The AST fuzzer found a Block structure mismatch reachable with query plan optimizations disabled, so the residual mismatch is in the base planner, not in the liftUpUnion / tryPushDownFilter guards. A UNION ALL whose branches produce aggregate-state columns sharing state representation but differing by type name (quantileExactTuple vs quantilesExactTuple(0.9)) picks one branch type as the common union header in buildCommonHeaderForUnion. addConvertingToCommonHeaderActionsIfNeeded then skipped the conversion for the other branch: blocksHaveEqualStructure and makeConvertingActions both treat the two aggregate-state types as equal. The branch kept physically emitting its own type while the union output advertised the common type, so a step above the union that wraps the column (tuple(s)) built a column whose name embeds the branch aggregate function name, and the strict per-stream checkBlockStructure aborted at pipeline build. Force the conversion, and an explicit CAST, whenever a branch column type name diverges from the common header so every branch physically emits the common type. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
The AST fuzzer failure on the previous head (STID 0993-2a62, Root cause: a Fix (3d81a4f): in |
Pre-PR validation gate (commit 3d81a4f, click to expand)
Session id: cron:clickhouse-worker-slot-6:20260717-071000 |
… type The AST fuzzer found a residual "Block structure mismatch in UnionStep stream" abort (STID 0993-27f0) for a UNION ALL whose branches carry an aggregate state nested inside a composite column, e.g. the -StateTuple combinator returning Tuple(AggregateFunction(quantileExactTuple, ...)) vs Tuple(AggregateFunction(quantilesExactTuple(0.9), ...)). buildCommonHeaderForUnion picks one branch's Tuple(agg) type as the common header and addConvertingToCommonHeaderActionsIfNeeded inserts a CAST to it. But FunctionCast::prepareImpl took an identity wrapper: the two Tuple(agg) types compare equal() (IDataType::equals is tolerant of aggregate states sharing the same representation but differing by function name), and the top-level type is DataTypeTuple, so the bare-DataTypeAggregateFunction strictEquals guard did not apply. The identity wrapper passed the source column through unchanged, so the branch kept emitting its original aggregate function while the union type advertised another. ColumnTuple::getName embeds the nested ColumnAggregateFunction function name, so the strict per-stream block-structure check aborted at plan build (reproduces with query_plan_enable_optimizations = 0). Extend the strict-identity guard to composite types: skip the identity wrapper when the two equal() types contain an aggregate-function subtype that is not strictEquals, so the real recursive Tuple/Array/Map wrapper rebuilds each aggregate column with the target function. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Extended the fix to the AST-fuzzer-found variant STID 0993-27f0 ("Block structure mismatch in UnionStep stream: different columns: s Tuple(AggregateFunction(quantileExactTuple, Tuple(UInt32, Float64)))"), found on the prior head Why the previous commit did not cover it. Commit Fix. Extend the strict-identity guard in Verified both directions on a Build-ID-pinned debug binary (worktree, fix Build ID |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-2:20260717-083700 |
Style check requires -WithMemoryTracking containers in src/Functions; replace std::vector<DataTypePtr> with the DataTypes typedef (VectorWithMemoryTracking<DataTypePtr>). Co-Authored-By: Claude Opus 4.8 <[email protected]>
…ERSECT/EXCEPT builders The query-tree planner (Planner::buildQueryPlanForUnionNode) already forces a CAST for any UNION branch whose column type name diverges from the common header even when blocksHaveEqualStructure is tolerant (aggregate-state columns that share the same state representation but differ by type name, e.g. quantileExactTuple vs quantilesExactTuple). The legacy enable_analyzer = 0 builders InterpreterSelectWithUnionQuery::buildQueryPlan and InterpreterSelectIntersectExceptQuery::buildQueryPlan still gated the branch conversion on !blocksHaveEqualStructure + plain makeConvertingActions, so a branch kept emitting its own aggregate-state type while the union advertised the common one. A step above the union that wraps the column (tuple(s)) then built a column whose name embeds the branch aggregate function name, and the strict per-stream Block structure mismatch check aborted at pipeline build. Route both legacy builders through the shared addConvertingToCommonHeaderActionsIfNeeded helper so the analyzer and legacy paths cannot drift. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Addressed in b21f021. The forced-cast homogenization now covers the legacy Confirmed the legacy path aborted before the fix: with Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-3:20260717-141300 |
…NION common type createVariantToVariantWrapper matched variant members by getName() only, so a UNION/set-op branch whose Variant nests an aggregate-state type differing from the common header only by function name (same state representation, e.g. quantileExactTuple vs quantilesExactTuple(0.9)) was rejected with CANNOT_CONVERT_TYPE even though the two Variant types are equals()-equal. buildCommonHeaderForUnion picks one branch's Variant as the common header and addConvertingToCommonHeaderActionsIfNeeded forces a CAST, but the variant wrapper could not rewrite it, so the branch kept emitting its own variant type and the strict per-stream block-structure check aborted at pipeline build. Match an unmatched-by-name old variant member to an equals()-equal new member and force a real converting wrapper so the subcolumn is physically rebuilt with the target function. Genuine Variant extensions still cast for free. Co-Authored-By: Claude Opus 4.8 <[email protected]>
| std::optional<ColumnVariant::Discriminator> matched; | ||
| for (size_t j = 0; j != new_variants.size(); ++j) | ||
| { | ||
| if (!new_discriminator_mapped[j] && old_type->equals(*new_variants[j])) |
There was a problem hiding this comment.
This fallback is broader than the union-common-header case it is trying to fix. old_type->equals(*new_variants[j]) can succeed for more than one unmapped target member when allow_suspicious_variant_types = 1, for example Variant(AggregateFunction(quantilesExactTuple(0.5), ...), AggregateFunction(quantilesExactTuple(0.9), ...), UInt8). A source member like AggregateFunction(quantileExactTuple, ...) or AggregateFunction(quantilesExactTuple(0.7), ...) will then be rewritten to whichever candidate sorts first, which changes the later merge/finalize semantics arbitrarily instead of preserving the documented "extension only" contract.
Please make this accept only a unique equals()-equal fallback match: if there are zero matches, keep throwing CANNOT_CONVERT_TYPE as before; if there is exactly one, use it for the union/common-header fix; if there are two or more, throw as ambiguous instead of picking the first one.
cppcoreguidelines-init-variables (-warnings-as-errors) does not do branch-assignment analysis and flagged the unconditionally-assigned new_discriminator in createVariantToVariantWrapper. Initialize at declaration; no behavior change. Co-Authored-By: Claude Opus 4.8 <[email protected]>
CI finish ledger — 3c5a8b1Every failure below has an owner. CI fully finished on this head (Finish Workflow SUCCESS).
Neither failure is PR-caused (both unrelated to the liftUpUnion / set-op divergent-aggregate-state fix this PR makes; both are pre-existing trunk/flaky signatures with open fixing PRs). Session id: cron:our-pr-ci-monitor:20260718-033000 |
CI finish ledger — 3c5a8b1Every failure below has an owner: a fixing PR (ours or external). No failure is caused by this PR's diff (which only changes the union converting-actions path in liftUpUnion/pushDownFilter/InterpreterSelectWithUnionQuery).
Config Workflow / Finish Workflow / Mergeable Check / PR aggregators are red only because they roll up the two lines above; both are owned. No PR-caused failure. |
Resolves conflicts in liftUpUnion.cpp and filterPushDown.cpp with master's ClickHouse#106956 const-fold guard. Both guards protect the same push-through-union rewrites but catch different divergence: master's blocksHaveEqualStructure check rejects physical divergence (a branch that constant-folds a column to Const) while remaining tolerant of aggregate-state type-name differences via IDataType::equals; this PR's check rejects the aggregate-state type-name divergence (quantileExactTuple vs quantilesExactTuple) that equals() misses. Folded both into the shared canPushStepThroughUnion helper so tryLiftUpUnion and filterPushDown's Filter->Union rewrite carry both protections.
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 113/116 (97.41%) · Uncovered code |
CI finish ledger - bb35bed...CI fully finished (Finish Workflow pass; 0 checks queued/in-progress; CH Inc sync pass). New head (pushed today) since the 2026-07-18 ledger. Failures below have owners; none is caused by this PR's diff (share identical-header precondition with the Filter->Union rewrite).
Session id: cron:our-pr-ci-monitor:20260721-190000 |
|
This PR is superseded by #111191 (merged 2026-07-30, backported to 26.5, 26.6 and 26.7). It fixed the same On a current master debug build ( |
No related open issue found.
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 in after optimization liftUpUnion" (server abort in debug and sanitizer builds) that could occur for a query with an expression or preliminaryDISTINCTabove aUNION ALLwhose branches produce aggregate-function state columns that share the same state representation but different type names (for examplequantileExactTupleStateandquantilesExactTupleState).Description
tryLiftUpUnionpushes the parentExpression/Distinctstep into each union branch, assuming the union forwards every branch unchanged. That assumption breaks when a branch column matches the union output only loosely: twoAggregateFunctioncolumns can share the same state representation yet print different type names (e.g.quantileExactTuplevsquantilesExactTuple(0.9)), soblocksHaveEqualStructuretreats them as equal and the union output takes the first branch's type. The union coerces the diverging branch at runtime via a converting step; pushing the parent down bypasses that coercion and produces branch headers that no longer match, tripping the post-optimizationcheckHeadersassertion.The fix lifts the parent only when every branch input header is identical (same name and same type name) to the union output. The optimization still fires for genuine same-type unions.
Found by the AST fuzzer (Stress test, amd_tsan; CIDB STID 0993-23fd).