Repository navigation
Text index: choose leapfrog intersection algorithm only when it can skip blocks - #121038
Conversation
…ne the cursor fast paths The lazy AND over bitpacked posting lists chose leapfrog whenever the minimum density was below `text_index_lazy_intersection_density_threshold` (0.2). But leapfrog only pays off when the sparsest list can skip whole packed blocks of the densest one: a block of `BLOCK_SIZE` postings of a list with density d_max spans about `BLOCK_SIZE / d_max` rows, and the sparsest list has about `d_min * BLOCK_SIZE / d_max` postings in that span. Once that is at least one, every block is decoded anyway and leapfrog only adds a search per posting. For an AND over tokens of comparable moderate density (0.05-0.11), where the result is nearly the smallest list, leapfrog took 2.5-3x the CPU of the brute-force counting pass and lost to the roaring codec. The selector now uses brute force when `d_min * BLOCK_SIZE >= d_max` as well. The setting keeps its role as an absolute cap: `0` still forces brute force and `1` still forces leapfrog, which the existing tests rely on. `advance` and `next` get inline fast paths for the common case (the target or the next value lies within the decoded block); block and segment transitions go through the out-of-line `advanceSlow` and `nextSlow`. `gallopingLowerBound` moves to the header for that. Forced leapfrog gets 14-15% cheaper. With both changes, multi-token AND queries over a 1B-row table take 2.4-3x less single-thread CPU with the bitpacking codec and are on par with or faster than the roaring codec. Co-Authored-By: Claude Fable 5.1 <[email protected]>
…lgorithm setting `text_index_lazy_intersection_density_threshold` becomes obsolete and `text_index_postings_cursor_intersection_algorithm` takes its place, with the values `auto` (the default), `bruteforce` and `leapfrog`. The threshold no longer selected anything. A posting list density is at most `1`, so the block span rule (brute force when `min_density * BLOCK_SIZE >= max_density`) already holds for every density at or above `1 / BLOCK_SIZE`, which is `0.0078`: at the default threshold of `0.2` the comparison against it could never decide a query, and only the two ends of the range still did anything - `0` forced brute force and `1` forced leapfrog. The new setting says that directly: `auto` applies the block span rule, `bruteforce` and `leapfrog` pin a path. Leapfrog is still used regardless of the setting for 256 or more posting lists, which the brute-force `UInt8` counters cannot represent. The old name stays accepted and ignored, and so does the name it itself replaced, `text_index_density_threshold`, which is why the obsolete entry is declared with `ALIAS` rather than `MAKE_OBSOLETE`. Tests that pinned a path through the threshold now name the algorithm instead. `04652_system_documentation_settings_history` used the old setting as its example of a rename that keeps the old name as an alias; `system.documentation` does not list obsolete settings, so that case moves to `evaluation_time`, which has the same shape. Co-Authored-By: Claude Fable 5.1 <[email protected]>
… trim the setting description The two old names, `text_index_lazy_intersection_density_threshold` and `text_index_density_threshold`, are declared with `MAKE_OBSOLETE` like the rest of the obsolete section instead of one `ALIAS` entry. Both stay accepted and ignored. The obsolete name has no settings changes record, only the new setting `text_index_postings_cursor_intersection_algorithm` does. The description of the new setting drops the block span formula and the note on the 256 posting lists limit of brute force. The comment of `advance` is shortened. Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
Workflow [PR], commit [52ceb02] Summary: ❌
AI ReviewSummaryThis PR changes lazy text-index PR Metadata
Findings❌ Blockers
Final VerdictRequest changes. LLVM Coverage ReportMeasured on commit 52ceb02.
Changed lines: Changed C/C++ lines covered: 203/207 (98.07%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes71 object files changed (+34.97 KiB total), 0 added.
716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units1910 translation units recompiled, 11561 s compile time in total, 1910 of them have a recent master baseline. Symbol sizes
|
|
📊 Cloud Performance Report ✅ AI verdict: no significant changes detected. K_source=6 K_base=30 flagged=0/65 clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
`05232_text_index_lazy_intersection_block_span_rule` asserts which algorithm
the `auto` rule picks, but the same commit added
`text_index_postings_cursor_intersection_algorithm` to the settings
randomizer of `tests/clickhouse-test`. When the randomizer picked
`bruteforce` or `leapfrog`, the two `_default` queries ran the forced
algorithm and the profile event assertions flipped:
-05232_rule_mid_pair_default 1 0
+05232_rule_mid_pair_default 0 1
Set the algorithm to `auto` in the test instead of relying on the default
value. The two queries that force `bruteforce` and `leapfrog` already pin it
per query.
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=121038&sha=latest&name_0=PR
ClickHouse#121038
Co-Authored-By: Claude Opus 5 <[email protected]>
…rithm setting The brute-force intersection counts matches in a `UInt8` per row, so an intersection of 256 or more tokens takes leapfrog even when the setting `text_index_postings_cursor_intersection_algorithm` forces `bruteforce`. Say so in the description of the setting. ClickHouse#121038 (comment) Co-Authored-By: Claude Opus 5 <[email protected]>
…st has no rows in the window `linearOr` and `linearAnd` now return whether they wrote anything to the output. Both scan functions return as soon as the lower bound for the window lands past it: the block has a doc_id at or past `row_offset`, so an empty range means that doc_id and everything after it are beyond the window. `intersectBruteForce` stops at the first cursor that wrote nothing, since the intersection over the window is then empty: the output is left zero-filled when it is the first cursor and cleared with `memset` otherwise, and `finalizeCounters` is skipped. The new profile event `TextIndexLazyBruteForceEarlyExits` counts the exits. The cursors are sorted by ascending cardinality for the brute-force intersection as well, not only for the leapfrog. The sparsest list is the most likely to be empty in a window, and it leaves the largest all-zero regions for the denser lists to skip. Before, the order came from a hash map and was arbitrary. Marks outside the row range of a token's posting-list segments never reach the cursors, so the exit fires for marks inside a gap of a token's range, where the straddling segment covers the marks but has no rows in them. Single-threaded, the intersections with such a token get 26 % faster on a 50M-row table; `text_index_lazy_wide_granule` is unchanged. Co-Authored-By: Claude Fable 5.1 <[email protected]>
… posting list wrote `linearOr` and `linearAnd` return a `PostingsCursorWindow`, the half-open range of rows they wrote, instead of a flag. The cursors after the first one scan only the window of the previous cursor, each narrowing it to the rows it incremented itself: a row outside misses at least one posting list and can never reach count == n. Packed blocks and segments outside the window are skipped by a range comparison instead of a scan of their all-zero output region, and `finalizeCounters` runs over the first cursor's range instead of the whole mark. The block search in `linearSegments` resumes from `current_block`, the last decoded block, when that block still lies before the window, instead of bisecting the whole segment on every call. `linearEmbedded` resumes from `index` in the same way and leaves it at the first doc_id past the window; before, it galloped from index 0 on every mark, which for a flat array of a million postings costs about 40 cache-missing probes per mark. `findRowRangeEnd` gallops as well. Both resume positions are checked against the window first, so a call out of order only costs a search from the start. Zeroing the counters between the first cursor's range and the final window with `memset` and comparing the window alone was measured against the single compare pass: it wins only when the first range is large and the window much narrower (8192 rows narrowed to 440: 50 vs 64 ns) and loses on the common narrow ranges (440 rows: 7.5 vs 5.2 ns), so the compare pass covers the first range. Single-threaded on a 50M-row table: intersections with a token clustered inside every mark get 13-27 % faster; queries whose sparsest list is a single-segment flat array get 16-28 % faster (the resume in `linearEmbedded`); `text_index_lazy_wide_granule` and the gap queries are unchanged. The number of decoded packed blocks does not change: the all-zero regions were already skipped, what goes away is the scans that found them. The new test `05234_text_index_lazy_brute_force_narrow_window` compares the results with a plain column scan and checks through `TextIndexLazyBlocksSkippedResolved` and `TextIndexLazySegmentsSkippedResolved` that the blocks outside the window are no longer examined. Co-Authored-By: Claude Fable 5.1 <[email protected]>
The linear scans write their ranges in ascending order, so a new range always starts past the current end of `PostingsCursorWindow`: `extend` only sets `begin` on the first write and moves `end` afterwards. The `std::min` on `begin` was redundant; both preconditions are asserted. Co-Authored-By: Claude Fable 5.1 <[email protected]>
The flag was equivalent to `current_segment != nullptr` on every path that read it. `prepareSegment` is never called for embedded cursors, so its early return is replaced by `chassert(!is_embedded)`. Add `chassert(current_segment)` in `next`, which relies on `advance` positioning a compressed cursor first. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
cf7023d

Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Optimized queries that search for several tokens at once with a text index, such as
hasAllTokens. Improved the automatic choice of algorithm for intersecting posting lists, controlled by the new settingtext_index_postings_intersection_algorithm.Workflow [PR]
Sync PR [sync-upstream/pr/121038]
Version info
26.10.1.613-master(included in26.10and later)