Repository navigation
Fix positionCaseInsensitiveUTF8 giving different results for constant and column arguments - #122113
Conversation
For a constant haystack the function lowercased both strings and used std::string::find, while a column is searched with UTF8CaseInsensitiveStringSearcher. The two disagree when a character's lowercase has a different UTF-8 length, e.g. the Kelvin sign U+212A and 'k': the constant returned 1, the column 0. A constant now uses the same searcher. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Workflow [PR], commit [e98703b] Summary: ✅
AI ReviewSummaryThis PR routes the constant-evaluation path of Final Verdict
LLVM Coverage ReportMeasured on commit e98703b.
Changed lines: Changed C/C++ lines covered: 25/25 (100.00%) · Uncovered code |
For a column, positionCaseInsensitiveUTF8 treats a match whose needle bytes run past the end of the row as not found. The constant path did not, so 'Ⱥ' (2 bytes) against the needle 'ⱥ' (3 bytes) gave 1 for a constant and 0 for a column. The constant path now uses the same rule. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e column positionCaseInsensitiveUTF8 with a constant needle treats a match whose needle bytes run past the end of the row as not found. With a needle column it did not, so 'Ⱥ' (2 bytes) against 'ⱥ' (3 bytes) gave 0 for a constant needle and 1 for a needle column. Both needle-column paths now use the same rule. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A haystack 'k' against a Kelvin sign needle must give 0 for every constant/column combination, like the reverse case in 05258. Co-Authored-By: Claude Opus 5.5 <[email protected]>
positionCaseInsensitiveUTF8 on a constant stringpositionCaseInsensitiveUTF8 giving different results for constant and column arguments
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units31 translation units recompiled, 105 s compile time in total, 31 of them have a recent master baseline. |
|
Should be ready for review. |
| @@ -0,0 +1,8 @@ | |||
| -- A constant haystack must give the same result as a column. | |||
|
|
|||
| SELECT 'Kelvin sign', positionCaseInsensitiveUTF8(unhex('E284AA'), 'k'), positionCaseInsensitiveUTF8(materialize(unhex('E284AA')), 'k'); | |||
There was a problem hiding this comment.
I think the test can be rewritten without hex.
| -- A needle column must give the same result as a constant needle. | ||
| -- The lowercase of 'Ⱥ' (2 bytes) is 'ⱥ' (3 bytes), so the needle does not fit in the haystack. | ||
|
|
||
| SELECT 'Ⱥ and ⱥ', positionCaseInsensitiveUTF8(materialize('Ⱥ'), 'ⱥ'), positionCaseInsensitiveUTF8(materialize('Ⱥ'), materialize('ⱥ')), positionCaseInsensitiveUTF8('Ⱥ', materialize('ⱥ')); |
There was a problem hiding this comment.
Could you please merge this test into the other one?
| @@ -0,0 +1,9 @@ | |||
| -- A needle column must give the same result as a constant needle. | |||
| -- The lowercase of 'Ⱥ' (2 bytes) is 'ⱥ' (3 bytes), so the needle does not fit in the haystack. | |||
There was a problem hiding this comment.
L. 2 is confusing, let's remove it.
| res = data.find(needle, start_byte); | ||
| if (res == std::string::npos) | ||
|
|
||
| /// Search like a column does: a match whose needle bytes run past the end of the string is not a match. |
There was a problem hiding this comment.
"like a column does" --> please reference a function here, I believe you mean vectorVector but not sure.
Also, it looks like this comment should go before l. 306
| if (res == std::string::npos) | ||
|
|
||
| /// Search like a column does: a match whose needle bytes run past the end of the string is not a match. | ||
| auto searcher = Impl::createSearcherInSmallHaystack(needle.data(), needle.size()); |
There was a problem hiding this comment.
The changes in l. 301-309 look actually unrelated.
| /// `res_null` serves as an output parameter for implementing an XYZOrNull variant. | ||
| chassert(!res_null); | ||
|
|
||
| Impl::toLowerIfNeed(data); |
There was a problem hiding this comment.
We no longer lower the data and needle. How do we still ensure that matching is case-insensitive?
|
@valerypetrov I needed to revert, sorry. But you're welcome to re-submit the PR if it addresses
Thanks! |
Edited by the nightly changelog CI job following .claude/skills/edit-changelog/SKILL.md. Changelog-revert: 122634 122113 Revert "Fix `positionCaseInsensitiveUTF8` giving different results for constant and column arguments" Changelog-deleted-entry: 122113 [Bug Fix (user-visible misbehavior in an official stable release)] [section] * Fix `positionCaseInsensitiveUTF8` returning different results depending on whether its arguments are constant, for characters whose lowercase has a different length in bytes, such as the Kelvin sign. [#122113](#122113) ([Valery Petrov](https://github.com/valerypetrov)).
…, tail length and row layout Re-submission of ClickHouse#122113, which was reverted in ClickHouse#122634, addressing the review comments and the follow-up issues ClickHouse#122594 and ClickHouse#122595. `positionCaseInsensitiveUTF8`, `countSubstringsCaseInsensitiveUTF8` and `ILIKE` gave different results depending on which arguments were constant, on how many bytes followed a match, and on the neighbouring rows of a block. - A case-insensitive UTF-8 match can cover a different number of haystack bytes than the needle has (`ẞ` and `ß`, `Ⱥ` and `ⱥ`). The row boundary checks in `PositionImpl`, `CountSubstringsImpl` and `MatchImpl` compared `needle.size()` with the end of the row, so a match could continue into the next row, or be rejected although it fits. `countSubstrings*` also advanced by `needle.size()` after a match. Add `matchEnd` to the searchers, which returns the end of the haystack part that a match covers, and use it at these places. The exact length searchers keep a plain pointer comparison. - The SIMD pre-checks accepted only the lower and upper case encodings of the needle, while the scalar comparison accepted every code point with the same `Poco::Unicode::toLower`, so a match could depend on the number of bytes after it. Make both use one rule, `utf8CaseFold`: `Poco::Unicode::toLower`, except that KELVIN SIGN, ANGSTROM SIGN, OHM SIGN and GREEK CAPITAL LETTER THETA SYMBOL match only themselves. Matching them to `k`, `å`, `ω` and `θ` is not possible without losing the SIMD and `Volnitsky` fast paths for every needle that contains one of these letters, which was measured to be up to 5 times slower. - Fix the first-byte and SIMD filters for the Greek `ι` and `μ`, whose `Poco::Unicode::toUpper` is a different code point, so that `Ι` and `Μ` were never found in a long haystack. - Route the constant haystack and constant needle case through the same searcher, and remove `toLowerIfNeed`. - Skip the decoding for two ASCII bytes in the scalar comparison. `ILIKE` patterns that go through `re2` keep the folding of `re2`. Add the test `05331_position_case_insensitive_utf8_constness`. In `02346_text_index_ilike_utf8_case_folding`, a KELVIN SIGN no longer matches `ILIKE '%zzzk%'`. Closes: ClickHouse#122594 Closes: ClickHouse#122595 Related: ClickHouse#122113 Related: ClickHouse#122634 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
positionCaseInsensitiveUTF8gave different results for the same strings depending on which arguments were constant. It happens for characters whose lowercase has a different length in bytes, for example the Kelvin signK(U+212A, 3 bytes) andk, orȺ(2 bytes) andⱥ(3 bytes).All four combinations now use the same searcher and the same rule as a haystack column with a constant needle: a match whose needle bytes run past the end of the string is not a match.
kk, Kelvin signȺ,ⱥThe results are from local builds of master and of this PR.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix
positionCaseInsensitiveUTF8returning different results depending on whether its arguments are constant, for characters whose lowercase has a different length in bytes, such as the Kelvin sign.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/122113]
Version info
26.10.1.852-master(included in26.10and later)