Repository navigation
Do not reject a deserialized plan header over the aggregate state variant - #114020
Conversation
…iant A distributed query plan containing a Window step over an aggregate function state column aborted the worker with a LOGICAL_ERROR whose two printed types were byte-identical: Block structure mismatch in deserialization of query plan Window step stream: different types: theilsUState(...) OVER (...) AggregateFunction(theilsU, UInt32, UInt32) ... theilsUState(...) OVER (...) AggregateFunction(theilsU, UInt32, UInt32) ... The differing field is AggregateFunctionStateVariant, which getNameImpl never prints. encodeAggregateFunction does not carry it either, and decodeAggregateFunction calls the factory with no variant, so it defaults to Aggregation. The initiator's Window variant is therefore decoded on the worker as Aggregation, while the rebuilt WindowStep's own output header legitimately carries Window, and strictEquals compares the variant first. The version IS printed and IS encoded, so identical printed types rule a version difference out. Accept a header pair only when both headers encode to identical bytes, i.e. when the difference cannot have come off the wire at all. Every difference the plan serializer can express, including the state version, is still rejected with the unchanged message. The encode runs only after the strict check has already failed, so it is off the hot path. No format change, so no plan serialization version bump and no mixed-version concerns: a plan that aborted before now succeeds, and a new initiator talking to an old worker behaves exactly as today. Comparing encoded bytes rather than calling the existing equalsIgnoringVariant reuses the encoder's own recursion, so a state nested in Array(...) from -ForEach is covered too; equalsIgnoringVariant is a method on DataTypeAggregateFunction and can only see a top-level state. NativeReader already tolerates the same variant-only difference at its own header check, for the same reason. The two variants are required to share their serialization format (IAggregateFunction.h) and do: a Window-produced theilsU state and an Aggregation-produced one are byte-identical and each finalizes to the same value through the other's type. The relaxation cannot confuse state layouts because ColumnAggregateFunction carries its own aggregate function pointer and consumers finalize through that, so the header type is validation metadata rather than the interpreter of the bytes. The same lost variant also reaches a lambda capture inside a deserialized ActionsDAG, which compares with the same variant-sensitive equals. That site is left unchanged, so a higher-order function capturing a -ForEach window state still aborts, exactly as it does on master today, where the header check rejects it first. Relaxing it would weaken a guard over a real execution-time capture on a path shared by every higher-order function.
The deserialized header check only runs once a plan splits into more than one stage: QueryPlan::convertToDistributed collapses a one-stage plan back to local execution and force-disables make_distributed_plan, so a query that stays single-stage would pass without ever reaching the check. Nothing in the test pinned the split, and re-running the file with make_distributed_plan = 0 reproduced the reference byte-for-byte, so a later planner change could make any of these shapes single-stage and the arm would keep passing while covering nothing. Assert the split for the two structurally distinct header shapes, a plain state and a state nested in Array(...) from -ForEach, with the oracle 04628_read_nothing_step_serializable already uses at this site. The row is absent unless an exchange was planted, so dropping make_distributed_plan now makes the test fail on exactly those two rows instead of silently covering nothing. The oracles do not aggregate: an aggregating query over EXPLAIN is itself distributed and would make the oracle self-satisfying.
Internal second-model reviewBefore opening this PR I ran an independent cold code review plus a second-model review of the ❌ Fixed in this PRTest could go vacuous without failing ( Changelog category ( A claim of mine was wrong, and the second model caught it (
|
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-41:20260809-032400 |
|
cc @novikd @yariks5s, could you review this? The plan header encoding does not carry |
|
Workflow [PR], commit [2340812] Summary: ✅
AI ReviewSummaryThis PR relaxes query-plan header validation during deserialization when the reconstructed header serializes to the same bytes as the header that came off the wire, which fixes distributed Final Verdict✅ No blocking findings. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 10/13 (76.92%) · 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 units7 translation units recompiled, 7 s compile time in total, 7 of them have a recent master baseline. |
CI finish ledger - 2340812CI is fully finished on this head and every check that ran is green: 154 success, 21 skipped, 0 failure. The praktika report's top-level status is
Session id: cron:our-pr-ci-monitor:20260811-170000 |
alexey-milovidov
left a comment
There was a problem hiding this comment.
This looks weird to me. It's hard to understand why did this complication arise.
Worth asking @davenger. In the meantime, it is good to merge.
|
The awkwardness is that the plan header encoding is not plan-private.
Putting the variant on the wire is the obvious fix, but those bytes are shared with stored data: @davenger, one forward-looking question, since #111824 touches this line: at |
Closes: #113989
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixes a logical error when a distributed query plan contains a window function producing an aggregate function state, for example
theilsUState(a, b) OVER (ORDER BY a)withmake_distributed_plan = 1. Affects thecramersV,cramersVBiasCorrected,theilsUandcontingencyfamilies.Description
SELECT theilsUState(a, b) OVER (ORDER BY a) FROM t SETTINGS make_distributed_plan = 1aborts theworker in debug and sanitizer builds, printing two identical types as the mismatch.
The differing field is
AggregateFunctionStateVariant, which no type name prints.encodeAggregateFunctionomits it anddecodeAggregateFunctioncalls the factory without one, so itdefaults to
Aggregation. The initiator'sWindowheader therefore round-trips back asAggregation, andstrictEquals, which compares the variant first, rejects the pair. That rules outthe version hypothesis in #113989: identical printed names exclude a version difference, since the
name includes it.
I relaxed this one comparison rather than put the variant on the wire: that encoding is not
plan-private (
DynamicandJSONtype tags share it, so its bytes reach stored data), andNativeReaderalready tolerates the same variant-only difference for the same reason. The check nowaccepts a header pair encoding to identical bytes, i.e. a difference the serializer cannot express.
The variant is the only field
equalscompares that the encoding omits, so nothing else newlypasses. Comparing bytes rather than calling
equalsIgnoringVariantalso covers a state nested inArray(...)from-ForEach, which that top-level method cannot see.State layouts cannot be confused:
ColumnAggregateFunctioncarries its own function pointer andconsumers finalize through that, so the header type is validation metadata, not the interpreter. The
assertion's other callers stay strict.
Out of scope: the lost variant also reaches a lambda capture in a deserialized
ActionsDAG, soarrayMapover a-ForEachwindow state still aborts, as on master. Relaxing that guard wouldweaken a check over a capture path shared by every higher-order function.
No changelog entry because no stable release can reach this:
WindowStepbecame serializable onlyin #109802 (2026-08-01), absent from
26.7and earlier. Seen on 3 unrelated pull requests, none onmaster.
Version info
26.8.1.1452(included in26.8and later)