Repository navigation
Text index: accept arbitrary LIKE/ILIKE patterns for the array tokenizer - #115649
Conversation
|
Workflow [PR], commit [ce14c29] Summary: ✅
AI ReviewSummaryThis PR teaches the text-index Findings❌ Blockers
💡 Nits
Tests
Final VerdictRequest changes. LLVM Coverage ReportMeasured on commit ce14c29.
Changed lines: Changed C/C++ lines covered: 59/59 (100.00%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units32 translation units recompiled, 323 s compile time in total, 32 of them have a recent master baseline. |
Can the |
|
Preview deployment for your docs. Learn more about Mintlify Previews.
|
@EmeraldShift, yes that is the end goal of this PR. I'll add support for those functions as well. |
|
depends on #116554 to support |
The `array` tokenizer stores the whole value as a single token, so a pattern matches a token exactly when it matches the value. Any pattern is therefore answered by a dictionary scan instead of a full scan. Previously only `%needle%` with an alphanumeric needle qualified. Closes #114641.
f88d83e to
f2d625a
Compare
This comment was marked as low quality.
This comment was marked as low quality.
|
📊 Cloud Performance Report ✅ AI verdict: This PR extends the text-index dictionary-scan optimization to accept arbitrary LIKE/ILIKE patterns for the clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
This comment was marked as low quality.
This comment was marked as low quality.
| @@ -1449,7 +1549,7 @@ bool MergeTreeIndexConditionText::traverseFunctionNode( | |||
| return false; | |||
|
|
|||
| const auto & like_pattern = value_field.safeGet<String>(); | |||
| auto patterns = stringLikeToPatterns(value_field, /*case_insensitive=*/ true); | |||
| auto patterns = stringLikeToPatterns(value_field, /*case_insensitive=*/ true, /*allow_arbitrary_patterns=*/ affix_patterns_allowed); | |||
There was a problem hiding this comment.
This widens the existing ILIKE + UTF-8 case-mapping bug from '%needle%' to the new array-tokenizer shapes. preprocessor->isLowerOrUpper() still admits lowerUTF8 / upperUTF8, but #116970 shows those transforms are not semantics-preserving for raw ILIKE: for example, lowerUTF8('abKoop zzz') becomes abkoop zzz, so s ILIKE 'abkoo%' is an exact index hit even though the row-level predicate is false.
Because the array tokenizer makes this path Exact, the original predicate is removed and the phantom row becomes final. Please either restrict this exact path to ASCII lower / upper, or keep lowerUTF8 / upperUTF8 in hint mode until #116970 is fixed.
Issue ClickHouse#118197 (duplicate ClickHouse#118037): on a `text(tokenizer = array)` index, `startsWith`/`endsWith` are answered by a dictionary scan with the LIKE pattern `needle%` / `%needle` in Exact mode, so the original predicate is dropped. Before ClickHouse#115649 the needle went into the pattern unescaped, and a `%` in it acted as a wildcard: `startsWith(tag, 'foobar%')` returned every row starting with `foobar`. ClickHouse#115649 escapes `%`, `_` and `\` on master, but no test pinned it: the only such case, `startsWith(name, '100%')` in 02346_text_index_function_like_array_patterns, returns the same rows with or without the escaping. The new test covers `%` next to the added wildcard and at the far edge, `LIKE 'foobar\%%'` (rewritten to `startsWith` by `optimize_rewrite_like_perfect_affix`), `_` and a trailing backslash, in both directions. Each indexed query is compared with `use_skip_indexes = 0`, and EXPLAIN checks that the text index answers it alone. Validated: matches the reference on master; with `escapeForLikePattern` removed from the affix branch all nine indexed results change (the last one throws CANNOT_PARSE_ESCAPE_SEQUENCE); on 26.8.21.12, which has the ClickHouse#114728 backport without ClickHouse#115649, the five `%` cases return extra rows. Co-Authored-By: Claude Opus 5.5 <[email protected]>

The
arraytokenizer stores the whole value as a single token, so a pattern matches a token exactly when it matches the value. Any pattern is therefore answered by a dictionary scan instead of a full scan. Previously only%needle%with an alphanumeric needle qualified.Closes #114641.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Qualify arbitrary LIKE/ILIKE patterns for dictionary scan when a text index is built via the
arraytokenizer.Workflow [PR]
Sync PR [sync-upstream/pr/115649]