Repository navigation
Conversation
|
Workflow [PR], commit [44a11ed] Summary: ✅
AI ReviewSummaryThis PR restores direct text-index reads for Missing context / blind spots
Final Verdict✅ No actionable review findings at LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 16/17 (94.12%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Compile time of recompiled translation units7 translation units recompiled, 14 s compile time in total, 7 of them have a recent master baseline. |
SET query_plan_max_limit_for_top_k_optimization = 1000 because ity is randomized. When 1, tryOptimizeTopK returns early (n > settings.max_limit_for_top_k_optimization, and our LIMIT 10 gives n = 10). No __topKFilter is installed, so the guard line prints 0. It's only in the "flaky check" jobs because those re-run the changed test with fresh randomization each time.
|
📊 Cloud Performance Report ✅ AI verdict: Release-transition baseline: compared against the last 26.8 master because no 26.9 master baseline exists at or before the trusted base-commit anchor. This PR narrowly fixes direct reads from a text index when an ExpressionStep from top-K optimization hides the filter above the read step; it only affects queries that use a text index with hasToken plus ORDER BY/LIMIT. None of the flagged ClickBench queries (Q18, Q28, Q33) use text indexes, so the three small improvements (-5.8% to -7.2%) cannot be attributed to this change. Q18 and Q28 are downgraded to not_sure as off-path variance, and Q33's no_change (delta within master's normal variance band) is correct. No performance impact from this PR is evident in these benchmarks. clickbenchFlagged queries (2 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
|
…ct-read-blocked-by-expression-step
|
Let's backport to 26.8 at least. |
I will give it a look, the change is pretty small, but the backport is not trivial because the code is pretty different |
Backport #115586 to 26.5: Fix lost text index optimization for queries with ORDER BY ... LIMIT
…for queries with ORDER BY ... LIMIT
Cherry pick #115586 to 26.8: Fix lost text index optimization for queries with ORDER BY ... LIMIT
…s with ORDER BY ... LIMIT
Backport #115586 to 26.8: Fix lost text index optimization for queries with ORDER BY ... LIMIT
ReproducerSET allow_experimental_full_text_index = 1;
SET query_plan_direct_read_from_text_index = 1;
SET use_top_k_dynamic_filtering = 1;
SET query_plan_max_limit_for_top_k_optimization = 1000;
SET query_plan_merge_expressions = 1;
CREATE TABLE tab
(
id UInt64,
v UInt64,
s String,
INDEX idx_s s TYPE text(tokenizer = 'splitByNonAlpha') GRANULARITY 1
)
ENGINE = MergeTree ORDER BY id;
INSERT INTO tab SELECT number, number % 1000, if (number % 100 = 0, 'error', 'fine') FROM numbers(10000);
-- plan references __text_index_idx_s_hasToken (index answers the filter)
EXPLAIN actions = 1 SELECT id, v FROM tab WHERE hasToken(s, 'error');
-- on 26.5/26.6/26.7 it does NOT: the ORDER BY ... LIMIT plan drops the virtual
-- column and reads + tokenizes the whole `s` column instead
EXPLAIN actions = 1 SELECT id, v FROM tab WHERE hasToken(s, 'error') ORDER BY v DESC, id LIMIT 10;
-- column order decides it: `SELECT v, id` keeps the index, `SELECT id, v` loses it
EXPLAIN actions = 1 SELECT v, id FROM tab WHERE hasToken(s, 'error') ORDER BY v DESC, id LIMIT 10;Results:
Backport the fix to CC component owner: @CurtizJ @ahmadov Analysis metadata
Introducing change: not identified
|
Backport #115586 to 26.6: Fix lost text index optimization for queries with ORDER BY ... LIMIT
…s with ORDER BY ... LIMIT
Backport #115586 to 26.7: Fix lost text index optimization for queries with ORDER BY ... LIMIT
…for queries with ORDER BY ... LIMIT
26.6 gained #115586 (`1cc90fa8b08`) after this backport branch was cut, so its `tryMergeExpressions` block collided with the loop #113154 restructures. Resolved to master's combined form: hoist the merge into a `walk_begin` iterator and keep the "parent is not a filter" LOG_TRACE inside the walk. The resolved `processAndOptimizeTextIndexFunctions` is identical to the one on master at #113154's merge commit `5c856f8790c`, except for the `isPrewhereDeferredAfterFinal` arguments, which this backport already omits because 26.6 has no such method. The DistinctStep.h include is kept: `isRowScanPassThroughStep` needs it. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
26.7 gained #115586 after this backport branch was cut, so its `tryMergeExpressions` block collided with the loop #113154 restructures. Resolved to master's combined form: hoist the merge into a `walk_begin` iterator and keep the "parent is not a filter" LOG_TRACE inside the walk. The resolved `processAndOptimizeTextIndexFunctions` is identical to the one on master at #113154's merge commit `5c856f8790c`, except for the `isPrewhereDeferredAfterFinal` arguments, which this backport already omits because 26.7 has no such method. The DistinctStep.h include is kept: `isRowScanPassThroughStep` needs it. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Related: https://github.com/ClickHouse/clickhouse-private/issues/68580
Related: #93545
A query that filters on a text index and also has
ORDER BY ... LIMITcould stop using the index to answer the filter, and read and tokenize the whole text column instead:The two optimizations did not compose: the one that speeds up
ORDER BY ... LIMITreshaped theplan in a way the text index optimization no longer recognized, and it silently fell back to
reading the column. Nothing indicated this in the query plan or the logs, and the results stayed correct, but the query got much slower and used much more memory. On a full-text search benchmark over ~30M rows the affected queries took ~300 ms and ~500 MB instead of ~30 ms and
~15 MB.
Whether a query was affected depended on the order of the columns in
SELECT, which made it look arbitrary:SELECT v, id ... ORDER BY vwas fine whileSELECT id, v ... ORDER BY vwas not. All the settings involved are enabled by default.Both optimizations now apply together. A
TRACElog entry was also added for the remaining cases where the text index optimization cannot be used, so a silent fallback is visible in the logs.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a performance regression where a query combining a text index filter with
ORDER BY ... LIMITstopped answering the filter from the index and read the whole text column instead.Workflow [PR]
Sync PR [sync-upstream/pr/115586]
Version info
26.9.1.106(included in26.9and later)26.8.1.2026,26.7.6.53,26.6.4.61