Skip to content

Restore attach compatibility for renamed text-index positions setting - #110787

Closed
groeneai wants to merge 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/text-index-positions-attach-compat
Closed

groeneai wants to merge 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/text-index-positions-attach-compat

Conversation

@groeneai

Copy link
Copy Markdown
Collaborator

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):

Fixed attaching a MergeTree table with a text index created by an older server. The setting allow_experimental_text_index_positions and the index argument positions were renamed to allow_experimental_text_index_phrase_search and support_phrase_search without a compatibility alias, so a newer server failed to attach such a table with Unknown setting 'allow_experimental_text_index_positions'. The old names are now accepted when reading existing metadata.

Description

Upgrade check failure reported on unrelated PRs (#110615, #108950, #100394):

Code: 115. DB::Exception: Unknown setting 'allow_experimental_text_index_positions':
for storage MergeTree: Cannot attach table `test_3`.`tab` ...
ATTACH TABLE test_3.tab (... INDEX idx (message) TYPE text(tokenizer = splitByNonAlpha, positions = 1) ...)
ENGINE = MergeTree ORDER BY (id) SETTINGS allow_experimental_text_index_positions = 1 ... (UNKNOWN_SETTING)

Root cause: #109900 renamed, without a backward-compatibility alias:

  • MergeTree setting allow_experimental_text_index_positions -> allow_experimental_text_index_phrase_search
  • text-index argument positions -> support_phrase_search

An older server writes metadata referencing the old names; the new server then cannot attach the table.

Fix (both directions blessed by @alexey-milovidov in the #110615 comment):

  1. MAKE_OBSOLETE_MERGE_TREE_SETTING(M, Bool, allow_experimental_text_index_positions, false) so the removed setting is tolerated on ATTACH.
  2. Accept the legacy positions text-index argument as an alias of support_phrase_search when reading metadata. Specifying both at once is rejected.
  3. The experimental gate is skipped on ATTACH so an existing table loads even though the new experimental setting is not enabled in its metadata; on CREATE the gate still applies.

Regression test 02346_text_index_positions_attach_compat creates a table with support_phrase_search, rewrites its metadata to the pre-#109900 names, and verifies it attaches.

ClickHouse#109900 renamed the MergeTree setting allow_experimental_text_index_positions
to allow_experimental_text_index_phrase_search and the text index argument
positions to support_phrase_search, without a compatibility alias. A table
written by an older server references the old names in its metadata, so a newer
server fails to attach it with UNKNOWN_SETTING (surfaced by the Upgrade check).

Make the old MergeTree setting obsolete (tolerated on ATTACH) and accept the
legacy positions text-index argument as an alias of support_phrase_search. The
experimental gate is skipped on ATTACH so existing tables load even though the
new experimental setting is not enabled in their metadata.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. CREATE a table with support_phrase_search=1, rewrite its metadata .sql to the pre-#109900 names (positions=1, allow_experimental_text_index_positions=1), ATTACH. Fails on master with Unknown setting 'allow_experimental_text_index_positions' (UNKNOWN_SETTING).
b Root cause explained? #109900 renamed the MergeTree setting allow_experimental_text_index_positions -> allow_experimental_text_index_phrase_search and the index arg positions -> support_phrase_search with no alias. Old-server metadata references the removed names, so the new server rejects both the setting and the index argument on ATTACH.
c Fix matches root cause? Yes. MAKE_OBSOLETE_MERGE_TREE_SETTING for the old setting + accept positions as an alias of support_phrase_search, exactly the two removed names.
d Test intent preserved / new tests added? New test 02346_text_index_positions_attach_compat. No existing test weakened.
e Demonstrated both directions? Without fix: ATTACH throws UNKNOWN_SETTING (and, once the setting is tolerated, "Unexpected text index arguments: positions"). With fix: ATTACH succeeds, SELECT count() returns 1, index preserved.
f Fix general, not a narrow patch? Both renamed names are handled (setting + argument). The alias applies on both CREATE and ATTACH; specifying positions and support_phrase_search together is rejected.
g Generalizes across inputs? Alias covers positions = 0 and positions = 1; value range check (> 1) unchanged and applies to both names.
h Backward compatible? Yes, this restores backward compatibility. Old setting is obsolete (tolerated, does nothing active); legacy index arg is read. No new backward-incompatible behavior.
i Invariants/contracts preserved? The experimental gate is skipped only on ATTACH (loading existing metadata); CREATE still requires allow_experimental_text_index_phrase_search=1. No change to on-disk index format.

Session id: cron:clickhouse-worker-slot-2:20260717-070800

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @rschu1ze @CurtizJ — could you review? Small backward-compat fix restoring ATTACH of text-index tables written before the #109900 rename (obsolete setting alias + legacy positions index argument).

@rschu1ze rschu1ze self-assigned this Jul 17, 2026
@nikitamikhaylov nikitamikhaylov added the can be tested Allows running workflows for external contributors label Jul 17, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [35631c3]

Summary: ❌

job_name test_name status info comment
Fast test FAIL
02995_new_settings_history FAIL cidb
Finish Workflow FAIL
python3 ./ci/jobs/scripts/workflow_hooks/new_tests_check.py FAIL
Code Review DROPPED
Fast test (arm_darwin) DROPPED
Build (amd_debug) DROPPED
Build (amd_asan_ubsan) DROPPED
Build (amd_tsan) DROPPED
Build (amd_msan) DROPPED
Build (amd_binary) DROPPED
Build (arm_debug) DROPPED

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jul 17, 2026
@rschu1ze

rschu1ze commented Jul 17, 2026 •

Copy link
Copy Markdown
Member

This is overkill. Setting allow_experimental_text_index_positions and text index argument positions wereo experimental, i.e. can change anytime. Production usage is not expected.

@rschu1ze rschu1ze closed this Jul 17, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

Understood, keeping it closed. Since the setting and the positions argument are experimental with no expected production usage, no ATTACH-compat alias is warranted.

That leaves the Upgrade check (amd_release) UNKNOWN_SETTING failure that started this (an older binary persists a table with allow_experimental_text_index_positions, the newer server rejects it on ATTACH; it hit #110615 plus two other unrelated PRs alexey listed there). If experimental MergeTree settings intentionally get no compat, the upgrade test should stop persisting the old experimental setting across the version boundary, or tolerate UNKNOWN_SETTING for experimental settings during the upgrade ATTACH. Leaving that call to you and the upgrade-check owners.

@groeneai

Copy link
Copy Markdown
Collaborator Author

@rschu1ze, one follow-up with measurements. 26.6 is a stable line (ten v26.6.*-stable releases), and a 26.6 table that used this argument does not load on newer versions. I tested official builds 26.6.8.7, 26.8.3.105-lts and 26.11.1.307 with clickhouse local on plain MergeTree:

written by read by result
26.6, positions = 1 26.8, 26.11 does not attach: Code: 115 Unknown setting 'allow_experimental_text_index_positions'
same, metadata renamed to the new names 26.8 works fully: hasPhrase, hasToken, OPTIMIZE FINAL
same, metadata renamed 26.11 attaches, but index reads and merges fail (next row)
26.8, support_phrase_search = 1 26.11 attaches; hasToken, hasPhrase and OPTIMIZE fail with Code: 246 Unknown positions codec 40 in text index header (with a one-block dictionary: Code: 33 CANNOT_READ_ALL_DATA and Corrupt text index positions). The column data is intact, and DROP INDEX + ADD INDEX + MATERIALIZE INDEX recovers.

The last row is unrelated to the rename. #111550 added positions_codec to the header but kept serialization version v2_with_positions, so 26.9+ reads the old sparse-index token count as the codec. From #121976 I understand the old layout was dropped on purpose. I mention it only because such a table attaches and then fails its merges, instead of being rejected up front.

So restoring the old names would fully fix the 26.6 to 26.7/26.8 upgrade (26.7 has the same on-disk layout as 26.8). That means a setting alias, as allow_experimental_block_number_column has for enable_block_number_column, plus positions accepted on ATTACH only. On 26.9+ the table would attach, but its index would still have to be re-created.

Do you want that change on master (backport labels at your discretion), or should it stay as is? A yes or no is enough; on a no I will leave it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants