Repository navigation
Text index: fix wrong result when a LIKE pattern contains an invalid backslash escape - #115634
Conversation
…backslash escape The index-side tokenizers drop a backslash which does not form a valid LIKE escape sequence, while row-level matching keeps it as a literal, so the index searched for a token the value never produced and pruned granules holding matching rows. Index analysis now declines such patterns and falls back to row-level evaluation. Fixes #115578.
|
Workflow [PR], commit [35ce6ac] Summary: ✅
AI ReviewSummaryThis PR stops Final Verdict
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 33/33 (100.00%) · 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 units85 translation units recompiled, 345 s compile time in total, 85 of them have a recent master baseline. |
|
|
||
| /// `nextInStringLike` tokenizes such a pattern differently than row-level matching and could prune a | ||
| /// granule holding matching rows. No tokens means "cannot prune", as for a pattern like `LIKE '%a%'`. | ||
| if (likePatternHasUnknownBackslashEscape(pattern)) |
There was a problem hiding this comment.
Function likePatternHasUnknownBackslashEscape was added in this PR. I wonder how the scan path determines that a pattern is invalid? Is there some existing function that we can call?
There was a problem hiding this comment.
unfortunately, there was no an existing functionality for that. I double -checked again, but couldn't find it.
| return res; | ||
| } | ||
|
|
||
| bool likePatternHasUnknownBackslashEscape(std::string_view pattern) |
There was a problem hiding this comment.
That won't work with custom escape symbols. Will that be a problem?
There was a problem hiding this comment.
no, it shouldn't be a problem now. I'll handle that with #105848.
The unknown-backslash-escape correctness fix this PR used to carry landed separately in ClickHouse#115634, which is now on master: the guard sits in MergeTreeIndexConditionText::stringLikeToTokens and in MergeTreeConditionBloomFilterText::traverseTreeEquals, and 02346 covers it. Drop the plain two-argument backslash arms from 04292 and 04351 so this PR's tests only assert the ESCAPE handling it adds. The folded-pattern arms stay: they exercise the 3-argument fold, which is this PR's code. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Hello @ahmadov, is it possible to backport it to 26.8 lts? |
The index-side tokenizers drop a backslash which does not form a valid LIKE escape sequence,
while row-level matching keeps it as a literal, so the index searched for a token the value
never produced and pruned granules holding matching rows. Index analysis now declines such
patterns and falls back to row-level evaluation.
Fixes #115578.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix invalid backslash escape characters in text, tokenbf_v1 and ngrambf_v1 indexes.
Workflow [PR]
Sync PR [sync-upstream/pr/115634]
Version info
26.9.1.21(included in26.9and later)