Repository navigation
Check the aggregates of deserialized query plan steps against their input - #131789
Conversation
…nput The aggregate functions of a deserialized `Aggregating` step are resolved from the argument types written in the plan, but the `Aggregator` executes them on the input columns found by name. A plan with other types (or a missing column) made a function interpret a column of another type. Likewise, the steps that merge states (`Aggregating` with `only_merge`, `MergingAggregated`, `Rollup`, `Cube`) merged the input columns with the functions from the plan. `checkDeserializedAggregatesMatchHeader` refuses such plans with `INCORRECT_DATA`: arguments must be in the input with the types the function is resolved for (`LowCardinality` aside, which the factory and the `Aggregator` both remove), and merged columns must be states of the same representation. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Workflow [PR], commit [f50f0b3] Summary: ✅
AI ReviewSummaryValidates aggregate argument types and merge layouts in deserialized query plans, and checks runtime aggregate finalization against the expected result types. The earlier findings are addressed in the current code; no additional actionable findings remain. The focused Final VerdictStatus: ✅ Approve |
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes14 object files changed (+142.48 KiB total), 0 added.
716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units2323 translation units recompiled, 8728 s compile time in total, 2323 of them have a recent master baseline. |
Address review: the `Aggregator` looks up the types of the keys and the states by name, but merges the columns by position (`makeAggregateColumnsData` reads `columns[keys_size + i]`). A plan whose input had the right states in another order, or that repeated an aggregate, passed the by-name check and merged a state with the function of another one. Now `checkDeserializedMergedAggregatesLayout` requires the input of the merging steps (`Aggregating` with `only_merge`, `MergingAggregated`, `Rollup`, `Cube`) to start with the keys and then the states, in the order of the plan, with distinct names. For `MergingAggregated` with grouping sets, the layout is checked per set as `MergingAggregatedTransform` reorders it. The merge-only `Aggregating` with grouping sets, which the planner never produces, is refused. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=131789&sha=8475b70149712863b7f4d424e1b30b336415a0f7&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20sequential%2C%201%2F2%29 ( |
|
Acknowledged. Reproduced on master (fdc4389), also with The extra two come from the post-spill re-seed that #126249 enabled for |
`Aggregator::Params::getHeader` builds the header of the merge-only steps from the whole input, so a later column with the name of a key or a state would be there, but not in the merged chunks. Addresses the review comment in #131789. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
The fix is in #132141: merges that only put the kept keys back into the table (the re-seed after a spill, and the kept-keys rebuild) no longer count as a new |
…s input Address review: `TotalsHavingStep::deserialize` accepted `AggregateDescriptions` without checking them against the input header, and `TotalsHavingTransform` finalizes the columns named by them, assuming they are states. Now every aggregate must name an input column holding a state of the same representation (`checkDeserializedFinalizedAggregates`), otherwise the plan is refused with `INCORRECT_DATA`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…d` step With grouping sets, `MergingAggregatedTransform` reads `__grouping_set` as `ColumnUInt64` and the output header takes its type from the input. A forged plan with another type or several such columns was accepted and then hit an exception in `MergingAggregatedTransform::addChunk`, or produced chunks that disagreed with the output header. Require exactly one `UInt64` `__grouping_set` column during deserialization. #131789 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ated` step without grouping sets `appendGroupingIfNeeded` copies a `__grouping_set` column of the input into the output header, but the merge without grouping sets does not produce it, so the chunks would not match the header. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… and distinct aggregate names - `Rollup` and `Cube` always finalize their states and address the whole input with a mask built for the keys and the states only, and finalize a single input chunk with the functions of its columns. `checkDeserializedGroupByModifierInput` now requires `final`, an input of exactly the keys and the states, and states whose functions finalize to the result types of the plan (functions with the same state representation, like `quantile` and `quantiles`, may finalize differently). - The merge-only `Aggregating` step requires an input of exactly the keys and the states, because `AggregatingInOrderTransform` addresses the whole input with the mask too. - The ordinary `Aggregating` step requires distinct key and aggregate names, because the finalization finds the states by name. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…kDeserializedGroupByModifierInput` https://s3.amazonaws.com/clickhouse-test-reports/PRs/131789/afba83fe9a58cef5710bd972fa0a556968118eb5/pr/build_arm_tidy_3_4/build_clickhouse/build_clickhouse.log #131789 Co-Authored-By: Claude Opus 5.5 <[email protected]>
… sort descriptions The merge-only `Aggregating` step (also in order) finalizes the states with the functions of its input, while its header takes the result types from the plan, so require them to agree, as for `Rollup` and `Cube`. `AggregatingInOrderTransform` takes the first columns of `group_by_sort_description` as the ones the input is sorted by and compares the key columns at their positions, so require `sort_description_for_merging` to be a prefix of `group_by_sort_description`, and the latter to name only keys. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`DataTypeAggregateFunction::equals` considers the states of functions with the same state representation (like `quantile` and `quantiles`) equal, so a `Union` can pass a column of `quantile` states under a header of `quantiles` states. `finalizeChunk` finalized it with the column's own function, producing `Float64` under an advertised `Array(Float64)`. The header checks of the deserialized steps cannot see this, so `finalizeChunk` now takes the expected finalized header and throws `ILLEGAL_COLUMN` if a state finalizes to another type (as `checkAggregateStateCanBeFinalized` does for `finalizeAggregation`). This covers `Rollup`, `Cube`, `TotalsHaving` and the in-order aggregation. The test now also reads the packets after the plan is built, so it sees the exceptions of the execution. That exposed a `LOGICAL_ERROR` for a deserialized `MergingAggregated` step with grouping sets and `distributed_aggregation_memory_efficient` (which is on by default in the step settings): the planners never combine them, so such a plan is now refused with `INCORRECT_DATA`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…d grouping-sets merge A deserialized `MergingAggregated` step with grouping sets now refuses an input in which a key occurs more than once (the output header and `makeCreatingMissingKeysForGroupingSetDAG` take keys by name), and the memory-bound merge with grouping sets, which threw a `LOGICAL_ERROR` in `transformPipeline`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Backport #131789 to 26.11: Check the aggregates of deserialized query plan steps against their input
Adapt the backport of #131789 to 26.3: - 26.3 has no serialization of `Rollup` and `Cube` steps, and no merge-only or in-order `Aggregating` step in a serialized plan, so their checks (`checkDeserializedGroupByModifierInput`, `checkDeserializedMergeOnlyInput`, the sort description checks) are dropped. The `finalizeChunk` check in the `Rollup` and `Cube` transforms is kept. - `deserializeAggregateDescriptions` has no `max_type_complexity` on 26.3. - `AggregateDescription.h` forward-declares `Block`. - The test uses query plan serialization version 0 and `ReadFromTable` leaves reading from tables created by the test; the `Rollup`, `Cube`, merge-only and in-order cases are removed. The byte layout was checked against the `clickhouse/clickhouse-server:26.3` image: the well-formed plans are accepted there, and the broken ones hit `LOGICAL_ERROR` and other errors without the fix. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Cherry pick #131789 to 26.3: Check the aggregates of deserialized query plan steps against their input
…plan steps against their input
Backport #131789 to 26.8: Check the aggregates of deserialized query plan steps against their input
Backport #131789 to 26.3: Check the aggregates of deserialized query plan steps against their input
Backport #131789 to 26.9: Check the aggregates of deserialized query plan steps against their input
Backport #131789 to 26.10: Check the aggregates of deserialized query plan steps against their input
The aggregate functions of a deserialized
Aggregatingstep are resolved from the argument types written in the plan, but theAggregatorexecutes them on the input columns found by name. A plan with other types (or without the column) made a function interpret a column of another type. Likewise, the steps that merge states (Aggregatingwithonly_merge,MergingAggregated,Rollup,Cube) merged the input columns with the functions from the plan.Such plans are now refused with
INCORRECT_DATA.checkDeserializedAggregateArgumentsrequires the arguments to be in the input with the types the function is resolved for (ignoringLowCardinality, which bothAggregateFunctionFactoryand theAggregatorremove). The merging steps read the keys and then the states by position, socheckDeserializedMergedAggregatesLayoutrequires their input to start with the keys and then the states in the order of the plan, with distinct names and states of the same representation (forMergingAggregatedwith grouping sets, per set, after the reordering done byMergingAggregatedTransform).TotalsHavingfinalizes the states it finds by name, socheckDeserializedFinalizedAggregatesrequires each of its aggregates to name an input column holding a state of the same representation.RollupandCubealways finalize and address the whole input with a mask for the keys and the states, and they finalize a single input chunk with the functions of its own columns. SocheckDeserializedGroupByModifierInputrequiresfinal, an input of exactly the keys and the states, and states that finalize to the result types of the plan. The merge-onlyAggregatingstep also requires an exact layout, becauseAggregatingInOrderTransformuses the same mask. The ordinaryAggregatingstep requires distinct key and aggregate names, because the finalization finds the states by name.States of functions that share a state representation (like
quantileandquantiles) have equal types, so aUnioncan pass a column of one under the header of the other, and the finalization used the function of the column.finalizeChunk(used byRollup,Cube,TotalsHavingand the in-order aggregation) now checks that every state finalizes to the type of the expected header, and throwsILLEGAL_COLUMNotherwise. A deserializedMergingAggregatedstep with grouping sets anddistributed_aggregation_memory_efficient(never produced by the planners) is refused instead of throwing aLOGICAL_ERROR.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix type confusion when deserializing a query plan whose aggregate functions do not match the types of their input columns. Now such a plan is rejected with
INCORRECT_DATA.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/131789]
Version info
26.12.1.19-master(included in26.12and later)26.11.1.2916,26.10.11.12,26.9.37.4,26.8.42.21,26.3.67.32