Skip to content

[Bug]: utf8mb4_0900_ai_ci string comparison and REGEXP are case-sensitive #25239

Closed as not planned

Description

@Ariznawlll

Environment

  • Branch: latest main
  • Commit: 33e96877604ad4b847ea7d5c55eb09429de1a5b6
  • MySQL oracle: 8.0.45
  • MO: 8.0.30-MatrixOne-v1.3.0

Steps to Reproduce

set names utf8mb4 collate utf8mb4_0900_ai_ci;
select @@character_set_connection as cs, @@collation_connection as coll;
select 'a' = 'A' as eq_case,
       'a ' = 'a' as eq_trailing,
       'abc' regexp 'A' as regexp_case;

MySQL Result

cs      coll
utf8mb4 utf8mb4_0900_ai_ci

eq_case eq_trailing regexp_case
1       0           1

MatrixOne Result

cs      coll
utf8mb4 default

eq_case eq_trailing regexp_case
0       0           0

Expected Behavior

For a case-insensitive collation such as utf8mb4_0900_ai_ci, string equality and REGEXP matching should follow MySQL's case-insensitive comparison semantics. The trailing-space equality result 0 is already aligned for this collation.

Activity

  1. added
    kind/bug
    severity/s1
    on Jun 30, 2026
  2. added theissue type on Jun 30, 2026
  3. modified the milestones: MO-2507, MO-202607 on Jun 30, 2026
  4. Ariznawlll commented on Jul 1, 2026

    @Ariznawlll
    CollaboratorAuthor

    Additional validation on latest main (200bfa7e0efb) shows the same collation issue also affects explicit COLLATE expressions beyond scalar equality / REGEXP.

    MySQL oracle:

    select
      _utf8mb4'a' collate utf8mb4_bin = _utf8mb4'A' collate utf8mb4_bin as bin_eq_case,
      _utf8mb4'a' collate utf8mb4_general_ci = _utf8mb4'A' collate utf8mb4_general_ci as ci_eq_case,
      _utf8mb4'a ' collate utf8mb4_bin = _utf8mb4'a' collate utf8mb4_bin as bin_eq_trailing,
      _utf8mb4'a ' collate utf8mb4_general_ci = _utf8mb4'a' collate utf8mb4_general_ci as ci_eq_trailing;
    
    select
      strcmp(_utf8mb4'a' collate utf8mb4_bin, _utf8mb4'A' collate utf8mb4_bin) as strcmp_bin_case,
      strcmp(_utf8mb4'a' collate utf8mb4_general_ci, _utf8mb4'A' collate utf8mb4_general_ci) as strcmp_ci_case,
      strcmp(_utf8mb4'a ' collate utf8mb4_general_ci, _utf8mb4'a' collate utf8mb4_general_ci) as strcmp_ci_trailing;

    MySQL returns:

    bin_eq_case  ci_eq_case  bin_eq_trailing  ci_eq_trailing
    0            1           1                1
    
    strcmp_bin_case  strcmp_ci_case  strcmp_ci_trailing
    1                0               0
    

    MO returns:

    bin_eq_case  ci_eq_case  bin_eq_trailing  ci_eq_trailing
    0            0           0                0
    
    strcmp_bin_case  strcmp_ci_case  strcmp_ci_trailing
    1                1               1
    

    Table-path checks show the same root behavior:

    create table t_collate_expr (
      id int primary key,
      s varchar(20) character set utf8mb4 collate utf8mb4_bin
    );
    
    insert into t_collate_expr values
      (1, 'apple'), (2, 'Apple'), (3, 'APPLE'),
      (4, 'banana'), (5, 'Banana'), (6, 'BANANA');
    
    select id, s
    from t_collate_expr
    where s collate utf8mb4_general_ci = _utf8mb4'apple'
    order by id;
    
    select distinct s collate utf8mb4_general_ci as ci_s
    from t_collate_expr
    order by ci_s;
    
    select s collate utf8mb4_general_ci as ci_s, count(*) as c
    from t_collate_expr
    group by ci_s
    order by ci_s;

    MySQL collapses case variants under utf8mb4_general_ci, while MO keeps them distinct. I am not opening a separate issue for this because it appears to be the same collation-semantic gap tracked here.

  5. added
    ai-heavy
    on Jul 1, 2026
  6. daviszhen commented on Aug 3, 2026

    @daviszhen
    Contributor

    不需要为了这三条“纯字符串字面量” SQL 一次性完整实现所有 collation;但也绝不能只补 SET NAMES 或用 strings.EqualFold 打补丁。需要的是一个覆盖 utf8mb4_0900_ai_ci 的端到端最小 collation 语义链路。

    即使做了, 还是半成品. 还不如完整支持呢

  7. removed
    severity/s1
    on Aug 6, 2026
  8. Ariznawlll commented on Oct 14, 2026

    @Ariznawlll
    CollaboratorAuthor

    补充 REGEXP_LIKE/INSTR/SUBSTR/REPLACE 默认大小写语义。MatrixOne 本地 runtime 8.0.30-MatrixOne-v1.3.0(source commit 2ce4e58af6f03b943ee288ffad81012766cf830a)与隔离 MySQL 8.0.45 对照,3 次独立执行一致:

    SELECT REGEXP_LIKE('Abc','^a'),
           REGEXP_LIKE('Abc','^a','c'),
           REGEXP_LIKE('Abc','^a','i'),
           REGEXP_INSTR('Abc','^a'),
           REGEXP_SUBSTR('Abc','^a'),
           REGEXP_REPLACE('Abc','^a','X');
    引擎 默认 REGEXP_LIKE 显式 c 显式 i 默认 REGEXP_INSTR 默认 REGEXP_SUBSTR 默认 REGEXP_REPLACE
    MySQL utf8mb4_0900_ai_ci 1 0 1 1 A Xbc
    MO (@@collation_connection=default) 0 0 1 0 NULL Abc

    显式大小写控制 c/i 两端一致;差异集中在未指定 match type 时,MySQL 从默认非二进制 collation 得到不区分大小写匹配,MO 默认按大小写敏感匹配。REGEXP_LIKE、REGEXP_INSTR、REGEXP_SUBSTR、REGEXP_REPLACE 是同一 collation/default-match-type 缺口的不同入口,归入本 issue,不另开重复 issue。

    MySQL 文档:Regular Expressions。

  9. XuPeng-SH commented on Oct 23, 2026

    @XuPeng-SH
    Contributor

    Closing as consolidated under #25096. This report adds the session SET NAMES/connection-collation and default REGEXP_* cases to the existing end-to-end collation workstream. Those execution paths remain separate regression cases; this is administrative tracking consolidation, not a fix. The original reproductions and results remain here.

  10. added
    duplicate
    on Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

ai-heavydeferredduplicatekind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions