Repository navigation
Cache missing text index tokens - #112742
Conversation
Repeated searches for a token that is absent from many text-index parts otherwise read each part dictionary again on every query. Store that result in the existing `TextIndexTokensCache` so negative entries share its capacity, eviction policy, and clear operation instead of introducing a parallel cache. Gate negative entries behind the independently controlled `use_text_index_negative_tokens_cache` setting, disabled by default. When the setting is disabled, ignore an already cached negative entry and evaluate the dictionary, preserving query-level setting semantics. Separate profile events expose negative cache population and reuse. A 10-million-row ClickBench `SearchPhrase` workload with 1,280 active parts measured about 20% lower server query time and CPU after warm-up; dictionary reads fell from 256,000 to zero across 200 measured queries. Keep this evidence in the pull request rather than adding a recurring performance test for the narrow opt-in optimization. Tests: `ninja -C build clickhouse`; `04658_text_index_negative_tokens_cache`; `02346_text_index_dictionary_cache`; `03999_stateless_settings_history`.
|
Workflow [PR], commit [ec1e54b] Summary: ✅
AI ReviewSummaryThis PR adds caching for text-index tokens that are absent from a part and enables that path by default. The performance motivation and changelog metadata are fine, but the current implementation still breaks the existing cache-disable and cache-size contracts for the token cache, so it is not ready to merge as-is. Findings❌ Blockers
Final Verdict❌ Changes requested. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 57/57 (100.00%) · Uncovered code |
Enable the cache by default and isolate the profile-event test from parallel replicas. Related: ClickHouse#112742
| private: | ||
| static const MappedPtr & notFoundEntry() | ||
| { | ||
| static const auto entry = std::make_shared<TokenPostingsInfo>(); |
There was a problem hiding this comment.
This sentinel makes every negative-cache cell weigh 0 bytes because TextIndexTokensWeightFunction delegates to TokenPostingsInfo::bytesAllocated(). CacheBase/SLRUCachePolicy only evict when total weight or max_count exceeds the limit, so these entries survive even when text_index_tokens_cache_size = 0 is supposed to disable the cache, and they also bypass the per-query local_cache_max_size fallback created in MergeTreeIndexConditionText.cpp when use_text_index_tokens_cache = 0 (max_count = 0 there).
A miss-heavy query can therefore keep adding (part, token) negative cells without honoring the configured cache-size bound. Could we give negative entries a non-zero weight or skip storing them when the backing token cache is effectively disabled?
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 57/57 (100.00%) · Uncovered code |
|
📊 Cloud Performance Report ✅ AI verdict: This PR only adds a negative-tokens cache for full-text (text) indexes, gated behind a new default-on setting, and touches only text-index code paths (MergeTreeIndexText, TextIndexCache) plus profile events and docs. None of the flagged ClickBench queries use text indexes or hasAnyTokens, so their deltas cannot be attributed to this change. Q9 and Q17 both show an identical +12.4% offset, which points to a systematic artifact consistent with the small source sample count and co-located runs rather than a real per-query effect. All three flags are downgraded to not_sure. clickbenchFlagged queries (3 of 43)
Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. tpch_adapted_1_official🟢 No significant changes Debug info
|
Missing tokens were looked up in every part on every query. This caches those misses in the existing token cache, behind
use_text_index_negative_tokens_cache(on by default).ClickBench benchmark: 10 million rows, 1,280 parts, 200 queries per mode.
Tested with a full build and the text-index cache stateless tests.
Changelog category (leave one):
Changelog entry:
Add optional caching for tokens missing from text indexes.