Skip to content

Add setting for compatibility serialziation of string - #90880

Merged
antonio2368 merged 14 commits into
masterfrom
setting-for-compatibility-serialization
Dec 2, 2025
Merged

antonio2368 merged 14 commits into
masterfrom
setting-for-compatibility-serialization

Conversation

@antonio2368

@antonio2368 antonio2368 commented Nov 26, 2025 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fix compatibility of in-memory serialization of String aggregation state. Different serialization could lead to duplicate results if aggregation query is executed on instances with different versions.
New serialization can be enabled with serialize_string_in_memory_with_zero_byte.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

@clickhouse-gh

clickhouse-gh Bot commented Nov 26, 2025 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [79dabb2]

Summary: ❌

job_name test_name status info comment
Bugfix validation (integration tests) failure
test_database_replicated_settings/test.py::test_database_replicated_settings[None-None-None-None-None-None-None-True] FAIL cidb
test_database_replicated_settings/test.py::test_database_replicated_settings[None-None-None-None-None-None-None-False] FAIL cidb
test_database_replicated_settings/test.py::test_database_replicated_settings[None-None-None-None-None-None-0.5-True] FAIL cidb
test_database_replicated_settings/test.py::test_database_replicated_settings[None-None-None-None-None-None-0.5-False] FAIL cidb
test_database_replicated_settings/test.py::test_database_replicated_settings[None-None-None-None-None-10-None-True] FAIL cidb
test_database_replicated_settings/test.py::test_database_replicated_settings[None-None-None-None-None-10-None-False] FAIL cidb
test_database_replicated_settings/test.py::test_database_replicated_settings[None-None-None-None-None-10-0.5-True] FAIL cidb
test_refreshable_mat_view/test.py::test_simple_append[True-True-SELECT now() as a, number as b FROM numbers(2)] FAIL cidb
test_database_replicated_settings/test.py::test_database_replicated_settings[None-None-None-None-None-10-0.5-False] FAIL cidb
test_database_replicated_settings/test.py::test_database_replicated_settings[None-None-None-None-900-None-None-True] FAIL cidb
2199 more test cases not shown
Stateless tests (amd_msan, parallel) failure
03338_http_compression_profile_events FAIL cidb
02801_backup_native_copy FAIL cidb
02346_text_index_queries FAIL cidb
00411_long_accurate_number_comparison_int2 FAIL cidb
Integration tests (amd_asan, db disk, old analyzer, 3/6) failure
test_accept_invalid_certificate/test.py::test_strict_reject_with_config FAIL cidb
Integration tests (amd_binary, 2/5) failure
test_keeper_disks/test.py::test_logs_with_disks FAIL cidb
BuzzHouse (amd_debug) failure
Logical error: 'Inconsistent AST formatting: the query: FAIL cidb
BuzzHouse (arm_asan) failure
Logical error: 'Function writeSlice expects same column types for GenericArraySlice and GenericArraySink.' FAIL cidb
BuzzHouse (amd_ubsan) failure
Segmentation fault (STID: 1539-2bd2) FAIL cidb
Integration tests (amd_asan, flaky) error

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Nov 26, 2025
Comment thread src/Columns/IColumn.h Resolved
@antonio2368
antonio2368 requested a review from Copilot November 26, 2025 15:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a compatibility issue in the in-memory serialization of String aggregation states that could lead to duplicate results when executing aggregation queries across a cluster with mixed ClickHouse versions. The fix introduces a new setting serialize_string_in_memory_with_zero_byte (defaulting to true) that controls whether String values are serialized with a trailing zero byte during aggregation. This ensures consistent serialization behavior across different server versions.

Key Changes:

  • Added serialize_string_in_memory_with_zero_byte setting to control String serialization behavior during aggregation
  • Updated all serialization/deserialization methods across column types to accept and propagate SerializationSettings
  • Modified String column serialization to conditionally append zero byte based on the new setting

Reviewed changes

Copilot reviewed 69 out of 70 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/integration/test_string_aggregation_compatibility/test.py Integration tests verifying compatibility between versions with/without the new setting
src/Core/Settings.cpp Added serialize_string_in_memory_with_zero_byte setting definition
src/Core/SettingsChangesHistory.cpp Registered the new setting in version 25.8 history
src/Columns/IColumn.h Added SerializationSettings struct and updated all serialization method signatures
src/Columns/ColumnString.cpp Core logic changes to conditionally serialize strings with zero byte terminator
src/Columns/ColumnUnique.h Updated deserialization to handle zero byte when setting is enabled
src/Interpreters/Aggregator.h Added serialize_string_with_zero_byte parameter to Aggregator::Params
src/Interpreters/Aggregator.cpp Propagates serialization settings through aggregation methods
src/Common/ColumnsHashing.h Extended HashMethodSerialized to use serialization settings
Multiple column types Updated all column implementations to accept and forward SerializationSettings parameter

Comment thread src/Columns/ColumnUnique.h Resolved
Comment thread src/Interpreters/Aggregator.cpp Resolved
Comment thread src/Columns/ColumnString.cpp Resolved
Comment thread src/Common/ColumnsHashing.h Resolved
@antonio2368 antonio2368 added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Nov 28, 2025
@antonio2368
antonio2368 added this pull request to the merge queue Dec 2, 2025
Merged via the queue into master with commit 7b11fdc Dec 2, 2025
@antonio2368
antonio2368 deleted the setting-for-compatibility-serialization branch December 2, 2025 11:52
@robot-ch-test-poll1 robot-ch-test-poll1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Dec 2, 2025
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Dec 2, 2025
@robot-ch-test-poll1 robot-ch-test-poll1 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Dec 2, 2025
antonio2368 added a commit that referenced this pull request Dec 5, 2025
Backport #90880 to 25.8: Add setting for compatibility serialziation of string
antonio2368 pushed a commit that referenced this pull request Dec 5, 2025
clickhouse-gh Bot added a commit that referenced this pull request Dec 5, 2025
Backport #90880 to 25.10: Add setting for compatibility serialziation of string
clickhouse-gh Bot added a commit that referenced this pull request Dec 5, 2025
Backport #90880 to 25.9: Add setting for compatibility serialziation of string
antonio2368 added a commit that referenced this pull request Dec 5, 2025
Backport #90880 to 25.11: Add setting for compatibility serialziation of string
alexey-milovidov added a commit to amosbird/ClickHouse that referenced this pull request May 9, 2026
…ision

The test was added in ClickHouse#90880 to demonstrate a cross-version string
serialization bug that only manifests when two-level aggregation is
active across servers running incompatible serialization formats.

This PR introduces `AggregationMethodPackedString` for the `key_string`
slot, replacing `AggregationMethodString` (`StringHashTable`). Because
the on-the-wire layout for single-string-key aggregation states is
incompatible between the two methods, this PR raises
`DBMS_MIN_REVISION_WITH_CURRENT_AGGREGATION_VARIANT_SELECTION_METHOD`
from 54448 to 54484. As a side effect, two-level aggregation is now
disabled in distributed queries against any server older than 54484
(including 25.6, used by `node256` in the integration test), and the
bug demonstrated by the test cannot be reproduced anymore — the
deduplication succeeds and the query returns 10000 instead of 20000.

Update the assertion to 10000 and add a comment explaining the change.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=93271&sha=6bde8cea7bc1e97b3d8cd5c96e902042f1c7fd60&name_0=PR&name_1=Integration%20tests%20%28amd_tsan%2C%205%2F6%29

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
alexey-milovidov added a commit to amosbird/ClickHouse that referenced this pull request May 19, 2026
…ision

The test was added in ClickHouse#90880 to demonstrate a cross-version string
serialization bug that only manifests when two-level aggregation is
active across servers running incompatible serialization formats.

This PR introduces `AggregationMethodPackedString` for the `key_string`
slot, replacing `AggregationMethodString` (`StringHashTable`). Because
the on-the-wire layout for single-string-key aggregation states is
incompatible between the two methods, this PR raises
`DBMS_MIN_REVISION_WITH_CURRENT_AGGREGATION_VARIANT_SELECTION_METHOD`
from 54448 to 54484. As a side effect, two-level aggregation is now
disabled in distributed queries against any server older than 54484
(including 25.6, used by `node256` in the integration test), and the
bug demonstrated by the test cannot be reproduced anymore — the
deduplication succeeds and the query returns 10000 instead of 20000.

Update the assertion to 10000 and add a comment explaining the change.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=93271&sha=6bde8cea7bc1e97b3d8cd5c96e902042f1c7fd60&name_0=PR&name_1=Integration%20tests%20%28amd_tsan%2C%205%2F6%29

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
pull Bot pushed a commit to admariner/ClickHouse that referenced this pull request Jul 26, 2026
…ision

The test was added in ClickHouse#90880 to demonstrate a cross-version string
serialization bug that only manifests when two-level aggregation is
active across servers running incompatible serialization formats.

This PR introduces `AggregationMethodPackedString` for the `key_string`
slot, replacing `AggregationMethodString` (`StringHashTable`). Because
the on-the-wire layout for single-string-key aggregation states is
incompatible between the two methods, this PR raises
`DBMS_MIN_REVISION_WITH_CURRENT_AGGREGATION_VARIANT_SELECTION_METHOD`
from 54448 to 54484. As a side effect, two-level aggregation is now
disabled in distributed queries against any server older than 54484
(including 25.6, used by `node256` in the integration test), and the
bug demonstrated by the test cannot be reproduced anymore — the
deduplication succeeds and the query returns 10000 instead of 20000.

Update the assertion to 10000 and add a comment explaining the change.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=93271&sha=6bde8cea7bc1e97b3d8cd5c96e902042f1c7fd60&name_0=PR&name_1=Integration%20tests%20%28amd_tsan%2C%205%2F6%29

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Aug 8, 2026
The previous commit wrote only `false`, on the argument that an absent name
leaves the receiver at the declared default `true`. That is true of a receiver
that declares the name, and wrong of the receivers the argument was meant to
protect.

`v25.8.12.129-lts` does not declare the setting, and its GROUP BY key path
(`serializeKeysToPoolContiguous` -> `ColumnString::serializeValueIntoArena`)
takes no serialization settings and writes no trailing zero byte - it behaves
exactly like `serialize_string_in_memory_with_zero_byte = false`. Omitting
`true` towards such a peer therefore does not leave it at `true`; it silently
hands it the other key layout, which is the divergence this PR exists to close.
`v25.8.13.73-lts` backported the setting (ClickHouse#90880) and does default it to `true`,
yet both advertise query-plan serialization version 0, so `version` cannot tell
the two apart and no gate can be built on it.

So the assignment goes back to unconditional, and the test now requires the name
on the wire for both values at version 0 as well as at the current version.
Reverting either production line still fails exactly that step's round-trip test.

Found by the second-model review, which caught the bad premise in the previous
commit.
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…ision

The test was added in ClickHouse#90880 to demonstrate a cross-version string
serialization bug that only manifests when two-level aggregation is
active across servers running incompatible serialization formats.

This PR introduces `AggregationMethodPackedString` for the `key_string`
slot, replacing `AggregationMethodString` (`StringHashTable`). Because
the on-the-wire layout for single-string-key aggregation states is
incompatible between the two methods, this PR raises
`DBMS_MIN_REVISION_WITH_CURRENT_AGGREGATION_VARIANT_SELECTION_METHOD`
from 54448 to 54484. As a side effect, two-level aggregation is now
disabled in distributed queries against any server older than 54484
(including 25.6, used by `node256` in the integration test), and the
bug demonstrated by the test cannot be reproduced anymore — the
deduplication succeeds and the query returns 10000 instead of 20000.

Update the assertion to 10000 and add a comment explaining the change.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=93271&sha=6bde8cea7bc1e97b3d8cd5c96e902042f1c7fd60&name_0=PR&name_1=Integration%20tests%20%28amd_tsan%2C%205%2F6%29

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants