Skip to content

[Bug]: Unicode-equivalent parent key updates skip ON UPDATE foreign-key actions #30340

Open

Description

@Ariznawlll

Description

ON UPDATE foreign-key actions are skipped when a referenced native Unicode UNIQUE value changes only in collation-equivalent spelling. CASCADE leaves the child at its old text, SET NULL leaves it non-NULL, and RESTRICT/NO ACTION allow an update that MySQL 8.0.45 rejects. The parent/child values remain referentially equal under the collation, but the declared action is not carried out.

Environment

  • Branch: official main
  • Commit: 48dbe277b6d20216c1c513d03c5cbd681380a8a2 (git_version() = 48dbe277b6)
  • Deployment: isolated local 1 Log/1 TN/2 CN
  • Comparator: isolated MySQL 8.0.45

Steps to reproduce

CREATE TABLE p (id INT PRIMARY KEY, s VARCHAR(30) COLLATE utf8mb4_unicode_ci UNIQUE);
CREATE TABLE c (
  id INT PRIMARY KEY,
  ref VARCHAR(30) COLLATE utf8mb4_unicode_ci,
  FOREIGN KEY (ref) REFERENCES p(s) ON UPDATE CASCADE
);
INSERT INTO p VALUES (1,'Alpha');
INSERT INTO c VALUES (10,'alpha');
UPDATE p SET s='ALPHA' WHERE id=1;
SELECT p.s,c.ref FROM p JOIN c ON c.id=10;

Actual behavior

MO returns ALPHA | alpha: the parent changed but the child stored value did not. SHOW CREATE TABLE c still declares ON UPDATE CASCADE.

The same Alpha→ALPHA change in separate tables also skips ON UPDATE SET NULL (MO child remains alpha, MySQL child becomes NULL). With ON UPDATE RESTRICT or NO ACTION, MO accepts the parent change while MySQL returns 1451 and leaves both rows unchanged.

Expected behavior

MySQL 8.0.45 returns ALPHA | ALPHA for the CASCADE SQL. Each declared ON UPDATE action should also be applied to a stored-value rewrite even when old/new spellings compare equal under the collation.

Stability and controls

  • Reproducer: 3/3 independent parent/child table pairs: Alpha→ALPHA, Café→Cafe, Éclair→ECLAIR all leave the MO child at its old spelling while MySQL updates it.
  • Normal control: Beta→Orbit (not collation-equivalent) cascades correctly in both engines.
  • Action controls: for non-equivalent Beta→Orbit, SET NULL nulls the child and RESTRICT rejects the update in both engines. ON DELETE CASCADE with differently spelled but collated-equal parent/child values deletes both rows in both engines.
  • Composite-key control: UNIQUE(s,n) / FOREIGN KEY(ref,n) cascades both parts for (Alpha,1)→(ALPHA,2) in both engines, but MO skips a later spelling-only (ALPHA,2)→(AlPhA,2) while MySQL updates the child spelling. This fits the same change-detection gap.
  • The equivalent parent UPDATE succeeds and FK equality remains true in MO; CASCADE/SET NULL yield wrong child values, and RESTRICT/NO ACTION take the wrong acceptance path.

Evidence

Exact SQL, 3/3 MO/MySQL results, and source references.

Code analysis

pkg/sql/plan/bind_update_fk.go:1717-1746 filters CASCADE/SET NULL parent mutations using NOT buildUpdateReferencedKeyUnchangedExpr. The RESTRICT check at lines 3081-3107 uses the same helper as an unchanged OR noChild escape. That helper at lines 3211-3268 compares old/new referenced-key values with SQL <=>. For native Unicode collation, distinct stored spellings can be equal under <=>, suppressing all four ON UPDATE actions. This is a code-supported explanation; the generated runtime plan was not instrumented.

Regression coverage

After a fix, assert CASCADE/SET NULL child values and RESTRICT/NO ACTION rejection for case/accent-equivalent rewrites, plus non-equivalent and ON DELETE controls. No repository test case was added in this exploration round.

Related

Activity

  1. added this to the MO-202610 milestone on Oct 16, 2026
  2. added
    kind/bug
    on Oct 16, 2026
  3. added theissue type on Oct 16, 2026
  4. changed the title [-][Bug]: ON UPDATE CASCADE leaves stale child text after Unicode-equivalent parent key update[/-] [+][Bug]: Unicode-equivalent parent key updates skip ON UPDATE foreign-key actions[/+] on Oct 16, 2026
  5. XuPeng-SH commented on Oct 16, 2026

    @XuPeng-SH
    Contributor

    复验结果:Unicode 等价父键更新遗漏 ON UPDATE CASCADE 仍可复现,请继续处理。

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

    CREATE TABLE p(id INT PRIMARY KEY,
                   s VARCHAR(30) COLLATE utf8mb4_unicode_ci UNIQUE);
    CREATE TABLE c(id INT PRIMARY KEY,
                   ref VARCHAR(30) COLLATE utf8mb4_unicode_ci,
                   FOREIGN KEY(ref) REFERENCES p(s) ON UPDATE CASCADE);
    INSERT INTO p VALUES(1,'Alpha');
    INSERT INTO c VALUES(10,'alpha');
    UPDATE p SET s='ALPHA' WHERE id=1;
    SELECT p.s,c.ref FROM p JOIN c ON c.id=10;

    实际为父表 'ALPHA'、子表 'alpha',子表保存的文本没有同步为 'ALPHA'。

    对照:继续把父键更新为非等价值 'Orbit' 时,子表正确 CASCADE 为 'Orbit'。测试入口:TestAuditUnicodeForeignKeySpellingUpdate。

    当前负责人为 matrix-meow,保留当前分配,保持 OPEN。

  6. XuPeng-SH commented on Oct 17, 2026

    @XuPeng-SH
    Contributor

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

    父键 Alpha -> ALPHA 后子表仍为 alpha,Orbit 非等价更新的 CASCADE 对照通过。

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

  7. XuPeng-SH commented on Oct 17, 2026

    @XuPeng-SH
    Contributor

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

    父键 Alpha -> ALPHA 后,ON UPDATE CASCADE 子表文本仍保留 alpha;改变实际键值的对照会级联。原始 spelling-only 级联断言仍失败。

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

  8. 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 的独立场景,结果仍为:Alpha -> ALPHA 后父表为 ALPHA、子表文本仍为 alpha;非等价的 Orbit 更新会级联,大小写等价更新断言仍失败。

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

  9. 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

    main 两个 CN 均复现:父键 'Alpha'、子键 'alpha',UPDATE p SET s='ALPHA' WHERE id=1 后子键仍是 alpha(预期 ALPHA),ON UPDATE CASCADE 未执行。

    4.2 在插入 collation 等价但不同拼写的子键时就报 FK 错误,未到达原始更新前置条件;没有将该分支的不同前置行为说成修复或同一 bug。

    原始命名断言、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。

  10. 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_unicode_ci 与 ON UPDATE CASCADE:父键 Alpha、子键 alpha,执行 UPDATE p SET s='ALPHA' WHERE id=1 后,CN0、CN1 子键仍为 alpha(预期 ALPHA)。问题仍可复现。该测试子集整体 exit 1,两个 CN 各 4 项失败。

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

  11. Ariznawlll commented on Nov 3, 2026

    @Ariznawlll
    CollaboratorAuthor

    结论

    测试不通过。Unicode 排序规则下,父键仅改变大小写时,四种 ON UPDATE 外键动作仍被跳过。

    关键证据

    • 版本:官方 main@d61a7206c16b30baa4efc525eb6067c4364035aa,macOS arm64,隔离 MO。使用 utf8mb4_unicode_ci,父值 Alpha、子值 alpha,更新父值为 ALPHA;四种动作各在独立表上运行三轮。
    • **Unhappy case:**CASCADE 三轮均得到 ALPHA / alpha,子值未改;SET NULL 三轮均保留 alpha;RESTRICT 和 NO ACTION 三轮均接受更新且保留 ALPHA / alpha,与 issue 中记录的 MySQL 参考行为不同。
    • **Happy / 控制 case:**非等价键 Beta → Orbit 三轮中,CASCADE 更新子值、SET NULL 将子值置空;RESTRICT/NO ACTION 返回 1451,父子行均保持原值。各轮临时库已清理。
    • 白盒:pkg/sql/plan/bind_update_fk.go 的 buildUpdateReferencedKeyUnchangedExpr 仍用于引用键变化判断;仅凭本次 SQL 结果不能证明其为唯一根因。该结果是当前 main 的复现,不据此推断其他发布版本。

    待解决点

    请研发检查 Unicode collation 等价但存储字节改变时的引用键变化判断,覆盖 CASCADE、SET NULL、RESTRICT、NO ACTION 和复合键;修复后再复测并补充回归。当前不把错误结果加入 MOTR 作为正确基线。

  12. Ariznawlll commented on Nov 3, 2026

    @Ariznawlll
    CollaboratorAuthor

    结论

    测试不通过。最新 main 上 Unicode 排序规则等价但存储字节不同的父键更新,仍跳过四种 ON UPDATE 外键动作;非等价更新对照通过。

    关键证据

    • 版本:官方 main@dd2499cdcdf2722848851d4debca6cd6c66b4751,本地隔离 LOG/TN/CN;同机新建独立 MySQL 8.0.45 对照。每个动作和场景在各自新建父子表上分别重复 3 轮。
    • Unhappy case:父 Alpha、子 alpha,均为 utf8mb4_unicode_ci,将父值更新为 ALPHA。MO 三轮均为 CASCADE 的父/子 ALPHA / alpha、SET NULL 的子值仍 alpha;RESTRICT、NO ACTION 均接受更新。MySQL 同样条件下分别将子值更新为 ALPHA、设为 NULL,或返回 1451 并保留 Alpha / alpha。
    • Happy case:父子均为 Beta 时更新为 Orbit,两端三轮均正确执行 CASCADE、SET NULL;RESTRICT 和 NO ACTION 返回 1451,父子记录保持原值。各测试库已清理。
    • 与 issue 中的现有 MySQL 对照与复现 SQL一致;当前没有把错误结果录为通过型回归基线。

    待解决点

    • 请研发处理 collation 等价但字节变化时的引用键变更判定,并覆盖四种动作、复合键及正确失败原子性;修复后重新验收并补充回归。本次验证为单 CN,不推断其他版本或生产影响。
  13. removed their assignment
    on Nov 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugneeds-triage

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions