Repository navigation
Optimize analysis of text index with using of generic exclusion search - #110530
Conversation
Optimize the hot path of MergeTreeIndexConditionText::mayBeTrueOnGranule, which is called for every mark of a part: - Replace the construction of a temporary roaring bitmap for the mark's row range and and_cardinality with roaring_bitmap_intersect_with_range, an allocation-free intersection check. The per-mark checks are moved from MergeTreeIndexGranuleText to MergeTreeIndexConditionText next to the RPN evaluation. - Resolve pointers to TextIndexAnalyzer::QueryBuilder for all RPN queries once in the analyzer's constructor instead of a hash lookup by the query hash per RPN element per mark. - Use an inlined vector for the RPN stack to avoid a heap allocation per mark. - Check the condition once on the whole row span of the requested ranges before the per-mark loop. The per-query checks are monotone with respect to the row range, so a false result proves the whole part can be skipped. Co-Authored-By: Claude Fable 5 <[email protected]>
Look up the query builder in mayBeTrueOnGranule by the query hash instead of the index in the flattened list of RPN queries. The hash of TextSearchQuery is precomputed in its constructor, so the lookup is a single hash-map probe anyway, and the extra vector of resolved pointers (along with the hidden requirement that query_builders is never rehashed after the constructor) is not worth the complexity. Co-Authored-By: Claude Fable 5 <[email protected]>
Replace the per-mark loop for the text index in filterMarksUsingIndex with genericExclusionSearch, the same algorithm that is used for the analysis of the primary key. The per-query checks in mayBeTrueOnGranule are monotone with respect to the row range: if the condition cannot be true on a range, it cannot be true on any of its subranges. So a range proven to have no matches is dropped as a whole without checking its marks one by one. It also generalizes the previous check of the condition on the whole row span of the requested ranges. The disjunction analysis keeps the per-mark loop because it needs partial results for every mark. filterMarksUsingIndex now takes the query Settings to read merge_tree_coarse_index_granularity, and MergeTreeSkipIndexReader stores the query context to pass the settings at read time. Co-Authored-By: Claude Fable 5 <[email protected]>
Mirror merge_tree_coarse_index_granularity and merge_tree_generic_exclusion_search_max_steps into MergeTreeReaderSettings instead of passing the query Settings to filterMarksUsingIndex, so MergeTreeSkipIndexReader does not have to store the query context. The step budget now also applies to the exclusion search over the text index. Co-Authored-By: Claude Fable 5 <[email protected]>
|
Workflow [PR], commit [cd0ae27] Summary: ❌
AI ReviewSummaryThis PR replaces the per-mark text-index analysis loop with generic exclusion search, adds the corresponding observability, and removes some reader-side overhead. The core algorithm looks sound, but the new text-index pruning now depends on exclusion-search settings that are not reflected in the skip-index query-condition-cache key, so different budgets/granularities can reuse stale cached mark ranges and lose the pruning the query asked for. Findings
Final Verdict |
|
📊 Cloud Performance Report ✅ AI verdict: This change is confined to the full-text (text) skip-index code path — it swaps the per-mark scan for a generic exclusion search and reworks the text-index reader's cursor bookkeeping. ClickBench Q15 exercises no text index, so it cannot plausibly benefit from this diff. The lone flagged row (Q15, clickbench, -16.5%) shows source and base medians both sitting inside master's current variance band with essentially unchanged CPU (2595 vs 2602 ms), so the deterministic envelope suppression to no_change is correct: this is run-to-run variance, not a PR effect. No real regressions or improvements to report; the benchmark's own text-index perf test is the relevant coverage for this change. clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
Mirror the primary-key instrumentation in the text-index branch of the generic exclusion search: new profile events `TextIndexGenericExclusionSearchAlgorithm` and `TextIndexGenericExclusionSearchStepLimitReached`, and report the reached step limit in the trace log. Add a test that runs the same text-index predicates under several `merge_tree_generic_exclusion_search_max_steps` budgets and `merge_tree_coarse_index_granularity` values and checks identical results and the expected profile events. Resolves review comments: ClickHouse#110530 (comment) ClickHouse#110530 (comment) Co-Authored-By: Claude Fable 5 <[email protected]>
| { | ||
| auto skip_index_read_result = index_read_result->skip_index_read_result; | ||
| chassert(mark < skip_index_read_result->granules_selected.size()); | ||
| const auto & skip_index_read_result = *index_read_result->skip_index_read_result; |
| main_reader_->all_mark_ranges, | ||
| main_reader_->settings) | ||
| , index(std::move(index_)) | ||
| , condition_text(assert_cast<const MergeTreeIndexConditionText *>(index.condition_template->generateUnsubstituted().get())) |
There was a problem hiding this comment.
There was a regression because generateUnsubstituted locks a mutex, and it was called for each granule.
| search_queries.push_back(condition_text->getSearchQueryForVirtualColumn(column.name)); | ||
| } | ||
|
|
||
| lazy_cursors.resize(columns_.size()); | ||
| prebuilt_cursors.resize(columns_.size()); |
There was a problem hiding this comment.
A small optimization to avoid lookups into the hash map for each granule.
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 268/279 (96.06%) · Uncovered code |
3881f8d
Mirror the primary-key instrumentation in the text-index branch of the generic exclusion search: new profile events `TextIndexGenericExclusionSearchAlgorithm` and `TextIndexGenericExclusionSearchStepLimitReached`, and report the reached step limit in the trace log. Add a test that runs the same text-index predicates under several `merge_tree_generic_exclusion_search_max_steps` budgets and `merge_tree_coarse_index_granularity` values and checks identical results and the expected profile events. Resolves review comments: ClickHouse#110530 (comment) ClickHouse#110530 (comment) Co-Authored-By: Claude Fable 5 <[email protected]>
…-condition Optimize analysis of text index with using of generic exclusion search


Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Optimized analysis of the text index.
Additional context
Depends on #109886.
A couple of optimizations: use exclusion search instead of iterating all granules; avoid creation of temporary roaring bitmaps for each range check.