Skip to content

[Bug]: utf8mb4_general_ci / utf8mb4_0900_ai_ci are fake case-insensitive #30680

Closed as duplicate

Description

@Ariznawlll

Bug or Feature Request

Bug

Description

The server claims utf8mb4_general_ci and utf8mb4_0900_ai_ci everywhere in metadata, but never applies their case-insensitive semantics to comparisons. Result: same database, same table, same column — constraint checking and querying answer differently, and values the catalog calls "case-insensitive" compare case-sensitively.

Evidence matrix (all on v3.x @ b24d1b3, fresh instance):

A. Literal comparison ignores the collation it itself reports

SELECT collation('Apple');          --> utf8mb4_general_ci   (metadata CI)
SELECT 'Apple' = 'apple';           --> 0                    (should be 1 under CI)
SET collation_connection = utf8mb4_general_ci;   -- accepted
SELECT @@collation_connection;      --> utf8mb4_general_ci
SELECT 'Apple' = 'apple';           --> STILL 0

B. utf8mb4_unicode_ci shows the intended behavior — proving the CI engine works, general_ci/0900_ai_ci are just not wired to it

CREATE TABLE ci2 (s VARCHAR(20) COLLATE utf8mb4_unicode_ci, UNIQUE KEY uk(s));
INSERT INTO ci2 VALUES ('Apple');
INSERT INTO ci2 VALUES ('apple');   --> ERROR 1062 Duplicate entry  (correct CI unique!)
SELECT * FROM ci2 WHERE s='apple';  --> matches 'Apple'          (correct CI compare)
JOIN on a.s=b.s with 'ApPlE'        --> matches                   (correct CI join)
SHOW CREATE TABLE ci2;              --> COLLATE utf8mb4_unicode_ci PRESERVED

But the same matrix under general_ci all fails:

CREATE TABLE ci (s VARCHAR(20) COLLATE utf8mb4_general_ci);
INSERT INTO ci VALUES ('Apple'),('APPLE'),('apple');
SELECT count(*) FROM ci WHERE s='apple';    --> 1   (should be 3)
ALTER TABLE ci ADD UNIQUE KEY uk_s(s);      -- accepts Apple/APPLE/apple concurrently (no 1062)
SHOW CREATE TABLE ci;                       -- COLLATE clause silently MISSING (unicode_ci keeps it)

C. utf8mb4_0900_ai_ci — the MySQL 8 default and MO's own default_collation_for_utf8mb4 — same story

SELECT 'Apple' = 'apple' collate utf8mb4_0900_ai_ci;  --> 0

D. SET collation_connection = utf8mb4_unicode_ci is REJECTED

ERROR 20301: invalid input: unsupported collation 'utf8mb4_unicode_ci'

…so the only collation that actually implements CI semantics is also the one that cannot be selected as a session default. The default (default) plus general_ci (accepted) are both inert.

Why this is a correctness/integrity issue, not cosmetics

  • Cross-engine seam: utf8mb4_general_ci columns accept case-duplicated unique keys silently. Data entered through such a key violates the (MySQL-standard) uniqueness the schema promises; the 1062 the user relies on never fires; tools migrating from MySQL with app-level expectations of CI uniqueness constraints get corrupted data.
  • Query/constraint disagreement: with unicode_ci columns the unique key says Apple==apple (rejects) while a hypothetical mixed-query pattern under general_ci says they differ — the same two strings compare differently depending on which code path (index maintenance vs expression evaluation) runs.
  • dump/restore fidelity: SHOW CREATE TABLE (and therefore mo-dump) drops the COLLATE utf8mb4_general_ci attribute (keeps the same attribute for unicode_ci) — a backup of a schema with general_ci columns silently changes collation on restore.
  • @@collation_connection default displays bare default, which is not a legal MySQL answer (should be a concrete collation name), compounding the ambiguity.

Source pointers (v3.x @ b24d1b3)

  • CI engine exists and handles: pkg/common/collation/general_ci.go has the full TiDB-derived utf8mb4_general_ci weight table (uppercase folds: 'a'(0x61)→0x41 etc.) — the capability is present but unused by the comparison path.
  • Domains enumerated in pkg/common/collation/key.go (UTF8MB4GeneralCI exists as a Domain), but pkg/container/types/types.go IsUnicodeCollation (line ~207) only recognizes CharsetUTF8MB4UnicodeCI/CharsetUTF8MB3UnicodeCI; applyTextCharsetToPlanType (pkg/sql/plan/build_util.go:583-593) only sets CollationVersion = CollationVersionV1 for those two, so general_ci/0900_ai_ci columns get KeyFormatLegacy (no transliteration) — the divergence starts here.
  • IsCaseInsensitiveCollation (types.go:203) — the very helper named for this property — also excludes general_ci, contradicting the catalog listing SHOW COLLATION provides (general_ci: Default YES, Compiled Yes).

Steps to Reproduce

  1. SELECT collation('Apple'), 'Apple'='apple'; → utf8mb4_general_ci | 0 (in one row; self-contradictory pair)
  2. SET collation_connection=utf8mb4_general_ci; SELECT 'Apple'='apple'; → still 0
  3. CREATE TABLE t(s VARCHAR(20) COLLATE utf8mb4_general_ci, UNIQUE KEY(s)); then insert Apple / apple → no 1062; SHOW CREATE TABLE t → COLLATE clause vanished
  4. Same with utf8mb4_unicode_ci → 1062 fires, COLLATE preserved (control)
  5. SET collation_connection=utf8mb4_unicode_ci; → ERROR unsupported collation (the only working CI is unsettable)

Expected behavior

  • utf8mb4_general_ci / utf8mb4_0900_ai_ci comparisons and unique keys must be case-insensitive (they're in SHOW COLLATION as the default!). If they're intentionally not supported as column collations, then: CREATE TABLE with those COLLATE must be rejected, SHOW COLLATION must not list them as default/compiled, collation() must stop reporting them, and SET collation_connection accepting them must stop — every metadata surface today lies about the actual behavior.
  • SHOW CREATE TABLE must round-trip whatever collate the table actually has, for every supported collation.
  • SET collation_connection = utf8mb4_unicode_ci must work (it's the only semantic CI engine actually implemented).

Versions

  • MatrixOne commit b24d1b3 (2026-10-16), v3.x dev, macOS 14.5 arm64

Additional context

Related earlier observation in #25096 (CI claims vs reality on UNIQUE with Abc/ABC/aBc) — that issue covered the CI unique-key aspect seen from version-scan; this one adds the expression-comparison level, the SHOW COLLATION/collation() metadata lying, the SHOW-CREATE attribute loss (dump fidelity), and the unicode_ci SET rejection, with source-level domain-mapping root cause.

Activity

  1. added
    kind/bug
    on Oct 20, 2026
  2. added this to the MO-202610 milestone on Oct 20, 2026
  3. XuPeng-SH commented on Oct 22, 2026

    @XuPeng-SH
    Contributor

    Consolidated into #25096. The current-main reproductions for general_ci/0900_ai_ci, SHOW CREATE, and collation_connection are retained there.

  4. Ariznawlll commented on Oct 22, 2026

    @Ariznawlll
    CollaboratorAuthor

    Additional divergence dimension worth tracking under this issue: PAD SPACE semantics are also missing for the fake-CI collations, with correctness ties to MySQL's most-deployed defaults (utf8mb3_general_ci is PAD SPACE).

    Setup identical on both servers (dev 3a1e42b430, MySQL 8.0.45):

    CREATE TABLE ps (id INT PRIMARY KEY, s VARCHAR(20));
    INSERT INTO ps VALUES (1,'ab'), (2,'ab  '), (3,'a b');
    
    SELECT id FROM ps WHERE s = 'ab';

    MatrixOne (default/utf8mb4_general_ci column): returns id=1 only.
    MySQL 8.0.45 (utf8mb3_general_ci, PAD SPACE): returns id=1, id=2.

    Full behavior matrix (MO | MySQL):

    form MatrixOne MySQL 8.0.45
    s = 'ab' 1 row 2 rows (PAD)
    s = 'ab ' 1 row (id=2) 2 rows (PAD)
    s <=> 'ab' 1 row 2 rows
    s IN ('ab','zz') 1 row 2 rows
    COUNT(DISTINCT s) 3 2 (pad collapse)
    GROUP BY s 3 groups ('ab','ab','a b') 2 groups
    s LIKE 'ab' (no wildcard) 1 row 1 row (LIKE ignores PAD, matches both)
    s LIKE 'ab%' 2 rows 2 rows ✓

    So the trailing-space-equality gap extends beyond case folding into the PAD SPACE compare/collapse family (equality, null-safe-equal, IN, DISTINCT, GROUP BY all affected).

    Cross-check that the real-CI engine path already implements PAD correctly — this issue's "only unicode_ci is real" observation holds for PAD too:

    CREATE TABLE u (id INT PRIMARY KEY, s VARCHAR(20) COLLATE utf8mb4_unicode_ci);
    INSERT INTO u VALUES (1,'ab'), (2,'ab  ');
    SELECT id FROM u WHERE s = 'ab';   -- MatrixOne: 2 rows ✓; COUNT(DISTINCT s) = 1 ✓ (collapses)

    i.e. utf8mb4_unicode_ci on MatrixOne gets PAD right; general_ci/0900_ai_ci/default do not apply either CI or PAD. Same root as this issue (collation version unassigned → binary compare), just documenting the additional PAD observable so the fix's regression matrix covers it. Note utf8mb4_0900_ai_ci is NO PAD in MySQL 8 — if MO keeps 0900 as fake-CI the eventual fix must NOT give it PAD — while general_ci-family and default must gain PAD to close this dimension.

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

Metadata

Metadata

Assignees

Labels

kind/bug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions