Skip to content

Text index: store positions for a better phrase search - #103172

Merged
ahmadov merged 53 commits into
masterfrom
ahmadov/text-index-positions
Jun 24, 2026
Merged

ahmadov merged 53 commits into
masterfrom
ahmadov/text-index-positions

Conversation

@ahmadov

@ahmadov ahmadov commented Apr 20, 2026 •

Copy link
Copy Markdown
Member

Implements #101473 for storing positional information for phrase search.

This positional data is stored as 96-bit "[32][32][32]" layout. This allows us to store larger token positions.

The following points would be implemented in follow-up PRs:

Changelog category (leave one):

  • New Feature

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

Add new positions argument support to text indexes to store token positions and enable exact direct reads for hasPhrase. The allow_experimental_text_index_positions needs to be enabled to store positional information.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Merged into: 26.7.1.42
  • Backported to: 26.6.1.1190

@clickhouse-gh

clickhouse-gh Bot commented Apr 20, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [874bf65]

Summary: ✅


AI Review

Summary

This PR adds experimental positional storage to text indexes so hasPhrase can be answered exactly from the text index, including .pos serialization, merge support, reader-side phrase intersection, docs, and stateless coverage. Most earlier review findings are addressed in the current tree, but one resolved-by-author correctness risk is still present, and the PR metadata should mark the feature as experimental.

PR Metadata
  • The Changelog category should be Experimental Feature, not New Feature, because positions = 1 is gated by allow_experimental_text_index_positions and the docs explicitly say the on-disk layout is not stable yet.

  • The changelog entry is required and mostly user-readable. Suggested replacement:

    You can now enable experimental token-position storage for text indexes with positions = 1, allowing direct text-index reads to answer hasPhrase exactly. Enable allow_experimental_text_index_positions before creating such indexes; the on-disk layout is experimental and may change.

Findings

⚠️ Majors

  • [src/Storages/MergeTree/MergeTreeIndexText.cpp:1551] [dismissed by author -- https://github.com/Text index: store positions for a better phrase search #103172#discussion_r3463116755] hasPhrase position data must preserve each token occurrence's position within a row, but token_position is still a UInt32 and increments without a bound check. A single document with more than UInt32::max() tokens wraps back to zero, writes later occurrences into low-position buckets, and can make exact direct reads return wrong phrase matches from corrupted .pos data. The row-id guard only bounds current_row; it does not bound per-document token positions.
    Suggested fix: keep the counter in a wider type and throw SUPPORT_IS_DISABLED before calling positions_builder.add once the position exceeds UInt32::max(), or enforce that limit inside RoaringishEntry::make.
Final Verdict

Status: ⚠️ Request changes

Minimum required actions: change the changelog category to Experimental Feature and add an explicit per-document token-position overflow guard before positional data is serialized.

@clickhouse-gh clickhouse-gh Bot added the pr-feature Pull request with new product feature label Apr 20, 2026
@ahmadov
ahmadov force-pushed the ahmadov/text-index-positions branch from 155ef11 to e1fe380 Compare April 21, 2026 07:53
@ahmadov
ahmadov force-pushed the ahmadov/text-index-positions branch from 9f76ec6 to b097487 Compare April 21, 2026 09:46
@ahmadov
ahmadov force-pushed the ahmadov/text-index-positions branch from b097487 to a182078 Compare April 21, 2026 14:57
@ahmadov
ahmadov added this pull request to the merge queue Jun 24, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 24, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.50% 85.40% -0.10%
Functions 92.60% 92.60% +0.00%
Branches 77.60% 77.60% +0.00%

Changed lines: Changed C/C++ lines covered by tests: 578/644 (89.75%) | Lost baseline coverage (was covered on master, now uncovered in this PR): 1 line(s) · Uncovered code

Full report · Diff report

@ahmadov
ahmadov added this pull request to the merge queue Jun 24, 2026
Merged via the queue into master with commit 1a335a4 Jun 24, 2026
167 checks passed
@ahmadov
ahmadov deleted the ahmadov/text-index-positions branch June 24, 2026 19:06
@ahmadov ahmadov added the pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! label Jun 24, 2026
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 24, 2026
robot-ch-test-poll added a commit that referenced this pull request Jun 24, 2026
Cherry pick #103172 to 26.6: Text index: store positions for a better phrase search
robot-clickhouse added a commit that referenced this pull request Jun 24, 2026
@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 Jun 24, 2026
@robot-ch-test-poll robot-ch-test-poll added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Jun 24, 2026
@Ergus

Ergus commented Jun 24, 2026

Copy link
Copy Markdown
Member

This got in the queue just before the postprocessor (#98939) and now there are conflicts :(

@clickgapai

Copy link
Copy Markdown
Contributor

Hi @ahmadov — while reviewing this PR I found the following:

Could you review the test PR and add the can be tested label if it looks good?
Happy to discuss — close anything that's wrong or already addressed.

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-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! pr-feature Pull request with new product feature 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants