Repository navigation
Description
Description
MatrixOne cannot drop the particular parent UNIQUE index recorded by a foreign key even when a second, fully equivalent UNIQUE index on the same columns remains. MySQL 8.0.45 allows the DROP and continues enforcing the FK through the remaining index. This is a DDL compatibility gap, not observed data corruption.
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, u INT,
UNIQUE KEY uk1(u), UNIQUE KEY uk2(u));
CREATE TABLE c (id INT PRIMARY KEY, u INT,
FOREIGN KEY (u) REFERENCES p(u));
INSERT INTO p VALUES (1,10);
INSERT INTO c VALUES (1,10);
ALTER TABLE p DROP INDEX uk1;Actual behavior
MO returns ERROR 1553 (HY000): Cannot drop index 'uk1': needed in a foreign key constraint. uk2(u) remains available. mo_catalog.mo_foreign_keys.referenced_index_name identifies uk1 as the selected FK index.
An atomic replacement has the same gap: with only uk_old(u) initially, ALTER TABLE p DROP INDEX uk_old, ADD UNIQUE INDEX uk_new(u) is rejected by MO with 1553, whereas MySQL succeeds and preserves FK enforcement. A related PRIMARY-key variant (PRIMARY KEY(id) plus UNIQUE KEY uk_id(id)) rejects ALTER TABLE p DROP PRIMARY KEY in MO but succeeds in MySQL, which retains uk_id(id) and FK enforcement. MO leaves each original definition intact; neither path caused partial DDL.
Expected behavior
MySQL 8.0.45 executes the same DROP successfully, retains UNIQUE KEY uk2(u), and continues rejecting invalid child references. MO could safely permit this operation by atomically rebinding the FK to the remaining equivalent index, or document the bound-index restriction as an explicit compatibility limit.
Stability and controls
- Reproducer: 3/3 independent parent/child UNIQUE fixtures.
ALTER TABLE ... DROP INDEXand standaloneDROP INDEX ... ONboth reject the selected index in MO and succeed in MySQL. Reversing physical index-creation order did not remove the gap; the catalog's selected name, not creation order, governs MO's decision. A separate atomic DROP+ADD replacement and PRIMARY-to-UNIQUE transition reproduce the same incompatibility. - Normal control: when no alternative key exists, both engines reject with 1553. In MO, dropping the unbound equivalent UNIQUE succeeds and FK enforcement stays active.
- Failed MO DDL leaves the selected index and FK intact; no partial mutation was observed.
Evidence
Exact SQL, three variants, controls, and catalog/code evidence.
Code analysis
pkg/sql/plan/build_ddl.go:CheckDropReferencedKeyForeignKeyDependency protects the exact ForeignKeyDef.ReferencedIndexName. The current planner UT also asserts that a bound index is not droppable even if another compatible UNIQUE exists. This is a safety-preserving current implementation choice, but it does not provide MySQL's alternative-index transition.
Regression coverage
If compatibility is added, cover a bound-index DROP with an equivalent surviving UNIQUE, a same-statement DROP+ADD replacement, PRIMARY-to-UNIQUE transition, reversed index creation order, standalone/ALTER syntax, post-DDL child FK checks, and the no-alternative rejection control. No repository test was added during this exploration round.
Related
- This is separate from [Bug]: Unicode-equivalent parent key updates skip ON UPDATE foreign-key actions #30340 (Unicode-equivalent FK ON UPDATE actions): ordinary INT keys reproduce this DDL gap.
Activity
[-][Compatibility]: DROP INDEX cannot switch an FK to an equivalent UNIQUE index[/-][+][Compatibility]: FK blocks replacing its bound parent key despite an equivalent UNIQUE[/+]test: rebind FK truncation identity oracle to the equivalent-key tran…
fix(plan): rebind foreign keys to equivalent surviving keys on parent…
test: rebind FK truncation identity oracle to the equivalent-key tran…
fix(plan): close FK equivalent-key review findings on claim validity …
fix(plan): rebind foreign keys to equivalent surviving keys on parent…
2 remaining items
fix(plan): align FK rebinding's durable constraints in the same trans…
fix(plan): rebind foreign keys to equivalent surviving keys on parent…
test: rebind FK truncation identity oracle to the equivalent-key tran…
fix(plan): close FK equivalent-key review findings on claim validity …
fix(plan): align FK rebinding's durable constraints in the same trans…
fix(plan): rebind foreign keys to equivalent surviving keys on parent…
test: rebind FK truncation identity oracle to the equivalent-key tran…
fix(plan): close FK equivalent-key review findings on claim validity …
fix(plan): align FK rebinding's durable constraints in the same trans…
fix(plan): rebind foreign keys to equivalent surviving keys on parent…
XuPeng-SH commentedon Oct 29, 2026
QA handoff for merged #31628 (
969998e69776e7809ed1c56f8bfc62a9a98aac73): this isolated QA run inspected the source and issue history but did not run current-head functional tests or live SQL because the existing resource guard left insufficient headroom. Please verify FK surviving-key rebinding, self-reference, atomicity and multi-CN visibility. Author-reported PR tests are separate evidence and are not results of this QA run.Ariznawlll commentedon Nov 3, 2026
结论
测试通过。删除被外键引用的父表键时,可重新绑定到等价唯一键并继续执行外键约束。
关键证据
main@d61a7206c16b30baa4efc525eb6067c4364035aa,隔离 MO 两 CN。待解决点
MOTR PR 尚待评审合入。