Skip to content

Optimize full text search with multiple tokens and predicates - #98226

Merged
CurtizJ merged 45 commits into
ClickHouse:masterfrom
CurtizJ:text-index-tokens-order
Jun 2, 2026
Merged

CurtizJ merged 45 commits into
ClickHouse:masterfrom
CurtizJ:text-index-tokens-order

Conversation

@CurtizJ

@CurtizJ CurtizJ commented Feb 27, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Performance Improvement

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

Improved performance of text index analysis in multi-token searches by optimizing handling of rare tokens.

Version info

  • Merged into: 26.6.1.324

@clickhouse-gh

clickhouse-gh Bot commented Feb 27, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [d7fc0ab]

Summary: ❌

job_name test_name status info comment
Stateless tests (arm_asan_ubsan, targeted) FAIL
Server died FAIL cidb IGNORED

AI Review

Summary

This PR refactors text-index granule analysis through TextIndexAnalyzer, orders dictionary token reads by observed cardinality, and adds regression coverage for LIKE fallback, large postings, partial-mark reads, and token read ordering. I did not find a new correctness issue in the current code, but the Performance Improvement evidence gate is still open at the current head.

Missing context / blind spots
  • ⚠️ The current CI performance comparison shards for d7fc0abe6e2395143be3e4da92b66b4f5513a28a are still PENDING, so there is no completed before/after data yet for tests/performance/text_index.xml or the optimized multi-token path.
Findings
⚠️ Majors
  • [src/Storages/MergeTree/MergeTreeIndexText.cpp:434] [dismissed by author -- https://github.com/Optimize full text search with multiple tokens and predicates #98226#discussion_r3264799192] The PR is categorized as Performance Improvement, but the current head still has no completed performance comparison or targeted benchmark showing that cardinality-ordered token reads improve multi-token text-index queries without regressing other text-index workloads. The added 04266_text_index_tokens_cardinality_order.sh proves read order, not runtime benefit. Please provide the completed performance comparison for the current SHA or another focused before/after measurement.
Final Verdict

Status: ⚠️ Request changes

Minimum required action: provide completed performance evidence for current d7fc0abe6e2395143be3e4da92b66b4f5513a28a, or recategorize if this should not claim a measured performance improvement.

@clickhouse-gh clickhouse-gh Bot added the pr-performance Pull request with some performance improvements label Feb 27, 2026
# Conflicts:
#	src/Storages/MergeTree/MergeTreeIndexText.cpp
#	src/Storages/MergeTree/MergeTreeIndexText.h
#	src/Storages/MergeTree/MergeTreeReaderTextIndex.cpp
- Fix iterator invalidation in `processTokenOperation`: copy the
  `queries_by_token` set before iterating, since erasing a failed query
  may mutate the same set when `query_token == token`.

- Implement `memoryUsageBytes` for `TextIndexAnalyzer` and use it in
  the granule to restore proper memory accounting for cache eviction.

- Validate per-column fallback expression existence in
  `analyzeTokensCardinality` to avoid UB in release builds when
  `evaluateMissingDefaults` returned null for a pattern virtual column.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@CurtizJ
CurtizJ marked this pull request as ready for review May 25, 2026 22:08
@CurtizJ CurtizJ changed the title Read tokens from text index in order of their cardinality [2] Optimize full text search with multiple tokens and predicates May 26, 2026
@CurtizJ
CurtizJ requested a review from ahmadov May 28, 2026 09:59

@ahmadov ahmadov 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.

in general LGTM 👍

Strengthen `04092_text_index_like_large_postings` and
`04093_text_index_like_overflow_fallback` so they force the text-index
reader path and assert a profile-event signal, instead of comparing two
queries that could both silently fall back to a full scan.

- 04092: force the direct read (`use_skip_indexes`,
  `use_skip_indexes_on_data_read`, `query_plan_direct_read_from_text_index`)
  and assert `TextIndexReadPostings` > 0 for the matching query, proving the
  multi-block posting list is actually read. The regression was that
  large-posting reading streams were never initialized, so the index
  returned no rows.
- 04093: force the path, set `text_index_like_min_pattern_length` = 1 (the
  short `%pa%` / `%p%` needles were otherwise rejected before the dictionary
  scan, so the test exercised nothing), and assert
  `TextIndexDiscardPatternScan` > 0 for the overflowing queries. `NOT LIKE`
  is relabeled honestly because it never uses the text index.

Addresses review comments on PR ClickHouse#98226:
ClickHouse#98226 (comment)
ClickHouse#98226 (comment)

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.40% 84.40% +0.00%
Functions 92.40% 92.40% +0.00%
Branches 77.00% 76.90% -0.10%

Changed lines: Changed C/C++ lines covered by tests: 646/708 (91.24%) | Lost baseline coverage (was covered on master, now uncovered in this PR): 26 line(s) · Uncovered code

Full report · Diff report

@CurtizJ
CurtizJ added this pull request to the merge queue Jun 2, 2026
Merged via the queue into ClickHouse:master with commit a242690 Jun 2, 2026
164 of 167 checks passed
@CurtizJ
CurtizJ deleted the text-index-tokens-order branch June 2, 2026 12:04
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

4 participants