Repository navigation
Gate the -Merge aggregate state version on a protocol revision - #123070
alexey-milovidov merged 4 commits into
Conversation
…over distributed queries `medianDeterministicMerge(state)` over `remote()`, a `Distributed` table or parallel replicas returned a split-dependent result (486416 instead of 492708 for the query of ClickHouse#122935), and a `GROUP BY` of `medianDeterministic` over `remote()` failed with `Skip degree in quantileDeterministic state is 136, which exceeds the maximum value of 31`. Both are writes of a state at a version other than the one announced for the peer: - `AggregateFunctionMerge` forwarded `isVersioned` and `getDefaultVersion` but not `getVersionFromRevision`, so `NativeWriter` derived version 0 for every `-Merge` intermediate state and the reservoir's skip degree was dropped. The forward is gated on the new revision 54493: 26.8 and 26.9 (revision 54492) send `-Merge` states at version 0 without announcing a version, and an ungated forward makes a new initiator read one byte too many per state from them (measured against 26.9.6.6: `UNKNOWN_CODEC`). - `ColumnBLOB::toBLOB` (parallel block marshalling) serialized with the local type's version while `NativeWriter::write` announced the revision-derived one. Both now go through `NativeWriter::setAggregateFunctionStateVersions`. A newly declared `-Merge`-typed column now gets the current state version pinned at `CREATE`, like a column of the function itself, so it keeps the skip degree in storage; existing tables keep version 0. Closes ClickHouse#122935. CI: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=122853&sha=ec896d3cdcb1f79f80021244714eebe4ff779fc9&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20ParallelReplicas%2C%20s3%20storage%2C%20parallel%29 PR: ClickHouse#122853 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Arm E covers the other versioned nested functions under `-Merge`. Without the forward, a shard sends a `sumMapMerge` partial state at version 0, which writes each sum with the `UInt8` value type (600 becomes 88, so the result is `([1],[288])` instead of `([1],[800])`), and a marshalled `GROUP BY` block of `sumMapMerge` or `maxMapMerge` states is written at version 1 but read as version 0. Measured the same on master and on 26.9.6.6. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Drop the call-site comment in ColumnBLOB::toBLOB (the helper's declaration documents it) and cut the revision constant's comment to one line. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 4 findings over 2 rounds) plus my own
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-10:20260930-130025 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-5:20260930-102600 |
|
Workflow [PR], commit [e942536] Summary: ✅
AI ReviewSummaryThis PR gates Findings
Final VerdictLLVM Coverage ReportMeasured on commit e942536.
Changed lines: Changed C/C++ lines covered: 14/15 (93.33%) · Uncovered code |
| static std::tuple<SerializationPtr, SerializationInfoPtr, ColumnPtr> getSerializationAndColumn(UInt64 client_revision, const ColumnWithTypeAndName & column); | ||
|
|
||
| /// Sets the state versions of the aggregate functions in `type` to the ones announced to a peer at `client_revision`. | ||
| static void setAggregateFunctionStateVersions(DataTypePtr & type, UInt64 client_revision); |
There was a problem hiding this comment.
RuntimeDataflowStatisticsCacheUpdater::recordAggregationStateColumnSizes feeds the non-key aggregate-state columns into estimateCompressedColumnSize, and that helper still serializes them via the raw getSerializationAndColumn / writeData pair in src/Processors/QueryPlan/Optimizations/RuntimeDataflowStatistics.cpp:118-134. So Auto-PR will keep modeling the pre-54493 payload for exactly the -Merge / quantileDeterministic states this PR fixes on the real wire. That can underestimate replica output bytes and skew the parallel-replicas cost model on grouped/distributed aggregation queries.
Can we thread setAggregateFunctionStateVersions through that path as well, or move the version adjustment into the lower-level serialization API that these estimators use?
There was a problem hiding this comment.
Not changing this. estimateCompressedColumnSize only samples at most 8192 rows to model a compressed size for the cost model, and the state version only changes a few bytes per state (one UInt8 skip_degree for quantileDeterministic), so the estimate is not meaningfully affected. It also serializes at DBMS_TCP_PROTOCOL_VERSION with the type as stored, not the type announced to a particular peer, so there is no peer revision to derive a version from there.
Build profile diff (arm_release)Commit See the job log for details. |
…r-state-version-122935 Renumber the `-Merge` state version revision to 54494 after `uniq` state version 1 (54493), and unify the `AggregateFunctionMerge::getVersionFromRevision` override.
-Merge aggregate states and grouped quantileDeterministic over distributed queries-Merge aggregate state version on a protocol revision
|
CI (https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=123070&sha=e94253609f69a547419572296303cc00279db693&name_0=PR): every job passed except |
| | Aggregate-function versioning | `DBMS_MIN_REVISION_WITH_AGGREGATE_FUNCTIONS_VERSIONING` | `54452` | `AggregateFunction` state is written without an embedded version. | | ||
| | `skip_degree` in `quantileDeterministic` state | `DBMS_MIN_REVISION_WITH_QUANTILE_DETERMINISTIC_SKIP_DEGREE` | `54491` | `AggregateFunction(quantileDeterministic, ...)` states (and the `quantiles`/`median` spellings of the same function) are written at state version `0`, without the trailing `UInt8 skip_degree`. See the note under [type aliases](#type-aliases). | | ||
| | 64-bit hash sample in `uniq` state | `DBMS_MIN_REVISION_WITH_UNIQ_STATE_VERSION_1` | `54493` | `AggregateFunction(uniq, ...)` states are written at state version `0`: no leading flags byte and no trailing sample of 64-bit hashes. See the note under [type aliases](#type-aliases). | | ||
| | Versioned `-Merge` states | `DBMS_MIN_REVISION_WITH_MERGE_COMBINATOR_STATE_VERSION` | `54494` | A state of a `-Merge` aggregate function, such as `AggregateFunction(quantileDeterministicMerge, ...)`, is written at state version `0`, whatever version the function it merges has at that revision. | |
There was a problem hiding this comment.
The description is controversial.
|
@groeneai make the description clearer in a follow-up PR when this PR is merged. |
|
Acknowledged. After this PR is merged I will send a follow-up that makes the description of revision |
9417c18
|
The follow-up is #125115. |
The rows describing `DBMS_MIN_REVISION_WITH_MERGE_COMBINATOR_STATE_VERSION` in `format.mdx` and `protocol.mdx` said that a `-Merge` state is written at version 0 "whatever version the function it merges has", without naming the column type, without saying that the version belongs to that type rather than to the merged function, and without describing the reader. Each row now names the full type of the partial state a shard sends for a distributed `quantileDeterministicMerge`, states both directions below the revision (written at version 0; a type string with no outer version is read at version 0), and says that a version spelled in the argument type does not apply to the payload. The protocol row also notes that the binary type encoding always carries the version. Checked on a debug build of master over HTTP with `client_protocol_version` 54490/54492/54493/54494 (type strings, binary type encoding, payload bytes) and with a distributed `quantileDeterministicMerge` against 26.9.9.28 in both directions. Requested in ClickHouse#123070 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
The bugs behind their `no-parallel-replicas` / `no-replicated-database` tags are fixed on master: - `01660_join_or_any`: ClickHouse#123683 - `04653_bloom_filter_fixed_string_constant_scalar`: ClickHouse#118988 - `04819_dynamic_aggregate_function_state_version`: ClickHouse#123649 - `04825_quantile_deterministic_alter_add_modify_column`: ClickHouse#115393, ClickHouse#123070 - `04494_atomic_populate_materialized_view_parallel_replicas`: ClickHouse#124477 - `04266_text_index_tokens_cardinality_order`: ClickHouse#124500 already disables parallel replicas for the log-checked query Related: ClickHouse#124015
Closes: #122935
Related: #112052
Related: #122853
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Keep exchanging
-Mergeaggregate states with servers of older releases working: the state version of a-Mergefunction follows the state version of the function it merges only for peers that announce the new protocol revision 54494.Description
The original bug of #122935 (
-Mergestates always sent at version 0, andColumnBLOB::toBLOBwriting the local type's version) is already fixed on master by theuniqstate version 1 change, which forwardsgetVersionFromRevisioninAggregateFunctionMergeand derives the version inColumnBLOB::toBLOB. That forward is not gated by a revision: 26.8 and 26.9 send-Mergestates at version 0 without announcing it, so a master server cannot read them (UNKNOWN_CODEC) and they cannot read the states it sends.This PR gates the forward on the new revision 54494 (
DBMS_MIN_REVISION_WITH_MERGE_COMBINATOR_STATE_VERSION, after 54493 of theuniqstate version 1), so-Mergestates to and from older peers are unchanged, and shares the version derivation betweenNativeWriter::writeandColumnBLOB::toBLOBinNativeWriter::setAggregateFunctionStateVersions. The new test coversquantileDeterministicMerge,sumMapMergeandmaxMapMergeoverremote(), also with parallel blocks marshalling; it passes on master as well, so the bugfix validation does not apply.Workflow [PR]
Sync PR [sync-upstream/pr/123070]
Version info
26.10.1.2073-master(included in26.10and later)