Repository navigation
Conversation
When a text index gives up its LIKE/ILIKE dictionary scan for a part, or a hasPhrase query exceeds text_index_hint_max_selectivity, the direct-read path must still produce the pattern's virtual column. It does that by reading the required physical columns once into a block and then, once per mark, cutting that mark's slice out of every physical column into a fresh block and evaluating the original predicate on the copy. IColumn::cut is a real copy, so each such query copies the searched column's bytes once more than it needs to: with the defaults a read block spans about max_block_size / index_granularity marks, so the predicate runs 8 times over 8 separate copies instead of once over the block the reader already holds. For a text index on a plain column with neither a preprocessor nor a postprocessor, evaluate the predicate once for the whole read instead, and append the result to the output column after the mark loop. The physical block is shared by a shallow Block copy, so no column data is copied at all. Every other index keeps the per-mark evaluation unchanged. The rule is read from the index metadata, once per reader, because a reader serves exactly one index. On such an index the fallback expression is the search function (like, ilike, startsWith, endsWith, hasPhrase) applied to the indexed column with constant arguments, plus the cast to UInt8 and the materializing outputs, which are pointer copies for a full column. None of these can observe how many times it runs, and no intermediate holds more than two bytes per row, apart from the dictionary part of a LowCardinality result, which the per-mark path also builds once per mark. Only an index expression or a pre/postprocessor can bring anything else into the expression: a function with an observable side effect such as sleep, an executable UDF that runs its command once per call while reporting itself deterministic and side-effect free, or an intermediate as wide as the searched column. Those indexes stay on the per-mark path. So does ilike over an ASCII lower/upper preprocessor, which would be safe to hoist but is excluded to keep the rule a single metadata check. The fallback reader's row count is now stated where the block is built. The per-mark cut enforced that contract by accident, throwing PARAMETER_OUT_OF_BOUND on a short block and dereferencing null on an absent column; the reader's return value is discarded, a Wide part reports the maximum over its columns, and nothing on this path fills missing columns. A single evaluation over the whole block consumes that contract directly, so it is checked once per read instead, which also turns the existing path's late error into an early named one. The result is appended rather than moved: res_columns accumulates across several readRows calls through MergeTreeRangeReader::DelayedStream, so moving the evaluated column in would discard rows a previous call had gathered. Its length is read_rows, so a read that stops before the end of the block stays correct by construction. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Drop the design narration above the fallback row-count check and shorten the evaluateFallback declaration comment. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 1 finding), plus my own review.
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-10:20260925-223100 |
|
Workflow [PR], commit [3bf01fa] Summary: ❌
AI ReviewSummaryThis PR changes the text-index direct-read fallback so exact Missing context / blind spots
Final Verdict✅ No review findings. LLVM Coverage ReportMeasured on commit 3bf01fa.
Changed lines: Changed C/C++ lines covered: 40/43 (93.02%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes4 object files changed (+23.77 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 units9 translation units recompiled, 42 s compile time in total, 9 of them have a recent master baseline. |
|
📊 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
|
CI finish ledger - 3bf01faEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
All 173 check runs completed (137 pass, 35 not selected, 1 red), Session id: cron:our-pr-ci-monitor:20260926-050212 |
|
Correction to the ledger above: the two binaries do not differ only by this diff, and the
@alexey-milovidov, this is the comparability problem the build profile diff solved with the warmup baseline (8576ccf). For the perf comparison, would you take (A) a reference built with the PR flags (link and upload the |
|
@ahmadov If you have time, could you look at this one? Low-priority though. |
|
@egor-click, a question about the perf reds that #124676 will not remove. #124676 makes the Should such reds stay blocking and be left to the reviewer (A), or should I measure how often they red PRs once #124676 is in, and propose a check that tells them apart (B)? |
lets wait for 124676 and decide after, it feels like the right fix for harness bug |
|
Thanks. I'll come back here with how often such reds still fire on unrelated PRs once #124676 is merged and has a few days of runs. |
|
|
|
@groeneai there is no visible performance improvement with this PR. Let's merge the latest origin/master into it and see what performance benchmark produces. |
|
I pushed the master merge (9166982) a few minutes after the PR was closed, so there will be no new benchmark run here. I accept the decision. For the record, on the previous head the query this PR targets, |
|
@egor-click, the numbers I said I would bring once #124676 had some runs (it merged on Oct 20; #126977, which starts both servers without ASLR, on Oct 21 16:21Z). PR perf shards that compared against the performance reference build, Oct 21 16:30Z to Oct 22 10:12Z:
The clearest case is Should such reds (A) stay blocking and be left to the reviewer, or (B) be scored by the dashboard against the spread of the performance reference builds of recent master commits instead of official master runs? For (B) I can send the per-query spreads. |
|
@groeneai please send me per-query spreads, i am looking into getting back eval based also on historical differences between PR and Master |
|
@egor-click here they are: https://gist.github.com/groeneai/c6e8746173bf95e9463b69be5ebea698
For most queries PR runs are no noisier than master runs (median p95 of new/old: arm 1.017 master vs 1.019 PR, amd 1.028 vs 1.028). About 9% are clearly noisier (p95 at least 1.5 times as far from 1: 324 of 3679 arm queries and 295 of 3397 amd queries that have 30 or more jobs of each kind).
So among the queries that blocked 3 or more PRs, only |
|
@groeneai this sounds like the issue we need to fix in the test there were also a few PRs that removed some differences between master and pr, did they do any good? |
|
1. It is mostly not a master/PR difference. Share of arm jobs where new/old of this query was above 1.10:
So master runs have it too, while the dashboard held #120502 to 9.6% (4.8% history noise from 30 master points). The code it measures is 2. The harness PRs. I can't see an effect on the red rate yet. PR shards red on a dashboard row:
Over all queries, PR runs were already as noisy as master runs before #124676 (median p95 of new/old: 1.020 for both on arm, 1.031 master vs 1.030 PR on amd) and still are, so these PRs can only move a few queries. #126977 cut the master share above for |
Closes: #122229
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
A text index that cannot answer a
LIKE/ILIKEpattern or ahasPhrasephrase from its posting lists now evaluates the predicate once per read block instead of once per granule, without copying the column data first. Such queries take 3-9% less CPU time, and about half as much for narrow columns with a smallindex_granularity. Applies to text indexes on a plain column without apreprocessororpostprocessor.Description
When a text index gives up its
LIKE/ILIKEdictionary scan, or ahasPhrasephrase exceedstext_index_hint_max_selectivity, the direct read evaluates the predicate on the column data. It did so once per granule, each time on a copy of that granule. Reported with a patch by @ snelheidai.Now the predicate runs once over the block the reader already holds, without copying it, and the result is appended after the granule loop.
This applies to a text index on a plain column without a preprocessor or postprocessor, where the expression is the search function over that column with constant arguments: evaluating it once per block changes nothing observable, and its intermediates add at most 2 bytes per row. Other indexes, including
ilikeover alowerpreprocessor, and queries that convert the column, such asCAST(s, 'String')over aLowCardinality(String)column, keep the per-granule path, since their expressions can contain functions such assleepor intermediates as wide as the column; forcing the new path on a postprocessor index tripled its peak memory.The fallback reader's row count is now checked where the block is built, with a named error instead of a late
PARAMETER_OUT_OF_BOUND.Measured on the new path:
LIKE/ILIKE,hasPhrase, andstartsWith/endsWithon thearraytokenizer, overString,FixedString,LowCardinality,Nullableand subcolumns, Wide and Compact parts; a new test compares such reads with a table without the index. NULLs in aNullablecolumn still raise the existingCode: 349here (#113332 addresses it).On release builds with an A/A control: 3-6% faster at
max_threads = 1; at 192 threads the wall-time change is not distinguishable from the A/A noise, while CPU drops 3-7%; peak memory is unchanged. A performance test query is added.Measurements
FIX/BASE, two crossover replicates; the A/A value is the same estimator on BASE against a byte-identical copy.
FixedString(1)/LowCardinality, granularity 1024Workflow [PR]
Sync PR [sync-upstream/pr/122350]