Skip to content

Text index: add cursor support for the phrase search - #118885

Merged
CurtizJ merged 46 commits into
masterfrom
ahmadov/positions-cursor
Oct 22, 2026
Merged

CurtizJ merged 46 commits into
masterfrom
ahmadov/positions-cursor

Conversation

@ahmadov

@ahmadov ahmadov commented Sep 8, 2026 •

Copy link
Copy Markdown
Member

Previously, phrase search used to find candidate rows by reading every token's whole posting list and intersecting them as bitmaps. For a phrase with one rare token, that meant decoding the frequent tokens' whole lists to find a few rows.

This PR adds a leapfrog over posting list cursors: the rarest token drives the walk, the others seek to it and skip whole blocks, and each candidate comes out with its rank in every list, which addresses its positions directly.

No layout change. In follow-up PRs, I'll try to improve by changing the layout (e.g. suggestion).

Changelog category (leave one):

  • Performance Improvement

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

Improve phrase search performance when one of the phrase's terms is rare, because it skips the parts of the frequent terms' posting lists that cannot match.


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

Version info

  • Merged into: 26.11.1.498-master (included in 26.11 and later)

@clickhouse-gh

clickhouse-gh Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [e655413]

Summary: ✅


AI Review

Summary

The PR streams hasPhrase candidates through posting-list cursors, derives positional ranks without materializing complete posting lists, and caches results in aligned row chunks. Review of PR head e6554136ea09538e3e26b0d29308159e1414d304 found no unresolved actionable findings. Earlier findings are addressed by the current implementation and regression coverage.

Missing context / blind spots
  • ⚠️ Local execution was unavailable because this checkout has no ClickHouse binary or build directory. The Praktika report reports successful checks, but its available records expose no detailed phrase-test results or performance artifacts. The focused correctness and performance tests were reviewed; their runtime results and speedup were not independently reproduced.
Final Verdict

Status: ✅ Approve. No new inline findings or thread changes are needed.

@clickhouse-gh clickhouse-gh Bot added the pr-performance Pull request with some performance improvements label Sep 8, 2026
@ahmadov ahmadov added the comp-text-index Full-text search: inverted/text index in MergeTree (tokenizers, posting lists, GIN-style index bu... label Sep 8, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing e6554136e with master 504275109 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 8982f784f; 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 (+76.27 KiB total), 1 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Storages/MergeTree/TextIndexPostingsRankCursor.cpp.o new 50.59 KiB +50.59 KiB
src/CMakeFiles/dbms.dir/Storages/MergeTree/MergeTreeReaderTextIndex.cpp.o 470.57 KiB 494.89 KiB +24.32 KiB (+5.17%)

719 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

30 translation units recompiled, 278 s compile time in total, 29 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 -17.8 s (-6%) in total before that adjustment.

Translation units without a recent master baseline:

  • src/Storages/MergeTree/TextIndexPostingsRankCursor.cpp: 5.4 s
Symbol sizes
Binary Symbol Master PR Δ
programs/clickhouse-keeper ProfileEvents::global_counters_storage 13.38 MiB 13.44 MiB +64.00 KiB (+0.47%)
programs/clickhouse ProfileEvents::global_counters_storage 13.38 MiB 13.44 MiB +64.00 KiB (+0.47%)

Job report

@ahmadov
ahmadov force-pushed the ahmadov/positions-cursor branch from 81a6034 to f44bb9f Compare September 22, 2026 16:15
@ahmadov ahmadov added the hold Skip for auto-updating. label Sep 23, 2026
@ahmadov
ahmadov force-pushed the ahmadov/positions-cursor branch from ad6aeb0 to a91fdc8 Compare September 23, 2026 16:18
@ahmadov
ahmadov force-pushed the ahmadov/positions-cursor branch from 59a9282 to 59aa411 Compare October 5, 2026 14:45

@CurtizJ CurtizJ left a comment

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.

Looks good in general

@ahmadov
ahmadov requested a review from CurtizJ October 16, 2026 16:34

@CurtizJ CurtizJ left a comment

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.

Looks great

Comment on lines +175 to +176
M(TextIndexPhraseSearches, "Number of phrase searches executed over a text index, one per reader of a granule. Readers served entirely from the cache are not counted.", ValueType::Number) \
M(TextIndexPhraseCursorSearches, "Number of phrase searches that found their candidate rows with posting list cursors instead of intersecting bitmaps.", ValueType::Number) \

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.

It looks like 2 profile events are redundant now. We can keep only TextIndexPhraseSearches.

@CurtizJ

CurtizJ commented Oct 21, 2026

Copy link
Copy Markdown
Member

Perf tests:
Screenshot 2026-10-22 at 01 26 23

@CurtizJ
CurtizJ added this pull request to the merge queue Oct 21, 2026
Merged via the queue into master with commit a044274 Oct 22, 2026
179 checks passed
@CurtizJ
CurtizJ deleted the ahmadov/positions-cursor branch October 22, 2026 02:06
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 22, 2026
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Oct 27, 2026
…-intersect-per-container

Master builds `range_posting` lazily in `buildPostingsForMark` and skips
columns answered by the analyzer's folded postings (ClickHouse#122896); the
per-container path only runs when postings must still be read, so it is
disjoint from the folded one. `setIndexGranule` keeps only the reset of
`intersection_steps`: master moved the per-granule phrase results into
`phrase_streams` (ClickHouse#118885) and dropped `blocked_positions_scratch`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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... hold Skip for auto-updating. pr-performance Pull request with some performance improvements pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants