Skip to content

Cherry pick #111803 to 26.7: Added a setting text_index_version for better forward compatibility - #115613

Merged
robot-ch-test-poll3 merged 21 commits into
backport/26.7/111803from
cherrypick/26.7/111803
Aug 21, 2026
Merged

robot-ch-test-poll3 merged 21 commits into
backport/26.7/111803from
cherrypick/26.7/111803

Conversation

@robot-ch-test-poll

Copy link
Copy Markdown
Contributor

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-pick locally.
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:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

CurtizJ and others added 20 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]>
…-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
@robot-ch-test-poll robot-ch-test-poll added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request labels Aug 20, 2026
# Conflicts:
#	src/Core/SettingsChangesHistory.cpp
#	src/Storages/MergeTree/MergeTreeIndexText.cpp
#	tests/integration/test_text_index_upgrade/test.py
@robot-ch-test-poll3
robot-ch-test-poll3 merged commit 0463801 into backport/26.7/111803 Aug 21, 2026
1 check passed
@robot-ch-test-poll3
robot-ch-test-poll3 deleted the cherrypick/26.7/111803 branch August 21, 2026 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants