Repository navigation
Optimize text index analysis - #109886
Optimize text index analysis#109886
Conversation
Precompute the hash of `TextSearchQuery` in the constructor because `getHash` is called on hot paths (per part, per virtual column and per mark). For that, `phrase_tokens` are now passed to the constructor, so all fields are set before the hash is calculated. Added an overload of `getSipHash128AsHexString` that takes a precomputed `UInt128`; the byte order of the hex string differs from the `SipHash`-based overload, so the names of text index virtual columns in test references changed. Reserve the memory for result columns in `MergeTreeReaderTextIndex` for the number of rows to read. Previously the columns grew mark by mark through a chain of large reallocations, which caused heavy contention on allocator mutexes (`malloc_mutex_lock_slow` at ~10% of CPU in profiles) across reading threads and made `shrinkToFit` copy the whole column again. Reduces CPU time of a `hasAllTokens` `count()` benchmark query by ~40%. Co-Authored-By: Claude Fable 5 <[email protected]>
All fields of TextSearchQuery must not be mutated after construction, otherwise the precomputed hash becomes stale. Enforce this invariant by making the fields private and exposing them through const getters. Co-Authored-By: Claude Fable 5 <[email protected]>
|
Workflow [PR], commit [278afe2] Summary: ❌
AI ReviewSummaryThis PR precomputes Missing context / blind spots
Final VerdictNo blocking issues found in the current revision. |
| auto column = columns_to_read[i].type->createColumn(*serializations[i]); | ||
| column->reserve(max_rows_to_read); | ||
| columns[i] = std::move(column); |
There was a problem hiding this comment.
A minor improvement with preallocation.
| cursors.push_back(it->second); | ||
| } | ||
| else if (query_builder.postings->cardinality() > 0) | ||
| else if (!query_builder.postings->isEmpty()) |
There was a problem hiding this comment.
A minor improvement: roaring::cardinality has the complexity O(number of containers).
| const TextIndexAnalyzer::QueryBuilder & TextIndexAnalyzer::getQueryBuilder(const TextSearchQuery & query) const | ||
| { | ||
| auto hash = query.getHash().get128(); | ||
| auto hash = query.getHash(); |
There was a problem hiding this comment.
A hot path with hash for which this refactoring is done.
|
📊 Cloud Performance Report ✅ AI verdict: This PR is a text-index refactor: it precomputes the SipHash of TextSearchQuery, moves its fields behind getters, and reserves reader columns up front. None of that touches the code paths ClickBench Q4 and Q15 execute (a plain aggregate scan and a GROUP BY), so neither query's apparent improvement can come from this change. Both show flat CPU with only wall-clock dipping and medians pinned to the bottom of the master variance band, so the deterministic no_change/within-envelope verdicts are correct — the ~19-20% deltas are run-to-run noise, not a real effect. No regressions or genuine improvements are attributable to this PR. clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 266/275 (96.73%) · Uncovered code |
|
A flaky check failed because of high load in parallel runs of tests: |
|
The reason why the name of virtual column has changed: It shouldn't be a problem, though, because we expose this column with an alias to the original column name to the planner, and distributed queries on different versions won't break. |
c920e6f
|
This is kind of a performance regression. Let's backport it to 26.6 |
Resolve cherry-pick conflicts for #109886 (Optimize text index analysis). The release branch does not contain #108114 (`num_live_tokens` / better discarding of `Any` text queries), so the conflicts are resolved by keeping 26.6's logic and applying only #109886's changes: the field->getter refactor of `TextSearchQuery`, the precomputed hash, and the result-column memory reservation in `MergeTreeReaderTextIndex`. The `02346_text_index_bug90778` reference is updated for the fixed virtual column name hash (the old name was a double-finalized `SipHash` accident); the `equals` query uses `direct_read_mode = Exact` on 26.6, giving the hash `55ee63b12fbf5cb6a7510c6b2df99282`. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Cherry pick #109886 to 26.6: Optimize text index analysis
Backport #109886 to 26.6: Optimize text index analysis
…-analysis Optimize text index analysis
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
Cache the
SipHashvalue inTextSearchQuerybecause we need to compute the hash for each granule, and this path became hot during index analysis in large tables.Version info
26.6.2.93