Skip to content

Revert "Fix positionCaseInsensitiveUTF8 giving different results for constant and column arguments" - #122634

Merged
rschu1ze merged 1 commit into
masterfrom
revert-122113-fix-position-case-insensitive-utf8-constant
Sep 28, 2026
Merged

rschu1ze merged 1 commit into
masterfrom
revert-122113-fix-position-case-insensitive-utf8-constant

Conversation

@rschu1ze

@rschu1ze rschu1ze commented Sep 28, 2026 •

Copy link
Copy Markdown
Member

@clickhouse-gh

clickhouse-gh Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [b83f523]

Summary: ✅

@clickhouse-gh clickhouse-gh Bot added pr-not-for-changelog This PR should not be mentioned in the changelog comp-regular-function Regular scalar functions: string processing, data conversion, arithmetic, math, comparison, condi... labels Sep 28, 2026
@rschu1ze
rschu1ze enabled auto-merge September 28, 2026 10:36
@rschu1ze
rschu1ze added this pull request to the merge queue Sep 28, 2026
Merged via the queue into master with commit 3f04f14 Sep 28, 2026
149 checks passed
@rschu1ze
rschu1ze deleted the revert-122113-fix-position-case-insensitive-utf8-constant branch September 28, 2026 11:34
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 28, 2026
shankar-iyer pushed a commit to shankar-iyer/ClickHouse that referenced this pull request Oct 21, 2026
…, 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-regular-function Regular scalar functions: string processing, data conversion, arithmetic, math, comparison, condi... pr-not-for-changelog This PR should not be mentioned in the changelog pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants