Repository navigation
Use text index for LIKE/ILIKE with ESCAPE - #105848
Conversation
Pre-PR Validation Gatea) Deterministic repro? Yes. Without the fix, on commit b) Root cause explained? Yes. c) Fix matches root cause? Yes. Apply the same d) Test intent preserved? / New tests added? New test e) Both directions demonstrated?
f) Fix is general, not a narrow patch? The fix handles both Session: cron:clickhouse-ci-task-worker:20260526-113000. |
|
cc @CurtizJ @ahmadov — could you review this? It fills a coverage gap so that |
|
@PedroTadim Yes, confirmed. |
|
Done in 50fb54c ( Pre-PR validation gate for this follow-up commit:
|
|
Workflow [PR], commit [82d2ce3] Summary: ❌
AI ReviewSummaryThis PR restores Final Verdict
LLVM Coverage Report |
|
@groeneai the arm tidy build failed, fix it |
|
Fixed in 163fbaa. clang-tidy |
Per clickhouse-gh[bot] review on PR ClickHouse#105848: `KeyCondition::atom_map` only contains `like` and `notLike`. The check `if (atom_map.find(func_name) == std::end(atom_map)) return false;` at the top of `extractAtomFromTree` rejects `ilike` and `notILike` before they can reach the new 3-arg rewrite branch, so listing them in the branch's condition and comment was misleading. Drop `ilike`/`notILike` from the condition and rewrite the comment to document the limitation: case-insensitive forms fall back to row-level evaluation, same as the existing 2-arg behavior. The text index path (test 04277) still covers all four forms because `MergeTreeIndexConditionText::traverseAtomNode` has its own dispatch. Test 04292 (primary key) and its reference are unchanged because they never exercised an ILIKE case. This is a no-op refactor: cleans up dead branches in the source and the test header. Extending primary-key pruning to `ilike`/`notILike` would require new atom_map entries with case-folding-aware prefix extraction and belongs in a separate PR.
Per inline review on PR ClickHouse#105848: let the exception propagate from `likePatternWithCustomEscapeToLikePattern` in both `KeyCondition::extractAtomFromTree` and `MergeTreeIndexConditionText::traverseAtomNode` instead of swallowing it and bailing out. Matches what row-level evaluation in `FunctionsStringSearch.h` does and surfaces an invalid escape sequence at query planning time instead of execution time.
|
@alexey-milovidov done in f21f410. Removed the try/catch around Verified locally with
Pre-PR validation gate (6/6):
session: |
CI ledger — covered SHA
|
| Failure | Class | Disposition |
|---|---|---|
BuzzHouse (amd_debug) — Logical error: 'Inconsistent AST formatting (STID 1941-1bfa)' |
Chronic trunk fuzzer bug | 81 distinct PRs hit it in 30d, 9 master hits. Crash query is INSERT INTO ... url('https://localhost:8443/...') with Enum16 identifiers, entirely unrelated to LIKE/ILIKE/ESCAPE. Tracked under issue #106358 and our internal task for STID 1941-1bfa (40+ PRs in 90d, 4 trigger shapes). Partial fix in PR #104991 merged 2026-05-31; tail still surfacing. |
Performance Comparison (arm_release, master_head, 6/6) |
Chronic perf-noise | Job-level failure (check_status = failure, no per-test FAIL rows). 30+ unrelated PRs hit it in 30d (#104976×12, #104591×9, #101796×5, etc.); only 1 master hit in 30d. Slower/unstable test basket rotates across runs (logical_functions_medium, min_max_index_with_cast, optimize_trivial_group_by_limit, uniqExactIf), no consistent regressing test. Affected tests are entirely unrelated to LIKE-ESCAPE / text index / KeyCondition changes in this PR. |
No PR-caused failures on this HEAD.
Awaiting reviewer re-review (@CurtizJ or @ahmadov as suggested 2026-05-26).
Session id: cron:our-pr-ci-monitor:20260604-080000
|
Addressed the unknown-backslash-escape wrong-results concern in commit The 3-argument Fix: added Pre-PR validation gate
Session id: cron:clickhouse-worker-slot-1:20260610-130800 |
Pre-PR validation gateFollow-up commit 79faafb (extends the unknown-backslash-escape decline to the 2-argument LIKE paths, per the bot review on
Session id: cron:clickhouse-worker-slot-7:20260610-151400 |
Pre-PR validation gate (map LIKE backslash decline, 4f9c52f)
Session id: cron:clickhouse-worker-slot-4:20260610-220500 |
|
CI finished on AST fuzzer (amd_debug):
(cron:our-pr-ci-monitor:20260619-003000) |
|
Re-merged The only red was the AST fuzzer (amd_debug) That bug was fixed on The merge is clean: master's |
Without the ESCAPE clause the predicate matches no rows; the index keeps the second part as a candidate, which is what produces the 16-granule plan. Say that instead of claiming a row match.
… tests
Extends the comment cleanup to the test files. Removes the per-SET rationale
comments, the no-parallel-replicas tag rationale, the fixture granularity note
and the two comments restating what the adjacent query already says.
Comments only. Every executed statement is byte-identical to the previous
revision (verified by stripping comment lines from both and comparing), the
tests do not run in `-- { echo }` mode, and none of the three `.reference`
files changed.
Kept the byte-level clarifications spelling out how many backslashes a SQL
literal denotes, and the note recording that the `literal 50 discount token`
row is what makes the 16-of-48-granule arm non-vacuous: a reader cannot
recover either from the code, and the latter is the only record that the arm
can redden.
Facts moved here rather than into a comment: `use_query_condition_cache = 0`
is set because the query condition cache would answer a repeated query
without reporting granule counts; `no-parallel-replicas` is set because
`EXPLAIN indexes = 1` prints the local primary-key analysis and a
parallel-replicas plan changes the output; the 04292 fixture uses
`index_granularity = 8192` so its five rows land in one granule and the
primary-key ranges read 1/1.
|
Done in b916a23. Removed the per- You are right that my earlier pass left this category behind. My 18:29 reply said I had cleaned Two comments deliberately stay. The byte-level ones spelling out how many backslashes a SQL literal denotes, because Comments only, so no re-approval needed for behavior. Every executed statement is byte-identical to the previous revision (checked by stripping comment lines from both revisions and comparing), the tests do not use |
CI finish ledger - b916a23Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
The same arm64 mirror burst hit true master at least 5 times plus 12 other PR carriers in the Every functional, integration, stress, fuzzer and performance check on this head is green. Session id: cron:our-pr-ci-monitor:20260826-043752 |
ahmadov
left a comment
There was a problem hiding this comment.
Also, try to merge the latest origin/master into it again.
| -- | ||
| -- Issue: https://github.com/ClickHouse/ClickHouse/issues/105885 | ||
|
|
||
| SET enable_analyzer = 1; |
There was a problem hiding this comment.
let's add SET use_query_condition_cache = 0;
There was a problem hiding this comment.
Added right after SET enable_analyzer = 1; in 9f5bb91.
04292 was the only one of the three files without the pin. The setting defaults to 1 and tests/clickhouse-test randomizes it per run, so roughly half of the runs had the cache enabled while these arms assert Parts:/Granules: counts. .reference is unchanged.
Per review. 04292 was the one file in the trio without the pin, while its two siblings already carry it. The setting defaults to 1 and is randomized per run by `tests/clickhouse-test` (`"use_query_condition_cache": lambda: random.randint(0, 1)`), so without the pin the cache is enabled in about half of all CI runs. Two of the arms fold to the identical condition `(s in ['abc%', 'abc%'])` on the same table, one through the operator form and one through `like(s, pattern, escape)`, which is exactly the shape a cache entry can answer, and the arms assert `Parts:`/`Granules:` counts. Test file only, no behavior change.
|
Both asks are in 9f5bb91.
Merged the latest master ( |
CI finish ledger - 9f5bb91Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task whose
CI is fully finished at this head: 175 unique check runs, 0 incomplete, one parent workflow run Neither red is caused by this PR, whose diff is confined to STID 1941-26fa is a STID 2945-3346 aborts in Session id: cron:our-pr-ci-monitor:20260827-190000 |
|
@groeneai merge the latest origin/master again into this branch and fix conflict. |
Resolves one conflict in MergeTreeIndexConditionText.cpp, where master's explicit-tokenizer overload (ClickHouse#115348) and this branch's LIKE ESCAPE fold both claim the three-argument branch of traverseAtomNode. Both are kept. The LIKE ESCAPE case is checked first because it is gated on the function name and returns on every path; tokenizerArgumentMatchesIndex accepts only hasAnyTokens, hasAllTokens and hasPhrase, so with the order reversed it would reject like/ilike before the fold ran and the index would stop answering LIKE ... ESCAPE. Everything else with three arguments still goes through master's tokenizer check. Merged master commit: 595bd75
canAnswerFunctionNode sends every three-child function node through tokenizerArgumentMatchesIndex, which accepts only hasAnyTokens, hasAllTokens and hasPhrase. A folded `like`/`ilike` atom therefore built a search query and had it discarded again in selectConditions, so `LIKE ... ESCAPE` got granule pruning but not the direct-read rewrite its two-argument form gets. Measured on this tree before the change, with the two-argument form as a live-channel control: s LIKE '%foo%' Prewhere filter column: s LIKE '%foo%' AND __text_index_idx_s_like_eca00f43... like(s, '%foo%', '#') Filter column: like(s, '%foo%', '#') and after it both forms produce the same __text_index_idx_s_like_eca00f43... column, which is also evidence the fold is exact. A three-argument hasAnyTokens whose tokenizer does not match the index is still rejected, so the tokenizer check keeps its meaning. Safe because none of needApplyTokenizer, needApplyPreprocessor or needApplyPostprocessor names `like`, so applyTransforms returns before the point where a third argument would be overwritten with a tokenizer description. The new arm in 04277 asserts the column for the ESCAPE form with the two-argument form beside it; turning the two plan settings off in that arm flips its result from 1 to 0, so it can fail.
|
Merged the latest The conflict is a single one, in Resolving it textually was not enough. The second commit exempts
Behaviour for the two-argument forms is unchanged from the tree you approved. The two commits are going up to the branch now. |
CI finish ledger - 2472b21CI is fully finished at this commit. One job of 170 failed, it has an owner, and it is not caused by this diff: the change touches three files under
Session id: cron:our-pr-ci-monitor:20260901-050000 |
…ape_bug105885 The leading 04292_105885_ read like two test numbers. The issue number now follows the description, as bug105885.
CI finish ledger - 82d2ce3Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task whose
Session id: cron:our-pr-ci-monitor:20260903-030000 |
7e7382c
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
LIKE ... ESCAPE 'c'andILIKE ... ESCAPE 'c'predicates now useTYPE textskip indexes to prune granules, andLIKE ... ESCAPE 'c'additionally uses thengrambf_v1,tokenbf_v1andsparse_gramsskip indexes, plus the primary key when the column is in the sorting key, instead of falling back to a full scan.NOT LIKE ... ESCAPE 'c'is recognized by the bloom-filter skip indexes and the primary key, matching what plainNOT LIKEalready does. TheTYPE textindex does not supportNOT LIKE, with or without anESCAPEclause.Documentation entry for user-facing changes
Description
Closes #105885. Follow-up to #99774, which added the
ESCAPEclause.... WHERE col LIKE pattern ESCAPE 'c'silently bypassed the primary key, theTYPE textindex and the bloom-filter text indexes (ngrambf_v1,tokenbf_v1,sparse_grams), full-scanning even when such an index was defined.Root cause:
LIKE pattern ESCAPE 'c'parses into a 3-argument calllike(col, pattern, escape_char), andMergeTreeIndexConditionText::traverseAtomNode,MergeTreeConditionBloomFilterText::extractAtomFromTreeandKeyCondition::extractAtomFromTreeaccepted only 2-argument forms, so the 3-argument call was rejected before reaching the LIKE handler. Results were always correct, sinceFunctionsStringSearch::executeImplalready folds the custom escape withlikePatternWithCustomEscapeToLikePattern; only performance was affected.This applies the same fold at index-analysis time and dispatches through the existing 2-argument handler:
like/ilikefor the text index,like/notLikefor the bloom-filter indexes and the primary key (ilike/notILikeare absent fromatom_mapand keep falling back to row-level evaluation, as with 2 arguments). The pattern and the escape argument must both be constant strings, the escape a single ASCII byte; anything else declines the atom. The ASCII check mirrors the execution layer, so an invalid escape byte raises at planning time instead of being dropped by a downstream optimization.Rebased onto #115634, now merged: the unknown-backslash-escape guard this PR used to carry is on master, so the diff here is the ESCAPE fold only.
Validation, one binary per arm with Build-IDs asserted:
04277_text_index_function_like_escape,04292_105885_primary_key_like_escapeand04351_bloom_filter_text_index_like_escapeall fail on master and pass with this change.Workflow [PR]
Sync PR [sync-upstream/pr/105848]