Repository navigation
Conversation
- Brute-force intersection: a packed block (or segment) of the next posting list is skipped when no counter in its rows equals the number of posting lists applied so far, i.e. when no row there is in all of them. Before, it was skipped only when its rows were all zero, so rows of earlier lists that had already failed kept the blocks of the following lists from being skipped. - Leapfrog intersection: a single loop led by the sparsest cursor replaces `intersectTwo`, `intersectThree`, `intersectFour`, `intersectLeapfrogLinear` and `intersectLeapfrogHeap`. The other cursors are advanced to the lead's doc id in ascending cardinality, and the first one that overshoots moves the lead, so a denser cursor only advances to the doc ids that all the sparser ones contain. The loop is unrolled for up to 8 cursors. - A packed block of consecutive row ids is padded as a whole instead of being decoded (new ProfileEvent `TextIndexLazyBlocksSkippedDense`). - The resolved-region checks are skipped for an already loaded segment or decoded block, and use `memchr` instead of the hand-written AVX2 `hasNoZeros`. Local measurements (50M rows, one part, `max_threads = 1`, interleaved A/B against the same master): leapfrog over 3+ skewed posting lists -30..-63%, brute force over 3 lists with clustered rows -20..-34%, tokens with long runs of consecutive rows -17..-69%, other shapes within noise. The perf test `text_index_lazy_wide_granule` shows -42..-48% for the 4-token leapfrog queries and no slowdowns. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…gImpl` Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
Workflow [PR], commit [b2bc31e] Summary: ✅
AI ReviewSummaryThis PR speeds up lazy text-index intersections by tightening the brute-force skip condition for Final Verdict
LLVM Coverage ReportMeasured on commit b2bc31e.
Changed lines: Changed C/C++ lines covered: 139/142 (97.89%) · Uncovered code |
A loaded dense segment skipped the segment-level `canSkipRegion` check and was padded even when its region was already resolved. ClickHouse#123873 (comment) - Run the segment-level and block-level `canSkipRegion` checks for loaded segments and decoded blocks too. - Move the dense block shortcut before the block-level check: padding at most a block of rows is cheaper than the check. - Replace `finalizeCounters` (AVX2 intrinsics with one vector per iteration, chosen by the runtime dispatch even on the default `x86-64-v3` build) with a plain loop inlined into `intersectBruteForce`, which the compiler vectorizes and unrolls. - In `advance` past the last doc_id of an embedded list, move `index` to its end. - `04257_text_index_lazy_profile_events`: the covered block of Q4 is dense and is now padded by the dense shortcut, so Q4 uses a token with a non-dense block. In a standalone microbenchmark of the linear path, the dense block shortcut first is −41..−44% for an AND with dense runs, and the plain finalize loop is −22..−48% on the kernel and −0.5..−10% per brute-force window. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
A segment that reaches the clip computation always overlaps the window: the preceding `continue` / `break` filters, the `begin <= end` validation of ranges on read, and the non-empty windows passed by the callers guarantee it. Replace the checks with `chassert` and compute the clipped offset and count once for segments and blocks. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Both scans searched the decoded values for the window, moved `index` past it and padded the matched rows with the same code. Move it to `linearDecoded`, which returns the range of rows written. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Clang emitted `linearDecoded` out of line, adding a call per decoded block to `linearSegments`. In a microbenchmark of the lazy linear path this cost +0.7..+0.9% on average and up to +6% for a union of a list of dense runs with a uniform list. With `ALWAYS_INLINE` the timings are within the noise of the code before the refactoring. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…ntersection-optimizations Resolve conflicts with ClickHouse#123786 in `MergeTreeIndexTextPostingListCursor`: move the new `blocks_skipped_dense` counter into `LazyPostingsStats`, switch `intersectLeapfrogImpl` to raw cursor pointers, and move the lead-first cursor positioning into the `Leapfrog` branch of `lazyIntersectPostingLists` (cursors are now sorted by the caller). Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
`std::ranges::copy` took the length from the vector at runtime, so every fixed-size specialization called `memcpy` with a runtime size. With `num_cursors` as the count the copy is inlined. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
CurtizJ
left a comment
There was a problem hiding this comment.
A few optimizations in this PR
| /// to its doc_id. So a denser cursor only advances to the doc_ids that all the sparser cursors contain. | ||
| /// `num_cursors` is the number of cursors when it is fixed at compile time, which unrolls the loops over them, or 0. | ||
| template <size_t num_cursors> | ||
| bool intersectLeapfrogImpl(UInt8 * out, const std::vector<PostingListCursor *> & cursor_ptrs, size_t row_offset, size_t effective_end) |
There was a problem hiding this comment.
- More optimal and simpler leapfrog.
| if (static_cast<size_t>(block_last) - block_first + 1 == block_size) | ||
| { | ||
| ++stats.blocks_skipped_dense; | ||
| padDenseRange<op>(data + block_clip_offset, block_clip_count); | ||
| window.extend(block_clip_begin, block_clip_end); | ||
| continue; | ||
| } |
There was a problem hiding this comment.
- Fill contiguous blocks without decoding.
| const int value = op == PadOp::Or ? 0 : num_applied; | ||
| return memchr(data, value, count) == nullptr; |
There was a problem hiding this comment.
- Skip regions for
ANDnot only if the region is full 0, but also if the region doesn't have rows that can reachcount == n.
…ear scan For `PadOp::And`, a dense block whose rows have no counter equal to `num_applied` was padded and added to the returned window, so `intersectBruteForce` neither stopped early on an empty intersection nor narrowed the window for the next cursor. The block-level `canSkipRegion` check now runs before the dense block shortcut again. ClickHouse#123873 (comment) Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
📊 Cloud Performance Report ✅ AI verdict: This PR only changes the lazy text-index posting-list code: it merges the leapfrog intersection variants into one loop, makes the AND-side skips exact, adds a dense-block shortcut and drops the hand-written AVX2 helpers. ClickBench and TPC-H queries don't use text indexes, so none of them run this code. The three flagged ClickBench queries (Q16 +15.9%, Q32 +10.1%, Q33 +5.6%) are all aggregation-heavy and stay not_sure. Q16 and Q33 are within master's normal range for those queries, and on Q32 the two tests disagree. Two of the PR's runs also shared a host, which likely explains the small, uniform rise in CPU time, so nothing here needs action from the author. 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
|

Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Improved performance of intersection of text index posting lists.
Workflow [PR]
Sync PR [sync-upstream/pr/123873]
Version info
26.10.1.1660-master(included in26.10and later)