Repository navigation
Conversation
The event is documented as the number of times a posting list embedded in the text index dictionary has been used, but it was incremented inside TextIndexSerialization::deserializeTokenInfo, a byte decoder that takes a ReadBuffer and has no notion of a query. The decoded TokenPostingsInfo, including its embedded_postings member, is stored in the server-global TextIndexTokensCache, so a query that hits the cache uses those postings through TextIndexAnalyzer::addTokenInfo without deserializing anything and therefore without incrementing the event. Conversely a background merge decodes every token of a dictionary block through the same function, which incremented the event with no query using anything. The event therefore under-counted real uses and over-counted non-uses. Move the increment to TextIndexAnalyzer::addTokenInfo, where the embedded postings enter a query, guarded by the pre-existing isTokenNeeded predicate so a posting list that no live query can still consume is not counted. The non-embedded readPostingsBlock route cannot reach it by construction, because the increment sits inside the embedded_postings branch. This restores the placement the event had until bd477d0 ("slightly better", part of ClickHouse#98226, a pull request about token ordering) moved it into the decoder. The class TextIndexAnalyzer lived in MergeTreeIndexText.cpp at that time. The name and description of the event are unchanged, so the code is being made to match its existing documented meaning. The new test asserts the event is cache-independent: a cold arm and a warm arm must both report it, and the warm arm must also report a tokens cache hit and zero cache misses, so it cannot pass by silently missing the cache and decoding again. It fails without this change and passes with it.
Review round 1 on the shipped test. The C++ change is unaltered except for a comment reword; no behavior changes here. The test now has a third arm covering the `isTokenNeeded` guard. Two tokens whose postings are embedded sit in disjoint id ranges, so an all-tokens search fails after the first token and the second token's posting list reaches zero query builders. The guard makes that read exactly 1 use; deleting the guard makes it read 2, so the arm reddens and the guard is no longer covered by reasoning alone. The arm also asserts both tokens really are embedded, since a fixture drifting above the embedding cardinality limit would otherwise let it pass with nothing embedded at all. Two environment pins. The tags now include `no-parallel-replicas`: the assertions read ProfileEvents from the initiator's query_log row, and events raised on a remote replica are never merged into it, so the parallel-replicas job would read numbers that no longer measure the counter placement. And `use_text_index_tokens_cache` is set explicitly, because a `compatibility` setting below 26.7 restores it to false, which swaps the server-global tokens cache for a per-query local one and removes the cross-query hit the warm arm asserts. Co-Authored-By: Claude Fable 5 <[email protected]>
The dead-query arm asserts an exact TextIndexUsedEmbeddedPostings count of 1, which holds only while tab_dead has a single active part: the counter is raised once per part, so a two-part state reads 2 -- the same value an implementation without the isTokenNeeded guard produces. In that state the cell stops discriminating and the arm would pass for the wrong reason. Two pins make the single-part premise explicit instead of implicit: optimize_throw_if_noop on the OPTIMIZE ... FINAL turns a refused merge into a loud error. StorageMergeTree::optimize only throws when that setting is set, and it defaults to false, so a refusal (for example when the background-memory soft limit rejects the merge) otherwise succeeds silently and leaves two parts. max_insert_threads = 1 pins the part count across the whole file. The tokens-cache key embeds the part's full path, so a change to the active part set between the cold and the warm query would probe a different key and turn the warm arm's asserted cache hit into a miss. The test runner randomizes max_insert_threads, and a query-level SET overrides the injected draw. Measured: both tables single-part; the amended test passes 50/50 under randomization; deleting the isTokenNeeded conjunct still reddens the arm with exactly one changed line, dead 1 -> dead 2.
Internal second-model reviewBefore opening this pull request I ran an independent code review plus a second-model review of the Round 1
Round 2
Round 3 — no findings. Two observations, neither requiring a change. First, the round-2 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-47:20260801-134502 |
|
cc @ahmadov @george-larionov, could you review this? The |
|
Workflow [PR], commit [ca6811a] Summary: ❌
AI ReviewSummaryThis PR moves Final Verdict✅ No findings. |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 7/7 (100.00%) · Uncovered code |
CI finish ledger — ca6811aEvery failure below has an owner: a fixing PR (ours or external), or a full-effort fix task 174 check-runs, 0 incomplete (paginated check-runs API),
Reports:
Not PR-caused: this PR touches only the Session id: cron:our-pr-ci-monitor:20260802-000000 |
|
Filed the tracking issue for the CI flake this fixes: #113751. It carries the mechanism, a As stated there, this PR removes the only measured mechanism for that flake's |
Pick your poison. Incrementing |
Related: #103526
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixes the
TextIndexUsedEmbeddedPostingsprofile event, which reported wrong values. It is documented as the number of times an embedded posting list has been used, but it was incremented where such a posting list is decoded from the dictionary. A query served from the text index tokens cache uses embedded postings without decoding them, so the event under-counted real uses, and a background merge decodes them without any query, so it also over-counted.Description
TextIndexUsedEmbeddedPostingsis documented as "Number of times a posting list embedded in the dictionary has been used", but it was incremented insideTextIndexSerialization::deserializeTokenInfo, a byte decoder that takes aReadBufferand knows nothing about queries. The decoded token info, including its embedded postings, is stored in the server-global tokens cache, so a later query that hits the cache uses those postings throughTextIndexAnalyzer::addTokenInfowith no decoding and no increment. Conversely a background merge decodes every token of a dictionary block, incrementing the event without any query involved.This restores the placement the event had until commit
bd477d0("slightly better", part of #98226, a pull request about token ordering), which moved it from the use site into the decoder. Note thatTextIndexAnalyzerlived inMergeTreeIndexText.cppat the time.The event is now incremented in
TextIndexAnalyzer::addTokenInfo, guarded by the existingisTokenNeededpredicate so a posting list that no live query can still consume is not counted. The non-embedded posting path cannot reach it by construction, since the increment sits inside theembedded_postingsbranch.Users observing this event will see it rise for cache-served reads and no longer rise during merges. The name and description are unchanged, so no documentation changes.
This does not claim to fix the flaky
02346_text_index_parallel_replicas, whose second probe column reads this event. That test is not modified. The fix removes the only mechanism I could measure for its1 0result diff, but 2326 local runs of it never reproduced the CI failure, so I cannot demonstrate the flake is gone.An alternative is to rename the event and add a new "used" one. That keeps existing dashboards numerically stable but breaks the name across 12 documentation pages, so I preferred making the code match the documented meaning.
Validation
Both directions, with the server restarted per arm and the served
buildId()asserted equal to eacharm's
readelf -nBuild ID:UsedEmbeddedPostingsTokensCacheHitsTokensCacheMissesThe new test fails on master with a one-line diff (
warm 1 1 0becomeswarm 0 1 0) and passes withthe fix. Its warm row also asserts a cache hit and zero cache misses, so it cannot pass by silently
missing the cache and decoding again.
Mutations, each rebuilt and each moving the Build ID: putting the increment back in the decoder
reddens the warm row; removing it entirely reddens both rows; dropping the
isTokenNeededguard, orhoisting the increment above the readable-rows block, makes an all-tokens-failed query count 2
embedded posting lists instead of 1.
Regression sweep over 170 text-index tests, baseline built from the same worktree with only the two
source files reverted: the same 170 ran in both arms, 0 regressions, 1 improvement (this pull
request's own test), 3 failures shared by both arms from a bare local sandbox.
02346_text_index_parallel_replicaspasses in both arms. 50 randomized runs of the new test: 50passed, 0 failed.