Repository navigation
Conversation
In materialize mode (always for the default `none` posting list codec and for `LIKE`), `MergeTreeReaderTextIndex` builds the rows of every granule separately: it clips the analyzer's folded postings and every block of every large token to the granule's range, intersects the clipped lists and flattens the result. For an `All` query over frequent tokens each clip copies and recounts the 65536-row Roaring container that eight consecutive 8192-row granules share, and every intersection is redone per granule. An `All` query with at least two posting lists and a large token now keeps, per virtual column, the intersection of the folded postings with the blocks of the first, second, ... large token, restricted to the Roaring container that holds the granule. A kept step is reused while the granule lies in the same container and its token has the same blocks (compared by identity), so it is rebuilt once per container and once per block boundary instead of once per granule; each granule then does one clip and the existing flatten. Blocks are read with the same arguments and the same early exits as before, so results and `TextIndexReadPostings` are unchanged. Only granules whose rows lie in one container take this path. A granule that spans several containers (`index_granularity` above 65536, or an adaptive granule crossing a container boundary) has nothing to reuse, because its clips and intersections are already one per container, so it keeps the previous code, as do `Any`, single-list and lazy-mode reads. Based on the analysis and patch by @snelheidai, ClickHouse#122557. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Results of multi-token searches read from a text index must match evaluation without the index when posting lists span several posting list blocks, granules, Roaring containers and parts, including partial-granule and reverse reads, and granules of several sizes: inside one container, spanning several containers, and crossing a container boundary. The performance test measures multi-token `hasAllTokens` searches over frequent tokens on the default `none` posting list codec. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The new `TextIndexPostingsIntersectionsReused` counts granules that reuse the intersection kept for the previous granules of the same 65536 rows. Test 05275 asserts it is positive for a scan of 1024-row granules and zero for 65536-row granules. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Drop the comment on the one-caller helper intersectWithBlocks and shorten the comments on the cache invalidation in setIndexGranule and on intersectPostingsInContainer to one line each. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 1 finding, none on the re-review after the fix) plus my own review (3 nits).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20260928-014000 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-4:20260927-225300 |
|
Workflow [PR], commit [65d5208] Summary: ❌
AI ReviewSummaryThis PR reuses Missing context / blind spots
Final VerdictStatus: ✅ Approve, subject to normal CI completion. No review changes required. |
Build profile diff (arm_release)Comparing commit See the job log for details. |
|
📊 Cloud Performance Report ✅ AI verdict: This PR changes only the text index direct-read path. Consecutive granules in the same 65536-row range can now reuse a cached intersection of posting lists for multi-token hasAllTokens searches. It also adds a new profile event and new tests. None of the four flagged improvements (clickbench Q33 -13.8%, Q34 -13.1%, tpch_adapted_1_official Q1 -18.5%, Q7 -22.2%) reads a text index, and all four have noisy history, so all are downgraded to not sure as run-to-run variance. The ClickBench medians are inside master's recent range, and the TPC-H deltas are only 12 to 18 ms. The change's real effect should be measured with the new text_index_materialize_intersection performance test, not with these benchmarks. clickbenchFlagged queries (2 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_officialFlagged queries (2 of 22)
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. Debug info
|
CI finish ledger - e334abbEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
146 of 146 check runs completed (130 passed, 14 not selected, 2 red: the two shards above), Session id: cron:our-pr-ci-monitor:20260928-073120 |
…-intersect-per-container Master replaced `large_postings_streams` with in-place analyzer checks (`isTokenNeeded` / `hasReadPostings`, 67bc365), so the per-container intersection path now skips tokens with the same predicate as `buildPostingsForQuery` and takes the analyzer as a parameter. The constructor keeps only the `intersection_steps` resize; master dropped the other cursor resizes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Since ClickHouse#120517 the text index reader serves incomplete granules, so with a random `max_block_size` below 65536 (and prewhere off) one granule of `tab_container` is read in several slices. Slices of one granule share the cached intersection, which is correct, but it made the negative control report a reuse in 4 of 20 randomized runs. Pin `max_block_size` to the granule size so the control keeps checking that whole granules of different containers never share an intersection. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ainer Since ClickHouse#120517 the reader serves incomplete granules, so the one-container check on the read slice also let slices of granules spanning several Roaring containers into the cached path. Check the whole granule instead, which keeps those granules on the previous code as measured. The test now also checks that a granule spanning two containers read in 1024-row slices and a single-token search never reuse an intersection; reverting either check makes its line fail. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The test measures the direct-read reuse path, so it should not depend on the default of query_plan_direct_read_from_text_index. Forcing idx makes it fail loudly if the planner stops using the index, as text_index.xml does. Co-Authored-By: Claude Opus 5.5 <[email protected]>
CI finish ledger - 7390ee9Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
CIDB has no other Session id: cron:our-pr-ci-monitor:20261013-030009 |
|
|
…-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]>
CI finish ledger - 65d5208Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
CIDB has no other Session id: cron:our-pr-ci-monitor:20261027-153012 |
Closes: #122557
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Text index searches for several tokens (
hasAllTokens,hasAll) with frequent tokens are faster when posting lists are applied inmaterializemode, which is always the case for the defaultnoneposting list codec: the intersection of the posting lists is built once per 65536 rows instead of once per granule.Description
In
materializemode the text index reader clipped the folded postings and every block of each frequent token (its posting list spans several blocks) to each granule and intersected them per granule, although eight default granules share one 65536-row Roaring container. Analysis and patch by @ snelheidai.For a granule inside one container, an
Allsearch now keeps per column the intersection of the folded postings with each frequent token's blocks in turn, restricted to that container, and reuses it while the next granules lie in it and use the same blocks (compared by identity); each granule then does one clip and the existing flatten. Granules spanning several containers (nothing to reuse),hasAnyTokens, single-token searches and lazy mode keep the previous code. Blocks are read as before, so results andTextIndexReadPostingsare unchanged. A kept intersection is at most one container (8 KiB) per token.A new test compares multi-block searches with evaluation without the index (granules inside one container, spanning several or crossing a boundary; reverse reads; several parts) and checks the new profile event
TextIndexPostingsIntersectionsReused; removing either cache key, the final clip, theAllor one-container check, or the reuse fails it. A sweep of 1220 predicate and setting combinations over three codecs matched master; a performance test is added.Against an A/A control on release builds, the text index read takes 26-71% less time at one thread (9-50% at four) and index-bound count queries run up to 3 times faster; unchanged paths stay within the noise (instructions within 2%). Peak memory grows by at most 1.5 MiB.
I did not take the posted patch as is: it also replaced the flatten and the
hasAnyTokensand single-list fills, was 54% slower on 1M-row granules on x86 and used up to 64 MB more memory per query.Measurements
x86 release builds without ThinLTO, 10M-row single-part tables, postings cache off; crossover effect FIX/BASE over 20 paired rounds; "within" = inside the A/A noise.
count(),hasAllTokens(s, ['w1', 'w10'])count(),hasAllTokens(s, ['w1', 'w2', 'w3'])count(),hasAll(tags, ['t1', 't2'])sum(id),hasAllTokens(s, ['w1', 'w2'])hasAnyTokens,hasToken,LIKE,pfor, count from the index, 1M-row granulesWorkflow [PR]
Sync PR [sync-upstream/pr/122597]