Skip to content

[Compatibility]: ODKU ignores case-insensitive and trailing-space unique collations #28164

Description

@Ariznawlll

现象

在 MatrixOne main 99ed717b769e261b842c2f17345bd65865fc1470,ODKU 没有按非二进制字符串唯一键的排序规则判定冲突:

CREATE TABLE ci (
  id INT PRIMARY KEY,
  k VARCHAR(32) COLLATE utf8mb4_general_ci UNIQUE,
  v INT
);
INSERT INTO ci VALUES (1, 'Alpha', 10);
INSERT INTO ci VALUES (2, 'alpha', 20)
  ON DUPLICATE KEY UPDATE v=VALUES(v);
INSERT INTO ci VALUES (3, 'Alpha ', 30)
  ON DUPLICATE KEY UPDATE v=VALUES(v);

当前结果是插入 3 行(Alpha、alpha、Alpha ),没有触发 duplicate-key UPDATE。二进制唯一键对 0x6162 与 0x4142 区分正常,说明问题集中在非二进制 collation 的唯一键查找。

期望

ODKU 的冲突判定应遵循列声明的 collation;utf8mb4_general_ci 下大小写不同及尾随空格不同的字符串应视为相同键并进入 UPDATE 分支。

影响

大小写不敏感或忽略尾随空格的业务唯一键可能被重复插入,破坏幂等 upsert 和唯一性约束语义。

复现信息

  • MatrixOne main: 99ed717b769e261b842c2f17345bd65865fc1470
  • 重复执行 3 次,结果一致

Activity

  1. added this to the MO-202609 milestone on Sep 4, 2026
  2. added
    kind/bug
    on Sep 4, 2026
  3. added theissue type on Sep 4, 2026
  4. VioletQwQ-0 commented on Sep 9, 2026

    @VioletQwQ-0
    Collaborator

    补充阶段性实现记录(不关闭 issue):

    本轮在共享 MOKY/MOKL/MOKS 契约和 sidecar 事务基础上新增 MOKP 快照边界:快照携带 codec/registry/generation、关系 ID 和 revision,entry 严格按完整 key 排序,恢复前校验嵌套 key/locator、SHA-256 完整性以及大小和 entry 数上限。新增单测和 race 测试均通过;make cgo、make build、相关 planner/engine/fulltext/indexplugin 测试也通过。

    这仍是分阶段基础实现:v2 capability/activation 保持 fail-closed,普通 SQL 尚不能创建或写入 v2 关系。TN/catalog 持久化 sidecar、全局 SQL equality/hash/group、全部写入入口、mo_ctl 显式迁移、完整升级/恢复和 QA 尚未完成,不能据此宣称 #28164 已修复或确认客户 12 分钟根因。

    当前 exact-head CI run 34405953507 仍在排队/运行,QA 尚未开始;issue 保持 OPEN,PR 保持 Draft。

  5. VioletQwQ-0 commented on Sep 9, 2026

    @VioletQwQ-0
    Collaborator

    阶段性实现更新(不关闭 issue):

    边界保持不变:v2 capability/activation 仍 fail-closed,普通 SQL 尚不能创建或写入 v2。TN/catalog 持久化 sidecar、全局 SQL equality/hash/group、全部 bulk/LOAD/S3/partition 入口、mo_ctl 显式迁移、完整升级/恢复和 QA 尚未完成。该 PR 不能据此宣称客户 12 分钟根因已确认;#28164 保持 OPEN。

  6. VioletQwQ-0 commented on Sep 9, 2026

    @VioletQwQ-0
    Collaborator

    阶段性实现补充(#28520,仍为 Draft;不关闭 issue):

    • exact head:5206d263df3f48abbe1f78b58e7f5a377f897aeb;base:81a6fc70e50d4ccc28d09b0d5e87f18a97a2ad9e。
    • 新增 MOKG 迁移 gate checkpoint 编解码:固定大端字段、owner/permit/replay 映射排序、长度/总量上限、SHA-256 完整性校验,以及恢复前 MigrationGate.Validate 状态机校验。它防止恢复时丢失写入许可、owner fence、replay target 或已发布标记。
    • pkg/common/collationkey unit、race、vet、git diff --check 和 make cgo/make build 均通过;该 head 的 mo-service SHA256 为 8469bd4f2476da22ff5aa45ec4c5adaed7368750261fa8dcaa256fcda2e4bb2d。
    • 新 head 的 ALL CI run 34409583638 当前仍在排队/运行,QA 尚未开始。

    边界不变:MOKG 目前是供后续 HAKeeper/catalog 适配器使用的内部持久化契约,尚未接入真实 TN/catalog sidecar、mo_ctl 迁移、全局 SQL 比较/哈希/group 或生产启用;v2 仍 fail-closed。该阶段不能宣称 #28164 已修复,也不能确认客户 12 分钟根因。请维护者按 exact-head CI、存储接入和 QA 继续验收。

  7. VioletQwQ-0 commented on Sep 9, 2026

    @VioletQwQ-0
    Collaborator

    补充校验:迁移 gate 编解码的错误路径已收紧为目标缓冲区原子不变,并已推送到 #28520 当前 exact head 013860cb6f13fa58fe1c634ba82bea0bccbb3878(base 81a6fc70e50d4ccc28d09b0d5e87f18a97a2ad9e)。pkg/common/collationkey unit/race/vet、make cgo、make build 和 git diff --check 重新通过;mo-service SHA256:78000b745d421f397b0c7e318e27ff71c061675114f88a45bcfff2a854705551。新 exact-head ALL CI 尚在排队/运行,QA 未开始。其余边界及“v2 未启用、不能宣称 issue 已修复”保持不变。

  8. VioletQwQ-0 commented on Sep 9, 2026

    @VioletQwQ-0
    Collaborator

    持久化边界补充(#28520,仍为 Draft):

    • HAKeeperRSMState 新增 typed UniqueKeyMigrationGate 字段(field 44),CheckerState 新增只读字段(field 20);RSM snapshot/recovery 和 StateQuery 均保留/深拷贝该 gate,旧 snapshot 在复用 state 时先清空,避免残留新状态。
    • pkg/pb/logservice 增加 common MigrationGate ↔ protobuf 的 fail-closed adapter,空/非法 gate 不会被当作新迁移;映射和 claim token 不共享调用方内存。
    • exact head:c8b3adc870298ef0b1797825a9a77dfab5a55137,base:81a6fc70e50d4ccc28d09b0d5e87f18a97a2ad9e。相关 common、logservice、hakeeper、planner 窄测及构建通过。
    • 新 head 的 ALL CI 已重新排队/运行;QA 尚未开始。

    该字段目前只提供 RSM 持久化与观察,不提供迁移状态变更命令,也未接入 TN/catalog sidecar、mo_ctl 或生产 v2 启用;#28164 继续 OPEN,客户根因仍未确认。

  9. VioletQwQ-0 commented on Sep 9, 2026

    @VioletQwQ-0
    Collaborator

    补充当前实现与验证记录(exact head):

    • PR feat: define collation key sidecar envelope #28520 当前 head 为 fbfbe76d08dcfebc46649cb18ec36f0777670a0e,base 为 81a6fc70e50d4ccc28d09b0d5e87f18a97a2ad9e,仍为 Draft;本次没有启用 v2,也没有改变普通 SQL 的唯一性行为。
    • 针对迁移门禁的状态范围修正:HAKeeperRSMState.UniqueKeyMigrationGates 和 CheckerState.UniqueKeyMigrationGates 现在按物理 relation ID 保存 gate map,不再用单一 gate 覆盖不同关系;新增双 relation snapshot/restore 覆盖,并清理旧快照复用状态。
    • 本地验证:go test ./pkg/common/collationkey ./pkg/pb/logservice ./pkg/hakeeper PASS;仓库 mo-cgo-test ./pkg/sql/plan PASS;make cgo PASS;make build PASS。当前构建产物 mo-service SHA256=f157ad0db80eda213b0607bf61bef5ee13cf2f423a86fb52b290e89a30470aef,cgo/libmo.dylib SHA256=760a841cb61c01c3ee44c011bad329a5707d86314bdf590b4ed4e20814400c87。
    • 该 PR 仍是共享编码、元数据/能力门禁、sidecar/迁移 checkpoint 与 planner fail-closed 基础增量;TN/catalog 实际 sidecar 写入、全局 SQL equality/hash/group、bulk/LOAD/S3/partition、mo_ctl 迁移入口、升级/恢复和 QA 尚未完成。生产启用保持关闭,[Compatibility]: ODKU ignores case-insensitive and trailing-space unique collations #28164 不能据此关闭。
    • 新 head 的 GitHub CI 已重新生成,目前仍在等待;不复用旧 head 结果。请按 exact head 继续 review,并将后续 QA 作为独立门禁。
  10. VioletQwQ-0 commented on Sep 9, 2026

    @VioletQwQ-0
    Collaborator

    补充:本轮 exact-head 验证证据已固化在开发工作树的 ignored artifact:
    artifacts/issue-28164-implementation/20260909T224500Z/(含 run.json、测试日志、preflight snapshot、审查清单和 SHA256SUMS)。该目录只保存开发侧证据,不进入 Git。

    状态仍为:实现增量和本地定向验证通过;GitHub CI run 34412107334 尚在运行;升级验证、完整生产启用和 QA 未运行。请不要把这轮基础增量当作 #28164 已修复或客户根因确认。

  11. VioletQwQ-0 commented on Sep 9, 2026

    @VioletQwQ-0
    Collaborator

    CI 修复与基线同步补充(PR #28520,仍为 Draft):

    • 旧 exact-head run 34412107334 的确定失败是 TestV2PrimaryKeyRejectsMissingHiddenIdentity:v2 主键缺少隐藏身份时,planner 在 legacy nil-column 分支提前返回 nil,未执行 fail-closed 拒绝。
    • 已修复并通过 focused 及完整 pkg/sql/plan CGo 测试;legacy 主键路径行为保持不变。
    • 分支已 rebase 到当前 upstream/main@7c643f469b9162dec19b7f880e4cf6b2c12507d9,并以 lease 推送。当前 PR head:624edadde4acab3939ec83fe8af095da7d323a2b。
    • 当前唯一有效 CI:34416285056,正在执行;旧 run 34412107334、34414605024 仅保留为 superseded 历史,不混入验收。
    • 本轮 artifact:artifacts/issue-28164-implementation/20260909T231820Z/,含新 head/base、diff/preflight 哈希、测试日志和 CI 快照。

    状态边界不变:这是共享编码、元数据/能力门禁、sidecar/checkpoint 与 planner 的阶段性基础增量;真实 TN/catalog sidecar 写入、全局 SQL 比较/hash/group、全部 bulk/LOAD/S3/partition 入口、管理迁移、升级/恢复和 QA 尚未完成,v2 未启用,#28164 继续开放,客户现场根因未确认。

  12. VioletQwQ-0 commented on Sep 9, 2026

    @VioletQwQ-0
    Collaborator

    版本纠正:

    上一条 CI 修复评论中的 1a8c2b7d… 属于 rebase 前 head,已被 superseded。当前 PR #28520 已 rebase 到 upstream/main@7c643f469b9162dec19b7f880e4cf6b2c12507d9,远端 head 为 624edadde4acab3939ec83fe8af095da7d323a2b。

    当前唯一有效 exact-head CI 为 34416285056,仍在运行;rebase 前的 CI 结果不用于最终验收。

  13. 33 remaining items

  14. XuPeng-SH commented on Oct 16, 2026

    @XuPeng-SH
    Contributor

    复验结果:原 issue 的 general_ci UNIQUE 问题仍可复现,请继续处理。

    实测 main 提交:97415db10bdb3d6ffdf53ff1810a7e80bd78ee11(实际 MySQL 协议)。

    CREATE TABLE uq(v VARCHAR(40) COLLATE utf8mb4_general_ci UNIQUE);
    INSERT INTO uq VALUES('Apple');
    INSERT INTO uq VALUES('apple');

    第二次 INSERT 实际成功,未返回预期的重复键 1062。

    #30113 交付的是 native Unicode UNIQUE 的限定子集;其功能测试通过并不表示原 issue 的 general_ci 语义已解决。测试入口:TestAuditOriginalIssueSQL/issue_28164。

    当前仍由开发负责人 ck89119、VioletQwQ-0 负责,保留当前分配,保持 OPEN。

  15. XuPeng-SH commented on Oct 17, 2026

    @XuPeng-SH
    Contributor

    最近24小时合并项复核补充:在 main aa4b6eddfdad54d11be6fd75a5675eb9801f6690 上,再次通过实际 MySQL 协议复现本 issue。

    general_ci UNIQUE 仍允许先后插入 Apple、apple。

    原始 SQL/对照与前一条复验评论一致。本轮没有证据表明它已修复,也不将其当作最近24小时新引入的问题。当前仍由开发负责人处理,保持 OPEN;关联 PR 已补充验证范围,未创建重复 issue。

  16. XuPeng-SH commented on Oct 17, 2026

    @XuPeng-SH
    Contributor

    继续验证记录(2026-10-17),main a322466757b9b0165c59fbda565608653d923b2a(Go 1.27.1),Linux/amd64、匹配 CGo 产物、真实测试执行结果:

    general_ci UNIQUE 场景仍接受 Apple / apple,原始应拒绝插入的语句没有报错。

    此项仍未解决;保留现有开发指派,不转测。使用现有 issue 跟踪,没有为同一现象重复建 issue。

  17. XuPeng-SH commented on Oct 17, 2026

    @XuPeng-SH
    Contributor

    新会话初始化修复合并后的范围复核(2026-10-17,main d9cf2dd4e2b92e2193bb390115be624b76099764,Linux/amd64、Go 1.27.1、匹配 CGo):

    本轮已通过真实 TCP 验证 #30398:45/192/224 的初始 session collation 均正确,mysql2 的 reset/change-user 四变量检查也通过。同轮通过真实 SQL 重跑本 issue 的独立场景,结果仍为:general_ci UNIQUE 仍接受 Apple 后再插入 apple,应出现的 1062 没有出现。

    因此不能用会话变量初始化已修复替代本 issue 的行为修复。该问题仍由现有开发负责人处理,保持 OPEN,不转测;此为已有问题的范围复核,未另建重复 issue。

  18. XuPeng-SH commented on Oct 18, 2026

    @XuPeng-SH
    Contributor

    补齐本轮 continue18 已完成实测的验收记录(2026-10-18;本评论没有冒充另一次新执行)。Linux/amd64、Go 1.27.1、各分支按源码独立新建 CPU/CGo、真实认证 MySQL TCP、CN0/CN1 分别运行;生产逻辑未修改。

    main:4226537e5094995155eab9c2a883db649ff7b95b
    4.2-dev:35273bcd6a5cfa9468bcf7ca4031fe17560b5ab1

    结果仍失败:唯一列 k COLLATE utf8mb4_general_ci 依次通过 ODKU 写入 'Alpha'、'alpha'、'Alpha ' 后,main/4.2 两个 CN 均保留 3 行(预期 1 行),未按 collation 进入冲突 UPDATE。失败子场景为 28164_unique。

    原始命名断言、SQL/错误与退出码保留于 /workspace/work/pr-audit-continue18/logs/main-sql-final.log、4.2-sql-final.log,相应混合命令均 exit 1,未称整批通过。独立诊断 overlay 为 audit_sql_test.go,重放入口 replay.sh main-sql / replay.sh 4.2-sql;完整证据包 matrixone-pr-audit-20261018-continue18.zip。问题仍在,保持现有开发指派,不转测、不重复建 issue。

  19. XuPeng-SH commented on Oct 19, 2026

    @XuPeng-SH
    Contributor

    本轮实测更新(2026-10-19,UTC)。目标分支 main,完整 SHA 8e63625c4e9baeb1d28c1095c07732f056c04895;Linux/amd64,Go 1.27.1,嵌入式两 CN、真实 MySQL TCP(仓库支持的 MO_TEST_CLUSTER_TCP_ONLY=1)。当前源码由本轮测试命令构建;native CGo 产物通过 provenance 校验,基于 090b14fbb4c288819728f628e009311a11812e1f 构建后复用(其后 #30602 为 test-only、native 输入未变)。

    实测命令:

    MO_TEST_CLUSTER_TCP_ONLY=1 .agents/skills/mo-dev/scripts/mo-cgo-test -overlay=<audit overlay> -p 1 -count=1 -v -timeout=5m -run 'TestAudit21UnresolvedAndFixedControls/(CN0|CN1)/(25096_general_ci|28164_unique|30339_unicode_diagnostic|30340_cascade)$' ./pkg/tests/issues
    

    utf8mb4_general_ci UNIQUE 上依次插入 Alpha、ODKU alpha、ODKU Alpha 后,CN0、CN1 均有 3 行(预期 1 行,最终值应由冲突更新得到 30)。问题仍可复现。该测试子集整体 exit 1,两个 CN 各 4 项失败。

    原始日志:continue22/runs/followups-main/public-followups.log(完整 497,614 字节,SHA-256 1fdfea1fa80b1f88f0cebe61be7a56252ca9e409834874eb3ff45ef753047765);临时测试源和 overlay 在同目录。保持现有开发指派。

    Binary-assignment PR follow-up — 2026-10-22 16:08 UTC

    PR #29057 now includes commit 48e544271aa5189febceeb5a95e572792f490102, which adds a changed-session DECIMAL generated-column regression and retargets the binary assignment while retaining the stored arithmetic expression. I inspected this incremental patch; it adds focused planner and public SQL coverage, and I found no definite defect in this change. The PR author reports the planner suite, three protocol-boundary tests and the binary-capacity SQL BVT passed on that incremental content; these are author-reported results, not a test run by me.

    The current PR head is cf96663a108a53fd82d265b1077e70851db679e5, a subsequent main synchronization. Exact-head run 39811166703 still has UT, SCA, shared build and UT-coverage jobs in progress; only preflight/coverage eligibility/size checks are complete. The prior formal review/request-changes records predate the 48e5442 repair, and the version-floor inline thread remains unresolved. This local environment is at 460b96365a381e74916b044a99fc9423c33ad3fd with no Go toolchain, so I did not rerun the tests.

    This PR explicitly covers only the binary-assignment/COPY stage of #28164; the general_ci UNIQUE ODKU collation defect remains unresolved. Issue stays open, with existing assignees ck89119 and VioletQwQ-0 unchanged; no tester transfer is warranted for the still-open core issue. Recheck current-head CI, reviewer disposition, and the outstanding ODKU reproduction separately.

  20. daviszhen commented on Oct 20, 2026

    @daviszhen
    Contributor

    最新 main 验证(2026-10-20)

    基线:309f618995af4ee23e3b9149365f4af77264090d;相关 PR:#30113/#29890/#29834。

    结论:问题仍可复现。exact-main Docker 执行 utf8mb4_general_ci UNIQUE + Alpha、ON DUPLICATE KEY UPDATE alpha、ON DUPLICATE KEY UPDATE Alpha 后仍得到 3 行;按大小写不敏感唯一键预期应复用同一行。该问题仍未解决,建议继续保留在开发中。

  21. Ariznawlll commented on Oct 29, 2026

    @Ariznawlll
    CollaboratorAuthor

    Independent confirmation on main c6683bd2f5 (2026-10-29 build, local dual-CN launch): the defect is not limited to the ODKU path — a plain INSERT into a utf8mb4_general_ci UNIQUE column also misses the collision and succeeds silently:

    CREATE TABLE u1(id INT PRIMARY KEY, k VARCHAR(20)) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
    INSERT INTO u1 VALUES (1,'abc');
    INSERT INTO u1 VALUES (2,'ABC');    -- succeeds; MySQL 8.0 rejects with ERROR 1062
    INSERT INTO u1 VALUES (3,'abc ');  -- succeeds; MySQL 8.0 rejects with ERROR 1062
    SELECT * FROM u1;  -- 3 distinct rows

    Since the binary-comparison lookup misses the row entirely, no error, no ODKU branch, no dedup — the constraint is effectively utf8mb4_bin for uniqueness regardless of the declared collation. Same root as the ODKU report (unique-key lookup ignoring the collation), confirmed still reproducing 9 days after the last verification on this thread; adding the plain-INSERT evidence since it shows every write path through the unique index is affected, not just upserts.

  22. XuPeng-SH commented on Oct 31, 2026

    @XuPeng-SH
    Contributor

    Additional v4.2.6 reproduction and white-box evidence (local embedded 3-CN; no concurrency):

    CREATE TABLE ci (
      id INT PRIMARY KEY,
      k VARCHAR(32) COLLATE utf8mb4_general_ci NOT NULL,
      v INT NOT NULL,
      UNIQUE KEY uk_k(k)
    );
    INSERT INTO ci VALUES (1,'AbC',10);
    INSERT INTO ci VALUES (2,'abc',20);
    -- succeeds; COUNT(*) = 2
    
    INSERT INTO ci VALUES (3,'ABC',30)
    ON DUPLICATE KEY UPDATE v=VALUES(v);
    -- also succeeds as a third row; it does not update the existing key

    On v4.2.6 commit 71498157cc21f833b8e717f45d50d1f926be3134, the hidden unique-index table held separate entries AbC and abc. The same duplicate was accepted by plain INSERT, so this is not limited to ODKU target arbitration. The utf8mb4_bin control also accepts case variants, as expected. On this branch, direct comparisons explicitly collated as utf8mb4_general_ci and utf8mb4_unicode_ci returned 0 for 'AbC' = 'abc', and the unicode_ci unique-index control accepted both rows too.

    White-box observation: the plan Type/ColDef representation used here carries no collation identity, and unique-index table/key construction derives its key type from the column's basic type. The DML lookup then probes with the raw string key. The declared collation therefore cannot govern the unique-index key on this path. This is consistent with the broader collation work tracked by #25096/#29479; I did not create a duplicate issue.

  23. XuPeng-SH commented on Oct 31, 2026

    @XuPeng-SH
    Contributor

    Confirmed still reproducing on the exact local origin/main HEAD ae40f12a647880a63466de32a9f507c2c72dca0b (2026-10-31), using an embedded 3-CN test:

    • With utf8mb4_general_ci, inserting ('AbC') then a plain UNIQUE value ('abc') succeeds; row count becomes 2.
    • Explicit 'AbC' COLLATE utf8mb4_general_ci = 'abc' COLLATE utf8mb4_general_ci returns 0.
    • After both spellings are stored, lookup of name='aBc' returns 0 with the normal plan, FORCE INDEX(uk_name), and IGNORE INDEX(uk_name).
    • ODKU on ('abc') also inserts a second row instead of updating the existing AbC row.
    • The utf8mb4_bin control accepts both case variants, as expected.

    Thus the failure is still in current main and is broader than unique-index target selection: declared _ci comparison semantics are not honored by direct expressions, table scans, or index scans in this case. The local test was run from detached source commit ae40f12a64; no production files were changed.

  24. XuPeng-SH commented on Oct 31, 2026

    @XuPeng-SH
    Contributor

    White-box follow-up on the same exact current HEAD ae40f12a647880a63466de32a9f507c2c72dca0b: after the plain insert accepted both variants, I resolved the hidden table for uk_name and inspected it. It is defined with a raw VARCHAR(32) __mo_index_idx_col primary key and an integer primary column; the stored keys are the verbatim values AbC and abc in separate rows. No collation-derived canonical key is stored on this path. Together with the comparison results above (including table scan and forced index), this points to both comparison semantics and unique-index key construction failing to use the declared collation, rather than a DEDUP/ODKU-only error.

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

Metadata

Metadata

Labels

kind/bugseverity/s1

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions