Repository navigation
Cherry pick #111803 to 26.6: Added a setting text_index_version for better forward compatibility - #115612
Merged
robot-ch-test-poll3 merged 21 commits intoAug 21, 2026
Conversation
The text index header version was recently bumped to `WithCodec` and is now written unconditionally, which prevents rolling a server back after it has written a text index part in the new format: older servers reject the unknown header version. Introduce a `text_index_version` MergeTree setting (enum `MergeTreeTextIndexVersion` with values `initial` and `with_codec`, default `with_codec`). During a rolling upgrade it can be set to `initial` so that newer servers keep writing the previous on-disk format that older servers can still read; the `compatibility` setting reverts it to `initial` automatically for versions older than 26.6. The version is resolved fresh from the table settings on every write (insert and merge), so it takes effect on `ALTER ... MODIFY SETTING` without rebuilding the index. `serializeHeader` writes the codec byte only for `with_codec`. The `initial` format does not persist the codec type and the per-block index section postdates it, so `initial` combined with a non-`none` posting list codec throws instead of producing a part that older servers would misread. `MergeTreeTextIndexVersion` is the single source of truth for the text index version concept (header, params, postings serialization); the generic `MergeTreeIndexVersion` is kept only at the index framework boundary. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Reject the `text_index_version = 'initial'` + `text_index_posting_list_codec != 'none'` combination while validating MergeTree settings, in `MergeTreeSettingsImpl::sanityCheck`, so the conflict is reported up front on CREATE and ALTER instead of only later at write time. `sanityCheck` runs only when the table is created or its settings are explicitly changed, not on attach, so an existing table that ends up in this combination via the `compatibility` setting still loads and serves reads. The write-time check in `serializeHeader` remains as the backstop for the case `sanityCheck` cannot see: a per-index `posting_list_codec` argument while the table-level codec setting is `none`. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…-setting Resolve conflicts with the text index positions support (support_phrase_search) from master and extend the text_index_version MergeTree setting with the new with_positions format version: - MergeTreeTextIndexVersion replaces TextIndexHeader::Version, gaining WithPositions = 2; enum values are pinned by static_asserts. - text_index_version defaults to with_positions and acts as a cap on the optional format features: an index with support_phrase_search always writes the WithPositions format; an index without it writes min(setting, with_codec), which keeps default behavior byte-identical to master. - textIndexValidator rejects support_phrase_search = 1 when text_index_version is pinned below with_positions on CREATE/ALTER (skipped on attach so tables still load under a compatibility pin); serializeHeader keeps a write-time backstop. - SettingsChangesHistory: with_codec -> with_positions in 26.7 (the release that introduced the WithPositions format), so compatibility resolves to initial / with_codec / with_positions for 26.5 / 26.6 / 26.7+. Co-Authored-By: Claude Fable 5 <[email protected]>
…-time constraint The effective serialization version of a text index is now resolved once, in `textIndexCreator`, by clamping the setting to what the index definition can represent: `support_phrase_search` requires exactly `v2_with_positions`, a posting list codec requires at least `v1_with_codec`, and an index without positions gains nothing from `v2_with_positions`. The resolution is total, so writing a text index never fails because of the setting (e.g. when `compatibility` pins an older default), and readers take the version from the on-disk header of each part. Remove the write-time rejection (`checkSerializationVersionForWrite` called from `createIndexAggregator` and `MergeTextIndexesTask`) and the prospective revalidation of text indexes in `checkAlterIsPossible`. The checks in `serializeHeader` become logical-error invariants. Explicit contradictions are still rejected at creation time: an index with `support_phrase_search` cannot be created while the setting is below `v2_with_positions`, an index with a `posting_list_codec` argument other than `none` cannot be created while it is `v0_initial` (previously this combination was accepted and threw on the first INSERT), and the conflicting pair of table settings keeps being rejected by the settings sanity check. Co-Authored-By: Claude Fable 5 <[email protected]>
Rebaseline `02346_text_index_posting_list_compression_data_size_validation`. With the default `text_index_serialization_version = 'v2_with_positions'` every text index is written in the `v2_with_positions` format, including an index without positions, so its header carries one extra `has_positions` varuint per granule (+2 compressed bytes per table in this test). Update the documentation, the setting description and the comments in `test_text_index_upgrade` that claimed an index without positions is written at most in the `v1_with_codec` format. Add the `database = currentDatabase()` condition to the `system.parts` query in `04630_text_index_serialization_version_compatibility` for the style check. CI reports: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=111803&sha=c021c515c1963640457b44da99817156b9db7b68&name_0=PR&name_1=Style%20check https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=111803&sha=c021c515c1963640457b44da99817156b9db7b68&name_0=PR&name_1=Fast%20test Related: #111803 Co-Authored-By: Claude Opus 5 <[email protected]>
- Remove unit test `PostingListCursorTest.TextIndexHeaderInitialVersionWithCodecThrows`: it expected `serializeHeader` to throw on the `v0_initial` + codec combination, but that mismatch is a `LOGICAL_ERROR` now (`textIndexCreator` always raises the version to fit the codec), and `LOGICAL_ERROR` aborts in debug/sanitizer builds before the exception propagates, so the test aborted with SIGABRT in the ASan/TSan/MSan unit test jobs. - Speed up `04408_text_index_serialization_version_setting`: with `index_granularity = 1` every 512-row insert produced 512 text index granules per part, each serializing its own header, dictionary and posting lists, which exceeded the 180 s per-run limit of the flaky check on the debug build with the thread fuzzer enabled. Use `index_granularity = 64` (8 index granules per part) - this still exercises the per-granule version headers and the merge path, and keeps the reference unchanged. Failed CI: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=111803&sha=40668f7d90e8ad1c3918b9eb078f5f927c284d88 PR: #111803 Co-Authored-By: Claude Fable 5 <[email protected]>
…-setting Conflict resolutions: * `MergeTreeIndexText.h`/`.cpp`: master introduced `PostingsSerialization::resolveCodec` and the raw/compressed mutual-exclusion check, which supersede the inline codec resolution in `deserialize` on this branch. `resolveCodec` referred to the nested `TextIndexHeader::Version` enum that this branch replaced with the settings-backed `MergeTreeTextIndexSerializationVersion`, so it now compares against `V1_WithCodec`. Kept master's new `checkTokenSize` next to this branch's `serializeHeader` signature. * `test_text_index_upgrade/test.py`: kept master's rename of `LAZY_APPLY_SETTINGS` to `SEARCH_SETTINGS` and this branch's version vocabulary in the comments. * `docs/en/engines/table-engines/mergetree-family/textindexes.md`: deleted by master's docs restructure; the `text_index_serialization_version` section moved to `docs/reference/engines/table-engines/mergetree-family/textindexes.mdx` with the new link slugs.
Review comments from #111803: - Reword the confusing "oldest format that can otherwise" sentence: a newer version that can represent the index is chosen automatically. - Remove implementation details from the guide page; keep them only in the setting description in MergeTreeSettings.cpp. - Recommend the profile-level compatibility pin for rolling upgrades and warn against ALTER TABLE ... MODIFY SETTING on replicated tables, because the persisted setting cannot be parsed by replicas running an older version. Co-Authored-By: Claude Fable 5 <[email protected]>
Remove the settings sanity check that rejected 'v0_initial' combined with a non-'none' text_index_posting_list_codec. The write path already chooses 'v1_with_codec' automatically for such indexes, and the check validated effective values, so it could fire without the user touching the version setting (e.g. under a compatibility pin) and even for tables without any text index. The validator checks for explicit index arguments contradicting the pinned version are kept. Rework the rejection cases in test 04408 into positive tests of the clamping behavior, shorten the setting description and the docs, and simplify the version resolution in textIndexCreator. Co-Authored-By: Claude Fable 5 <[email protected]>
Reuse a local variable for `text_index_serialization_version` in `textIndexValidator` and trim the comments there. Update `test_change_codec_after_upgrade`: setting `text_index_serialization_version = 'v0_initial'` while the table default codec is `bitpacking` is no longer an error, because the write path bumps such an index to `v1_with_codec`. Co-Authored-By: Claude Opus 5 <[email protected]>
`text_index_serialization_version` is introduced by this pull request, so the autogenerated page `reference/settings/merge-tree-settings/text-index` does not contain its anchor yet, and `lychee` reports `Cannot find fragment`. Link to the page instead of the anchor. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=111803&sha=588e228ba9ba4dd8580d9f8418e3d71aaddee1da&name_0=PR&name_1=Docs+check+%28Mintlify%29 Pull request: #111803 Co-Authored-By: Claude Opus 5 <[email protected]>
…ation `assert_index_used` explained `SELECT count() ... WHERE hasToken(...)`, which the new binary now answers with `ReadFromTextIndexCount` (added to `master` by `optimizeTrivialCountFromTextIndex.cpp`). That plan has no `ReadFromMergeTree` step, so the `Name: idx` line the assertion looks for is absent. The two other call sites run on the old binary, where the optimization does not exist, so only the check on the new binary failed. Explain a query that reads a column instead. Both binaries then produce a `ReadFromMergeTree` step with the `Indexes` section (verified against `clickhouse/clickhouse-server:26.4` and the current build). CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=111803&sha=416261899380b7f3a8f068a457d99e3b2d29e710&name_0=PR&name_1=Integration%20tests%20%28amd_asan_ubsan%2C%20flaky%29 Pull request: #111803 Related: #111494 Co-Authored-By: Claude Opus 5 <[email protected]>
Make `text_index_serialization_version` a pure preference on all DDL paths: `textIndexValidator` no longer rejects `support_phrase_search` or a `posting_list_codec` argument under an older pinned version. Instead `textIndexCreator` raises the version to one that can represent the index features, on CREATE TABLE and ALTER ADD INDEX as well as on ATTACH. Co-Authored-By: Claude Fable 5 <[email protected]>
…tion Per review, the paragraph about `text_index_serialization_version` and the rolling-upgrade `compatibility` pin was hidden in the collapsible advanced-parameters block. Move it to a new visible section next to Limitations. #111803 (comment) Co-Authored-By: Claude Fable 5 <[email protected]>
Added a setting `text_index_version` for better forward compatibility
# Conflicts: # src/Core/SettingsChangesHistory.cpp # src/Storages/MergeTree/MergeTreeIndexText.cpp # src/Storages/MergeTree/MergeTreeReaderTextIndex.cpp # src/Storages/MergeTree/MergeTreeSettings.cpp # tests/integration/test_text_index_upgrade/test.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Original pull-request #111803
Do not merge this PR manually
This pull-request is a first step of an automated backporting.
It contains changes similar to calling
git cherry-picklocally.If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.
The check results does not matter at this step - you can safely ignore them.
Troubleshooting
If the conflicts were resolved in a wrong way
If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job