Repository navigation
Conversation
… row WITH TOTALS together with max_rows_to_group_by and group_by_overflow_mode = 'any' sets Aggregator::Params::overflow_row, which makes TotalsHavingTransform::transform require an AggregatedChunkInfo on every chunk it sees, and it tests that before its own early return for an empty chunk. Aggregation in order cannot serve such a query. Its only aggregation entry point is Aggregator::executeOnBlockSmall, which calls the five-argument executeImpl with overflow_row = nullptr, so the is_overflows chunk is never produced. optimizeAggregationInOrder has refused the combination since c5f93eb ("It just does not work"), but the force_aggregation_in_order branch of both Planner::addAggregationStep and InterpreterSelectQuery::executeAggregation consulted only the setting and the grouping-sets state, so the in-order step was built anyway, and optimizeAggregationInOrder cannot undo it because its early return is skipped once explicitSortingRequired() is set from the same bool. Two or more parts are then needed to observe it. FinishAggregatingInOrderAlgorithm::consume skips row-less inputs, so with every stream empty prepareToMerge emits an empty ChunksToMerge; MergingAggregatedBucketTransform::transform attaches its AggregatedChunkInfo to a chunk that mergeBlocks left with zero columns, and the header conformance back-fill in ISimpleTransform::work then replaces that chunk wholesale and discards chunk_infos. With a single part the tail is FinalizeAggregatedTransform, which back-fills the missing info, which is why one part passes. Gating the local bool on overflow_row is sufficient at both sites, because the same bool also supplies AggregatingStep's explicit_sorting_required_for_aggregation_in_order argument: the sort descriptions stay empty, inOrder() and explicitSortingRequired() are both false, memoryBoundMergingWillBeUsed() is false, and transformPipeline takes the hash branch that does call checkLimits and does emit the is_overflows chunk. This is the shape ClickHouse#109862 used for the neighbouring grouping-sets condition in the same expression. The old analysis is still reached for a mutation scalar subquery, which reproduced the identical assertion, so it is guarded too and the new test covers that route. The projection construction site cannot reach it: a projection SELECT does not parse with WITH TOTALS. Found by the AST fuzzer (amd_msan) on an unrelated carrier pull request: https://github.com/ClickHouse/ClickHouse/actions/runs/35659017389/job/106583430653 Co-Authored-By: Claude Opus 5 <[email protected]>
Drop the optimizeAggregationInOrder cross-reference from the Planner comment; it is in the commit message.
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model over three rounds (engine: codex; 3 findings), plus my
Also noticed while reviewing, and deliberately not raised further: the header conformance back-fill in Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-10:20260922-084100 |
Pre-PR validation gate (click to expand)
Also run: 58 tests across the TOTALS / overflow-row / aggregation-in-order families (45 OK; the 13 failures fail identically on the unpatched binary, all Session id: cron:clickhouse-impl-slot-5:20260922-081502 |
|
Workflow [PR], commit [1e41ef1] Summary: ✅
AI ReviewSummaryThe planner now disables forced aggregation in order when an aggregation overflow row is required, and Final VerdictStatus: ✅ Approve |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units8 translation units recompiled, 40 s compile time in total, 8 of them have a recent master baseline. |
AggregatingStep::deserialize rebuilds overflow_row (flag bit 2) and the in-order sort descriptions (bit 32) independently, and neither the AggregatingStep constructor nor deserialize cross-checks them, so the combination the planner now refuses was still accepted when the plan came off the wire instead of being built locally. A deserialized plan is not planned on the receiving node, so nothing else downstream declines it. Measured on two servers, the initiator one commit behind this branch and the receiving server carrying it with process_query_plan_packet enabled: a serialize_query_plan = 1 query whose shipped fragment holds both the in-order Aggregating and the TotalsHaving (EXPLAIN distributed = 1 shows the pair) reached 'Chunk should have AggregatedChunkInfo in TotalsHavingTransform.' at TotalsHavingTransform.cpp:160 on the receiving server, which in these debug builds terminated it. With this commit the same query returns INCORRECT_DATA and the server stays up. The check reads the flags rather than the reconstructed step so that it sits with the two version gates already in deserialize, which reject invalid flag combinations the same way. Enforcing the invariant in the AggregatingStep constructor instead would not cover the optimizer: optimizeAggregationInOrder turns a step in-order through applyOrder after construction, so a constructor check cannot see that path. There is no serialize-side twin, unlike the two version gates: a node running this code cannot build the pair, so a check there would only guard already-corrupt state. Only a gtest can present the offending stream, because a server that refuses to build the pair also never serializes it, so the coverage extends the existing AggregatingStep serialization gtest rather than the stateless test. Co-Authored-By: Claude Opus 5 <[email protected]>
CI finish ledger - e24a610Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only
Neither row belongs to this diff. The crash path runs through Attribution note, since a SIGSEGV is never written off as noise here: the stack on this head is the Session id: cron:our-pr-ci-monitor:20260923-010313 |
…r-overflow-row # Conflicts: # src/Interpreters/InterpreterSelectQuery.cpp
Master now builds a scalar subquery with `InterpreterSelectQueryAnalyzer` (`ExecuteScalarSubqueriesVisitor`), so a mutation's scalar subquery is planned by `Planner` and the `Planner` guard covers it. What still reaches `InterpreterSelectQuery::executeAggregation` is the projection machinery and the AST arms of `EXPLAIN`, and a projection query cannot carry `WITH TOTALS`, so `overflow_row` is never set there. The mutation arm of the test stays: it still raises the logical error on master without the `Planner` guard. Co-Authored-By: Claude Opus 5.5 <[email protected]>
CI finish ledger - 4a7600bEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only Every job that ran on this head passed (0 failed tests in CIDB). The red comes only from 3 jobs that never ran.
Session id: cron:our-pr-ci-monitor:20261007-180301 |
…r-overflow-row `src/Planner/Planner.cpp` was split on master (f6de30c moved `addAggregationStep` into `src/Planner/PlannerSteps.cpp`). Resolved by taking master's Planner.cpp and porting the `!aggregator_params.overflow_row` conjunct to PlannerSteps.cpp.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Aggregation in order is no longer used when a query needs an aggregation overflow row, that is
WITH TOTALStogether withmax_rows_to_group_byandgroup_by_overflow_mode = 'any'. That path never produces the overflow row, so withforce_aggregation_in_orderset such a query could fail withChunk should have AggregatedChunkInfo in TotalsHavingTransform.Description
Failing job: https://github.com/ClickHouse/ClickHouse/actions/runs/35659017389/job/106583430653 (
AST fuzzer (amd_msan)), resultLogical error: Chunk should have AggregatedChunkInfo in TotalsHavingTransform. (STID: 3546-3720). It surfaced on PR #113856, which is only the carrier: that PR changes text index files undersrc/Storages/MergeTreeonly.WITH TOTALSwithmax_rows_to_group_byandgroup_by_overflow_mode = 'any'setsoverflow_row, soTotalsHavingTransformrequires anAggregatedChunkInfoon every chunk. Aggregation in order cannot serve that:AggregatingInOrderTransformaggregates throughAggregator::executeOnBlockSmall, which passesoverflow_row = nullptr, so theis_overflowschunk is never produced.optimizeAggregationInOrderhas refused the combination since c5f93eb, but theforce_aggregation_in_orderbranch of the planner consulted only the setting, so the in-order step was built anyway; with two or more parts the all-empty merge product then loses its chunk info to the header conformance back-fill inISimpleTransform::work, and the precondition is violated.The planner now also tests
overflow_row, which is the shape #109862 used for the neighbouring condition in the same expression.AggregatingStep::deserializerejects a serialized plan that carries both withINCORRECT_DATA, so an older initiator cannot ship the combination to a server that accepts query plan packets.The new test reproduces it deterministically on a Debug build: four single-row parts, a filter that reads every part and matches no row, and
GROUP BY ... WITH TOTALSwith those settings. It also coversWITH ROLLUPand a mutation's scalar subquery, and pins that noAggregatingInOrderTransformis built for such a query while one still is without the overflow settings.Keeping
chunk_infosacross that back-fill would silence the error too, but the query would still run on a path that never produces the overflow row, so the refusal belongs in the planner.Workflow [PR]
Sync PR [sync-upstream/pr/121522]