Skip to content

Added a setting text_index_version for better forward compatibility - #111803

Merged
CurtizJ merged 19 commits into
ClickHouse:masterfrom
CurtizJ:text-index-format-setting
Aug 20, 2026
Merged

CurtizJ merged 19 commits into
ClickHouse:masterfrom
CurtizJ:text-index-format-setting

Conversation

@CurtizJ

@CurtizJ CurtizJ commented Jul 24, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Improvement

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

Added a new MergeTree setting text_index_version that controls the on-disk format version of text indexes: v0_initial, v1_with_codec, or v2_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

  • Merged into: 26.8.1.1761 (included in 26.8 and later)
  • Backported to: 26.7.6.12, 26.6.4.18

CurtizJ and others added 4 commits June 23, 2026 17:34
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]>
@clickhouse-gh

clickhouse-gh Bot commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [d81ce3b]

Summary: ❌

job_name test_name status info comment
Docker keeper image ERROR IGNORED

AI Review

Summary

This PR introduces text_index_serialization_version so newer servers can prefer older on-disk text-index layouts during upgrades and downgrades, and extends the text-index header/reader for codec and position-aware formats. The overall direction is reasonable, but the current version-resolution logic still breaks the advertised rollback / mixed-version contract for codec-bearing legacy indexes, so I would not merge it yet.

PR Metadata
  • Changelog category: Improvement fits the change.
  • Changelog entry: required, but the current text still uses the old setting name text_index_version. Suggested replacement: Added the MergeTree setting \text_index_serialization_version` to choose which on-disk text-index format new parts prefer to write during upgrades and downgrades.`
Findings

❌ Blockers

  • [src/Storages/MergeTree/MergeTreeIndexText.cpp:2095-2102] The write path still treats any non-none posting_list_codec as requiring v1_with_codec, so compatibility = '26.5' no longer preserves 26.4-readable parts for codec-bearing indexes. That violates the PR's upgrade/downgrade contract: 26.4 already writes and reads v0_initial text indexes with posting_list_codec = 'bitpacking' (the integration test comments at tests/integration/test_text_index_upgrade/test.py:5-7 rely on exactly that layout), but a new server now clamps the same index to v1_with_codec and emits headers older replicas cannot parse. Suggested fix: keep v0_initial valid for the legacy bitpacking path, and only raise the minimum version for features the old layout truly cannot represent (for example positions).
Tests
  • ⚠️ Add a downgrade / rolling-upgrade test for posting_list_codec = 'bitpacking': start on 26.4, upgrade under compatibility = '26.5', write and merge new parts, then restart 26.4. The current downgrade coverage only exercises the posting_list_codec = 'none' path, so it does not protect the regression above.
Final Verdict
  • ⚠️ Request changes
  • Minimum required action: stop auto-promoting the legacy bitpacking codec path from v0_initial to v1_with_codec.
  • Minimum required action: add downgrade coverage for codec-bearing text indexes.

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.90% 86.90% +0.00%
Functions 91.90% 91.90% +0.00%
Branches 79.20% 79.20% +0.00%

Changed lines: Changed C/C++ lines covered: 173/175 (98.86%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Jul 24, 2026
@CurtizJ
CurtizJ marked this pull request as draft July 30, 2026 01:23
CurtizJ and others added 5 commits July 30, 2026 01:26
…-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]>
@CurtizJ
CurtizJ marked this pull request as ready for review August 19, 2026 10:06
CurtizJ and others added 2 commits August 19, 2026 10:23
…-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]>
CurtizJ and others added 2 commits August 19, 2026 12:57
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]>
@clickhouse-gh

clickhouse-gh Bot commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing d81ce3b40 with master 90e6c433c (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes
Binary Master PR Δ
programs/clickhouse-stripped 703.88 MiB 700.85 MiB -3.02 MiB (-0.43%)

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 sizes

16 object files changed (+43.11 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Core/SettingsEnums.cpp.o 2.04 MiB 2.07 MiB +24.75 KiB (+1.18%)

737 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

1867 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.
The matched translation units cost -592.4 s (-5%) in total before that adjustment.

Job report

…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]>
@CurtizJ
CurtizJ requested a review from rschu1ze August 19, 2026 21:22
@rschu1ze rschu1ze self-assigned this Aug 19, 2026
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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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."},

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm 99% sure that v2 became the default in 26.6 already.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I have to add an entry to the 26.8 version to pass CI.

CurtizJ and others added 2 commits August 19, 2026 22:16
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]>
@CurtizJ
CurtizJ added this pull request to the merge queue Aug 20, 2026
Merged via the queue into ClickHouse:master with commit bddae8d Aug 20, 2026
178 of 180 checks passed
@CurtizJ
CurtizJ deleted the text-index-format-setting branch August 20, 2026 12:24
@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 Aug 20, 2026
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 20, 2026
robot-ch-test-poll3 added a commit that referenced this pull request Aug 21, 2026
Cherry pick #111803 to 26.6: Added a setting `text_index_version` for better forward compatibility
robot-clickhouse added a commit that referenced this pull request Aug 21, 2026
robot-ch-test-poll3 added a commit that referenced this pull request Aug 21, 2026
Cherry pick #111803 to 26.7: Added a setting `text_index_version` for better forward compatibility
robot-clickhouse added a commit that referenced this pull request Aug 21, 2026
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Aug 21, 2026
CurtizJ added a commit that referenced this pull request Aug 24, 2026
Backport #111803 to 26.7: Added a setting `text_index_version` for better forward compatibility
CurtizJ added a commit that referenced this pull request Aug 24, 2026
CurtizJ added a commit that referenced this pull request Aug 24, 2026
Backport #111803 to 26.6: Added a setting `text_index_version` for better forward compatibility
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Sep 4, 2026
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.
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-improvement Pull request with some product improvements 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 v26.6-must-backport v26.7-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants