Skip to content

[Subtask]: C05 — Unify collation semantics across sort, aggregation, joins and shuffle #29484

Open

Description

@ck89119

Parent Issue

#29479 — C05

Detail of Subtask

Values equal in one effective domain must group, deduplicate and join consistently, and every ordering consumer must use that domain.

Scope

  • Cover ORDER BY/TopN/window ordering, MIN/MAX, DISTINCT/COUNT DISTINCT, GROUP BY, UNION DISTINCT and already-supported set operations.
  • Cover hash/merge joins, shuffle partitioning, local/merge aggregation and runtime filters.
  • Preserve original representatives while using canonical keys for comparison.

Acceptance criteria

  • Case, accents, padding, combining characters, NULL and empty strings form the correct equivalence classes.
  • Hash collisions still require equality checks; results contain original values, never opaque weights.
  • Single-CN and multi-CN results agree; equivalent keys cannot be split into incompatible shuffle partitions.
  • Temporary-key ownership, retained mpool accounting, spill/reload where applicable, cancellation and reset/reuse are tested.

Describe implementation you've considered

Reuse the resolved domain from C04, existing keys and PR #29056. SQL does not mandate one particular original representative for every equivalence class; do not invent such a test oracle.

Additional information

  • Prerequisites: C04: [Bug]: Default collation is binary/case-sensitive; explicit _ci collations are ignored #25096
  • Existing implementation references: fix(plan): validate catalog collation metadata before pruning #29056
  • Native SQL activation also requires the applicable C11 upgrade and C12 release gates.
  • Shared scope: five charset families and twelve canonical collations; latin1/latin1_* are explicitly unsupported for new requests.
  • Exclusions: partition tables, stored procedures, UDFs, warning count/text compatibility, utf16/utf32/gb18030 and other unlisted collations.
  • Existing product defaults are not changed incidentally. Preserve legacy objects; do not use accepted DDL or a backend-only test as end-to-end evidence.
  • This issue does not itself approve a production design, an open PR, or unverified CI evidence.

Activity

  1. self-assigned this
    on Sep 29, 2026
  2. Ariznawlll commented on Oct 14, 2026

    @Ariznawlll
    Collaborator

    补充 C05 的 JOIN 对照证据(固定 main commit 2ce4e58af6f03b943ee288ffad81012766cf830a,MO 与 MySQL 8.0.46 各 3 次结果稳定):

    SELECT 'A' COLLATE utf8mb4_general_ci = 'a' COLLATE utf8mb4_general_ci;

    MySQL 返回 1,MO 返回 0。同一 collation 明确写在 JOIN 键上时,ON a.s COLLATE utf8mb4_general_ci = b.s COLLATE utf8mb4_general_ci 对左侧 'A'、右侧 'a'/'A' 应匹配两行;MySQL 返回两行,MO 仅匹配完全同字节的 'A'。JOIN ... USING(k,s) 的同一数据也呈现同样差异。

    这属于已由 #25239 跟踪的大小写不敏感 collation 比较差异在 JOIN/USING 上的表现,不另开重复 issue;记录在 C05 的 joins 范围内供后续覆盖。

  3. Ariznawlll commented on Oct 14, 2026

    @Ariznawlll
    Collaborator

    补充 C05 的聚合 collation 差异(固定 MatrixOne runtime commit 2ce4e58af6f03b943ee288ffad81012766cf830a,对照 MySQL 8.0.46):

    CREATE TEMPORARY TABLE t(
      ci VARCHAR(8) COLLATE utf8mb4_general_ci,
      bin VARCHAR(8) COLLATE utf8mb4_bin
    );
    INSERT INTO t VALUES ('a','a'),('A','A'),('B','B');
    
    SELECT COUNT(DISTINCT ci), COUNT(DISTINCT bin) FROM t;
    SELECT ci, COUNT(*) FROM t GROUP BY ci;

    MySQL 返回 COUNT(DISTINCT ci)=2,binary 控制为 3;GROUP BY ci 将 a/A 归为同一组(计数 2),B 为另一组(计数 1)。MO 对 ci 返回 distinct 计数 3,并将 A、B、a 分成三个单行组;binary 控制两端均为 3 个组。

    MIN/MAX 的 general_ci 和 binary 控制值两端一致,因此当前证据收敛在 DISTINCT/GROUP BY 的等价类判定,而非排序输出值。该现象属于本 issue 明确列出的 DISTINCT/COUNT DISTINCT/GROUP BY 聚合范围,不另开重复 issue。

  4. Ariznawlll commented on Oct 14, 2026

    @Ariznawlll
    Collaborator

    继续补充 C05 的 UNION DISTINCT 与 ORDER BY 对照(同一固定 commit / MySQL 8.0.46):

    • UNION DISTINCT 的三项 a, A, B 在 utf8mb4_general_ci 下,MySQL 的结果行数为 2,MO 为 3;同样输入用 utf8mb4_bin 时两端均为 3。
    • UNION ALL 的 general_ci 控制两端均为 3 行。
    • 表列 ORDER BY ci, BINARY ci(ci 为 general_ci,含 a,A,B)在 MySQL 排序为 A,a,B,MO 为 A,B,a;binary 列 ORDER BY bin 两端均为 A,B,a。

    这些都与上条 COUNT DISTINCT/GROUP BY 结果一致:binary collation 控制稳定,general_ci 等价类/排序在集合、聚合、排序消费者之间没有被统一处理。属于本 issue 已列出的 UNION DISTINCT、ORDER BY 与聚合范围,不另开重复 issue。

  5. Ariznawlll commented on Nov 10, 2026

    @Ariznawlll
    Collaborator

    结论

    补充同类问题在窗口分区和金额汇总上的复现,不另开重复单,也不将它描述为某个修复“测试不通过”。这验证的是当前公开 SQL 路径;不把接受 COLLATE DDL 当作 native collation 的发布/升级开关已经生效的证据。

    关键证据

    官方 main 0c8bd5e5f3be4ce5582201513161181ddca37d6d 的干净本地构建,与独立 MySQL 8.3.0 各执行 3 个新建库:

    CREATE TABLE t(id INT PRIMARY KEY,k VARCHAR(12) COLLATE utf8mb4_general_ci,m INT);
    INSERT INTO t VALUES
      (1,'a',10),(2,'A',20),(3,'á',30),(4,'a ',40),(5,NULL,50);
    
    SELECT GROUP_CONCAT(id ORDER BY id),COUNT(*),SUM(m) FROM t GROUP BY k;
    SELECT id,COUNT(*) OVER(PARTITION BY k) FROM t ORDER BY id;
    SELECT id,COUNT(*) OVER(PARTITION BY CAST(k AS BINARY)) FROM t ORDER BY id;
    • GROUP BY:MO 将 1–4 分为四组,金额分别 10/20/30/40;MySQL 将其合为一组,成员 1,2,3,4、计数 4、金额 100。NULL 在两端均为独立组、金额 50。
    • 窗口:MO 返回 (1,1),(2,1),(3,1),(4,1),(5,1);MySQL 返回 (1,4),(2,4),(3,4),(4,4),(5,1)。
    • 显式 CAST(k AS BINARY) 的窗口对照:两端均为五个单行分区。源表值不变,会话继续可用。

    用组内 id 集合及金额作比较,没有假设等价组必须返回某一个特定文本代表值。上述结果 3/3 一致,是本单已列出的 padding/accent/GROUP BY/window 等价类范围的扩展证据。

    待解决点

    需要结合 C04/C11/C12 的实际激活条件完成公开 SQL 端到端验证。本轮没有验证滚动升级或跨 CN shuffle,不把本地一致复现扩写成这些路径的结论。

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions