Skip to content

[Bug]: LIKE/REGEXP ignore column COLLATE (work on '=' but not LIKE even with utf8mb4_unicode_ci) #31179

Closed as not planned

Description

@Ariznawlll

Description

LIKE and REGEXP ignore the column's declared collation entirely. Even on a column explicitly created with COLLATE utf8mb4_unicode_ci — the collation that MO otherwise implements correctly for =, IN, and UNIQUE — pattern matching still compares case-sensitively. So on the same column, = is case-insensitive but LIKE is not.

This is distinct from the report that LIKE/REGEXP are case-sensitive under the default collation: here the collation is explicitly the one that otherwise works, and pattern matching still ignores it.

Environment

  • MatrixOne dev build (local multi-CN, main)
  • MySQL 8.0.45 control

Reproduction

CREATE TABLE uci2 (s VARCHAR(20) COLLATE utf8mb4_unicode_ci);
INSERT INTO uci2 VALUES ('Alice'), ('BOB');

-- equality and IN honor the collation:
SELECT COUNT(*) FROM uci2 WHERE s = 'alice';        -- MO: 1  ✓ (correct)
SELECT COUNT(*) FROM uci2 WHERE s IN ('alice');     -- MO: 1  ✓ (correct)

-- pattern matching does not:
SELECT COUNT(*) FROM uci2 WHERE s LIKE 'alice%';    -- MO: 0  ✗ (MySQL: 1)
SELECT COUNT(*) FROM uci2 WHERE s LIKE 'ALICE%';    -- MO: 0  ✗ (MySQL: 1)
SELECT COUNT(*) FROM uci2 WHERE s REGEXP '^alice';  -- MO: 0  ✗ (MySQL: 1)

MySQL returns 1 for all five.

The same split exists at literal level:

SELECT 'Apple' = 'apple' COLLATE utf8mb4_unicode_ci;   -- MO: 1  ✓
SELECT 'Apple' LIKE 'apple' COLLATE utf8mb4_unicode_ci; -- MO: 0  ✗

Root cause (diagnostic)

MO contains a working case-folding collation implementation (utf8mb4_unicode_ci behaves exactly like MySQL, including ß→ss, œ→oe, æ≠ae, and correct sort weights). But LIKE/REGEXP evaluation appears to bypass the collation layer: they take the raw string bytes and run a byte-wise matcher (and a case-sensitive regex engine), never consulting the column's collation.

By contrast =/IN/UNIQUE do consult it — which is why the same column mixes correct and incorrect behavior.

Impact

  • WHERE name LIKE 'prefix%' returns fewer rows than MySQL on any _ci column, including columns where the user explicitly chose a working collation. There is currently no way to get case-insensitive pattern matching — COLLATE at the column level does not help, so the behavior cannot be worked around in SQL.
  • Application search breaks: autocomplete, admin filters, and WHERE title LIKE '%term%' all become case-sensitive, diverging from MySQL behavior that applications were written against.
  • Self-contradictory predicates: WHERE s = 'alice' OR s LIKE 'Ali%' mixes two case rules; a single row can satisfy one and not the other, which is essentially impossible to reason about.
  • Index range scans diverge: LIKE 'prefix%' can be pushed into an index range, so the same query may return different rows depending on whether the index or a scan answers it.

Expected behavior

LIKE and REGEXP must honor the operand's collation, exactly as = and IN already do:

CREATE TABLE uci2 (s VARCHAR(20) COLLATE utf8mb4_unicode_ci);
INSERT INTO uci2 VALUES ('Alice');
SELECT COUNT(*) FROM uci2 WHERE s LIKE 'alice%';    -- 1
SELECT COUNT(*) FROM uci2 WHERE s REGEXP '^alice';  -- 1

Since utf8mb4_unicode_ci already routes correctly through the comparator for =, the fix is to route the LIKE/REGEXP matchers through the same collation-aware comparison instead of a byte-wise matcher. (_bin collations should of course keep the current byte-wise behavior.)

Activity

  1. added
    kind/bug
    on Oct 26, 2026
  2. added this to the MO-202610 milestone on Oct 26, 2026
  3. added theissue type on Oct 26, 2026
  4. added
    severity/s0
    ai-easy
    and removed on Oct 26, 2026
  5. XuPeng-SH commented on Oct 26, 2026

    @XuPeng-SH
    Contributor

    Tracking consolidated into #31175. The canonical issue retains this report’s full reproduction/discussion and independent acceptance requirements. This is administrative consolidation, not a claim that the defect is fixed. Original evidence remains preserved here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

ai-easykind/bugseverity/s0

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions