Repository navigation
Description
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→ECLAIRall 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 NULLnulls the child andRESTRICTrejects the update in both engines.ON DELETE CASCADEwith 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
- [Compatibility] Common MySQL collations reject Java application schema initialization #29206 tracks native Unicode collation activation; the failure is in an already accepted
ON UPDATE CASCADEexecution path, not unsupported DDL. - The new diagnostic-only issue [Bug]: Native Unicode UNIQUE conflicts truncate 1062 duplicate-entry diagnostics #30339 is separate from this wrong-result defect.
Activity
[-][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[/+]XuPeng-SH commentedon Oct 16, 2026
复验结果:Unicode 等价父键更新遗漏 ON UPDATE CASCADE 仍可复现,请继续处理。
实测 main 提交:
97415db10bdb3d6ffdf53ff1810a7e80bd78ee11(实际 MySQL 协议)。实际为父表 'ALPHA'、子表 'alpha',子表保存的文本没有同步为 'ALPHA'。
对照:继续把父键更新为非等价值 'Orbit' 时,子表正确 CASCADE 为 'Orbit'。测试入口:
TestAuditUnicodeForeignKeySpellingUpdate。当前负责人为 matrix-meow,保留当前分配,保持 OPEN。
XuPeng-SH commentedon Oct 17, 2026
最近24小时合并项复核补充:在 main
aa4b6eddfdad54d11be6fd75a5675eb9801f6690上,再次通过实际 MySQL 协议复现本 issue。父键 Alpha -> ALPHA 后子表仍为 alpha,Orbit 非等价更新的 CASCADE 对照通过。
原始 SQL/对照与前一条复验评论一致。本轮没有证据表明它已修复,也不将其当作最近24小时新引入的问题。当前仍由开发负责人处理,保持 OPEN;关联 PR 已补充验证范围,未创建重复 issue。
XuPeng-SH commentedon Oct 17, 2026
继续验证记录(2026-10-17),main
a322466757b9b0165c59fbda565608653d923b2a(Go 1.27.1),Linux/amd64、匹配 CGo 产物、真实测试执行结果:父键
Alpha -> ALPHA后,ON UPDATE CASCADE 子表文本仍保留alpha;改变实际键值的对照会级联。原始 spelling-only 级联断言仍失败。此项仍未解决;保留现有开发指派,不转测。使用现有 issue 跟踪,没有为同一现象重复建 issue。
XuPeng-SH commentedon Oct 17, 2026
新会话初始化修复合并后的范围复核(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。
XuPeng-SH commentedon Oct 18, 2026
补齐本轮 continue18 已完成实测的验收记录(2026-10-18;本评论没有冒充另一次新执行)。Linux/amd64、Go 1.27.1、各分支按源码独立新建 CPU/CGo、真实认证 MySQL TCP、CN0/CN1 分别运行;生产逻辑未修改。
main:
4226537e5094995155eab9c2a883db649ff7b95b4.2-dev:
35273bcd6a5cfa9468bcf7ca4031fe17560b5ab1main 两个 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。XuPeng-SH commentedon Oct 19, 2026
本轮实测更新(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 输入未变)。实测命令:
父子表使用
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-2561fdfea1fa80b1f88f0cebe61be7a56252ca9e409834874eb3ff45ef753047765);临时测试源和 overlay 在同目录。保持现有开发指派。Ariznawlll commentedon Nov 3, 2026
结论
测试不通过。Unicode 排序规则下,父键仅改变大小写时,四种 ON UPDATE 外键动作仍被跳过。
关键证据
main@d61a7206c16b30baa4efc525eb6067c4364035aa,macOS arm64,隔离 MO。使用utf8mb4_unicode_ci,父值Alpha、子值alpha,更新父值为ALPHA;四种动作各在独立表上运行三轮。ALPHA / alpha,子值未改;SET NULL 三轮均保留alpha;RESTRICT 和 NO ACTION 三轮均接受更新且保留ALPHA / alpha,与 issue 中记录的 MySQL 参考行为不同。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 作为正确基线。
Ariznawlll commentedon Nov 3, 2026
结论
测试不通过。最新 main 上 Unicode 排序规则等价但存储字节不同的父键更新,仍跳过四种 ON UPDATE 外键动作;非等价更新对照通过。
关键证据
main@dd2499cdcdf2722848851d4debca6cd6c66b4751,本地隔离 LOG/TN/CN;同机新建独立 MySQL 8.0.45 对照。每个动作和场景在各自新建父子表上分别重复 3 轮。Alpha、子alpha,均为utf8mb4_unicode_ci,将父值更新为ALPHA。MO 三轮均为 CASCADE 的父/子ALPHA / alpha、SET NULL 的子值仍alpha;RESTRICT、NO ACTION 均接受更新。MySQL 同样条件下分别将子值更新为ALPHA、设为 NULL,或返回 1451 并保留Alpha / alpha。Beta时更新为Orbit,两端三轮均正确执行 CASCADE、SET NULL;RESTRICT 和 NO ACTION 返回 1451,父子记录保持原值。各测试库已清理。待解决点