Skip to content

Text index: keep text index token positions continuous within a row - #121300

Open
ahmadov wants to merge 13 commits into
masterfrom
ahmadov/fix-array-column-positions
Open

ahmadov wants to merge 13 commits into
masterfrom
ahmadov/fix-array-column-positions

Conversation

@ahmadov

@ahmadov ahmadov commented Sep 21, 2026 •

Copy link
Copy Markdown
Member

Previously, MergeTreeIndexTextGranuleBuilder::addDocument restarted the token position at 0 on every call. Therefore when an index is built on an Array(String) column, each element started its own position sequence.

The counter now lives in the granule builder and is reset in incrementCurrentRow, so the tokens of a row are numbered continuously across all of its array elements.

Changelog category (leave one):

  • Backward Incompatible Change

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

hasPhrase on an Array input matches a phrase only within a single element.


Workflow [PR]
Sync PR [sync-upstream/pr/121300]

Previously, `MergeTreeIndexTextGranuleBuilder::addDocument` restarted
the token position at 0 on every call. Therefore when an index is built
on a `Array(String)` column, each element started its own position sequence.

The counter now lives in the granule builder and is reset in `incrementCurrentRow`,
so the tokens of a row are numbered continuously across all of its array elements.
@ahmadov ahmadov added the comp-text-index Full-text search: inverted/text index in MergeTree (tokenizers, posting lists, GIN-style index bu... label Sep 21, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [e0edb93]

Summary: ❌

job_name test_name status info comment
Stateless tests (arm_binary, s3 storage, DBReplicated, parallel, 1/2) FAIL
03707_autopr_unsupported_cases FAIL cidb

AI Review

Summary

The PR makes text-index token positions continuous within a row and confines hasPhrase matches to one array element for tokenizers other than array, including postprocessor rewrites. At head e0edb93bc8edf13f9ab37900d9b24d9426b83037, the previously reported compatibility break remains. There are no new inline findings; the author-resolved discussion remains untouched.

PR Metadata

The Backward Incompatible Change category is correct. The required changelog entry identifies the new behavior but omits the previous behavior, the array tokenizer exception, and migration guidance. Suggested replacement:

With tokenizers other than array, hasPhrase on an Array input now requires the whole phrase to occur within one element; previously, tokens from all elements formed one sequence. The array tokenizer continues matching across consecutive elements of already tokenized arrays. For cross-element matching over arrays of text, explicitly tokenize each element, flatten the token arrays, and search the resulting token sequence with the array tokenizer.

Findings

❌ Blockers

  • src/Functions/hasPhrase.cpp:203 and optimizeDirectReadFromTextIndex.cpp:935: Released query semantics cannot be restored through compatibility. [dismissed by author -- https://github.com/Text index: keep text index token positions continuous within a row #121300#discussion_r4599726309] The author intentionally rejects cross-element matches, but this still changes existing query results even when older compatibility is requested. The released implementation preserves the matcher across elements; the PR binary returns 0 for SELECT hasPhrase(['a b', 'c'], 'b c') SETTINGS compatibility = '26.10', including without any text index. Both the matcher reset and the postprocessor rewrite enforce the new behavior unconditionally. Switching to the array tokenizer does not restore splitting within each text element: searching ['a b', 'c'] for ['b', 'c'] with that tokenizer also returns 0. Gate both paths with a setting and compatibility history, and add regression coverage for the older compatibility mode.

💡 Nits

  • PR description: expand the changelog entry using the replacement above so upgrading users can distinguish arrays of text from already tokenized arrays and adapt affected queries.
Final Verdict

Status: ❌ Block

Provide a compatibility setting and history for both matching paths, cover the older compatibility mode in a focused regression test, and clarify the changelog migration guidance. The dismissed finding is retained only in this summary; no duplicate inline comment or thread reopening is needed.

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Sep 21, 2026
@ahmadov ahmadov changed the title Text index: peep text index token positions continuous within a row Text index: keep text index token positions continuous within a row Sep 21, 2026
@alexey-milovidov alexey-milovidov mentioned this pull request Sep 21, 2026
1 task done
@ahmadov
ahmadov requested a review from rschu1ze September 22, 2026 12:11
@clickhouse-gh

clickhouse-gh Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing e0edb93bc with master 809ae9786 (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

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Object file sizes

8 object files changed (+23.07 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Storages/MergeTree/MergeTreeIndexTextPostprocessor.cpp.o 135.53 KiB 155.59 KiB +20.06 KiB (+14.80%)

716 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

32 translation units recompiled, 231 s compile time in total, 32 of them have a recent master baseline.

Job report

@clickhouse-gh clickhouse-gh Bot added pr-improvement Pull request with some product improvements and removed pr-not-for-changelog This PR should not be mentioned in the changelog labels Oct 13, 2026
Comment thread src/Functions/hasPhrase.cpp Resolved
@ahmadov
ahmadov requested review from CurtizJ and Ergus October 14, 2026 13:59
@alexey-milovidov alexey-milovidov removed the hold Skip for auto-updating. label Oct 24, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Dear @CurtizJ, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself.

@rschu1ze
rschu1ze removed their request for review November 6, 2026 18:53
@ahmadov
ahmadov added this pull request to stack #131997 November 16, 2026 12:58
Comment thread src/Functions/hasPhrase.cpp Resolved
@clickhouse-gh clickhouse-gh Bot added pr-backward-incompatible Pull request with backwards incompatible changes and removed pr-improvement Pull request with some product improvements labels Nov 17, 2026
@CurtizJ CurtizJ self-assigned this Nov 24, 2026

This branch has not been deployed

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

Labels

comp-text-index Full-text search: inverted/text index in MergeTree (tokenizers, posting lists, GIN-style index bu... pr-backward-incompatible Pull request with backwards incompatible changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants