Repository navigation
Read text index virtual columns right before the first PREWHERE step that uses them - #124880
Conversation
…that uses them The steps that read the `__text_index_*` virtual columns were always placed before all PREWHERE steps, so the text index was read for every selected row, ahead of cheaper and more selective conditions and of the `__topKFilter` dynamic filter. `getPrewhereActions` now inserts each index read step right before the first step that uses its columns, and reads the columns that no step uses after the last PREWHERE step. Steps for index tasks without columns are no longer created. Adjacent conditions on the virtual columns of one index share a step (like conditions on subcolumns of one column, via a storage name override in `tryBuildPrewhereSteps`), so that the index reader fills them in one pass and keeps the locality of the query-local postings cache. On 30M log rows sorted by `(service, ts)` with `... ORDER BY ts DESC LIMIT 100`, the text index reader reads ~16x fewer rows; queries are 6-17% faster when the text predicate is not trivial. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
Workflow [PR], commit [c3d2f83] Summary: ✅
AI ReviewSummaryThis PR moves text-index virtual-column reads to the latest possible read step and teaches PREWHERE step splitting to track index usage separately from physical-column usage, which is the right shape for the intended optimization. I did not find a remaining correctness issue in the current diff or in the previously discussed threads, but I cannot approve it yet because the PR is categorized as Requests for evidence
Final Verdict
|
Build profile diff (arm_release)Commit See the job log for details. |
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The test runs two queries over a log table with a text index. In one, a manual `PREWHERE` on `host` is much cheaper than reading the index. In the other, the dynamic top-K filter on `ts` rejects most granules before the index is read. `ts` is in the sorting key only through an expression, so the primary key does not prune granules by the top-K threshold, and the `PREWHERE` filter does the work. Local perf.py, base vs this PR, 20M rows, three runs: the manual `PREWHERE` query is 46-48% faster and the top-K query 35-37% faster. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
📊 Cloud Performance Report ✅ AI verdict: This PR changes how text-index columns are read during PREWHERE: they are now read right before the first step that needs them. None of the flagged queries can reach that code, because the ClickBench hits table has no text index. In that case the new step-placement code exits right away, and the step-splitting code only scans an empty index list. The ClickBench Q33 (-8.1%) and Q34 (-8.0%) improvements are downgraded to not sure: both are unfiltered GROUP BY queries, noisy on master and inside master's recent range. Q28 (+6.8%) stays not sure, with flat CPU time and mixed signals from the two tests. TPC-H showed no flagged changes, and the PR's own new text-index perf test is the right place to judge its effect. 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
|
Walk the PREWHERE steps once and, before each step, add a read step per index for the virtual columns that the step uses and that are not read yet. This replaces the precomputed inputs of all steps and the map keyed by position and index name, and does nothing when there are no index read tasks. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
`tryBuildPrewhereSteps` takes `IndexReadTasks` instead of a map from virtual columns to index file names. `resolveNodeInfo` puts a virtual column of an index into `NodeInfo::required_indexes` instead of passing the index name off as a storage column, and adjacent conditions share a step when `NodeInfo::readsSameColumns` holds for both storage columns and indexes. `addIndexReadSteps` again resolves the first step that uses each virtual column once, tracking only the columns of indexes, and places the read steps by `(position, index name)` instead of scanning every step for every index through a callback. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Replace the map keyed by `(position, index name)` with a vector of `steps.size() + 1` elements, one per step position, each holding the columns to read for every index read task. Empty elements are skipped. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
aabf43b
… runtime filter in the query condition cache" This reverts commit 64da8a0, reversing changes made to be89302. Conflicts resolved by keeping the later changes in the same lines: `is_query_prewhere` (ClickHouse#130645), the `last_reader_evaluating_defaults` argument (ClickHouse#128452), `readsSameColumns` (ClickHouse#124880), `follows_top_k_filter` (ClickHouse#129882), and the PREWHERE query condition cache write of ClickHouse#115522 in its own form before it merged ClickHouse#122380. Co-Authored-By: Claude Opus 5.5 <[email protected]>

Related: #124595
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Speed up queries that filter by a text index together with other
PREWHEREconditions, such as the dynamic filter ofORDER BY ... LIMITqueries.Workflow [PR]
Sync PR [sync-upstream/pr/124880]
Version info
26.10.1.2396-master(included in26.10and later)