Repository navigation
Added a setting text_index_version for better forward compatibility - #111803
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]>
|
Workflow [PR], commit [d81ce3b] Summary: ❌
AI ReviewSummaryThis PR introduces PR Metadata
Findings❌ Blockers
Tests
Final Verdict
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 173/175 (98.86%) · Uncovered code |
…-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: ClickHouse#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: ClickHouse#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 ClickHouse#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: ClickHouse#111803 Co-Authored-By: Claude Opus 5 <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Object file sizes16 object files changed (+43.11 KiB total), 0 added.
737 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 units1867 translation units recompiled, 10878 s compile time in total, 1867 of them have a recent master baseline. Median compile-time ratio to the baselines is ×0.94 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio. |
…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: ClickHouse#111803 Related: ClickHouse#111494 Co-Authored-By: Claude Opus 5 <[email protected]>
| Changing a table-level setting applies the new parameters only to text indexes built for new parts; existing parts keep their current layout. | ||
|
|
||
| The on-disk format version of text indexes is controlled by the table-level setting [`text_index_serialization_version`](/reference/settings/merge-tree-settings/text-index) (default: `v2_with_positions`). | ||
| The setting is a preference rather than a hard constraint: if the configured version cannot represent an index, a newer version that can represent it is chosen automatically, so writing a text index never fails because of this setting. |
There was a problem hiding this comment.
The setting is a preference rather than a hard constraint: if the configured version cannot represent an index, a newer version that can represent it is chosen automatically, so writing a text index never fails because of this setting.
I'm not sure this is a good semantics. It leaves some unnecessary leeway so that upgrades can still fail.
As of today, I think the only relevant situation today where the configured version may not represent the index is phrase search support (index argument support_phrase_search). It's fine IMHO to fail when writing a text index.
There was a problem hiding this comment.
I think the current semantic is ok. The effective version raised only when the user explicitly enables a feature that requires it (e.g. support_phrase_search). I'd like to avoid a case where, to enable a new feature, a customer first has to bump an obscure setting, which isn't trivial because its value comes from the config (e.g. a compatibility pin). It's expected that if you enable a new feature, it won't be supported on older servers anyway.
If we throw instead of adjusting the version, we have to deal with inconvenient cases: e.g. the index is already created in the new format, and the version setting is then lowered in the config. INSERTs and merges must keep working, so we need the adjusting semantics on attach anyway — and the setting would behave differently depending on how the table reached that state.
| {"shared_merge_tree_merge_coordinator_distribution_algorithm", "water_filling", "sainte_lague", "Enable Sainte-Lague distribution by default."}, | ||
| {"text_index_max_processed_tokens_before_flush", 100000000, 100000000, "New setting"}, | ||
| {"text_index_max_memory_usage_before_flush", std::numeric_limits<UInt64>::max(), 1073741824, "New setting. The previous value disables memory-based flushing to preserve pre-26.8 behavior"}, | ||
| {"text_index_serialization_version", "v1_with_codec", "v2_with_positions", "Allow the 'v2_with_positions' text index format that persists token positions for phrase search. Reverts to 'v1_with_codec' under older compatibility so that newer servers keep writing the format that older servers can read during a rolling upgrade."}, |
There was a problem hiding this comment.
I'm 99% sure that v2 became the default in 26.6 already.
There was a problem hiding this comment.
I have to add an entry to the 26.8 version to pass CI.
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. ClickHouse#111803 (comment) Co-Authored-By: Claude Fable 5 <[email protected]>
bddae8d
Cherry pick #111803 to 26.6: Added a setting `text_index_version` for better forward compatibility
…tter forward compatibility
Cherry pick #111803 to 26.7: Added a setting `text_index_version` for better forward compatibility
…tter forward compatibility
Backport #111803 to 26.7: Added a setting `text_index_version` for better forward compatibility
Fix build in the 26.6 backport of #111803
Backport #111803 to 26.6: Added a setting `text_index_version` for better forward compatibility
The test compares `system.settings` / `system.merge_tree_settings` against baselines captured from a *pre-release* of 26.6, and required every setting missing from the baselines to have a `SettingsChangesHistory.cpp` entry with a version strictly greater than `26.6`. That is too strict for a setting introduced later in the 26.6 series. The `MergeTree` setting `text_index_serialization_version` was added to the 26.6 branch by the backport of ClickHouse#111803, i.e. after the v26.6.1 pre-release the baselines were generated from, so it is absent from `02995_merge_tree_settings_settings_26_6_1.tsv` while its history entry correctly says `26.6`. As a result the test failed deterministically for every pull request based on `26.7`: PLEASE ADD THE NEW MERGE_TREE_SETTING TO SettingsChangesHistory.cpp: text_index_serialization_version WAS ADDED Accept `26.6` in the version comparison: a setting that is absent from the baselines must carry a history entry of 26.6 or later. No strictness is lost - settings that were already present in the baselines never reach this predicate. On `master` the test does not exist anymore, it was replaced by `03999_stateless_settings_history` in ClickHouse#111605, so this fix is only needed on the release branch.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Added a new MergeTree setting
text_index_versionthat controls the on-disk format version of text indexes:v0_initial,v1_with_codec, orv2_with_positions. During a rolling upgrade or before a downgrade, set it to an older version so that newer servers keep writing text index parts in a format older servers can still read; the compatibility setting automatically adjusts it.Workflow [PR]
Sync PR [sync-upstream/pr/111803]
Version info
26.8.1.1761(included in26.8and later)26.7.6.12,26.6.4.18