fix fk meta - #26469
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Requesting changes for two blocking legacy-upgrade gaps at f8c66fd.\n\n1. pkg/bootstrap/versions/v4_0_6/upgrade.go:129: Foreign keys added with ALTER TABLE are silently left unconverted because mo_tables.rel_createsql is the original CREATE snapshot and ALTER does not rewrite it. Parsing that SQL yields no tree.ForeignKey, legacyForeignKeyMetadataUpdates returns an empty update list, and the tenant upgrade reports success while constraint_id stays 0 and the action stays RESTRICT. The new KEY_COLUMN_USAGE / REFERENTIAL_CONSTRAINTS views therefore remain wrong for this supported path.\n\n2. pkg/bootstrap/versions/v4_0_6/upgrade.go:154: A valid CREATE TABLE with an unnamed FK can abort the whole tenant upgrade. createTableSQLForCatalog persists the original one-statement SQL before adjustConstraintName generates the catalog UUID, so parsing the persisted SQL produces an empty ConstraintSymbol; this branch treats it as an error. The new test at upgrade_test.go:224 currently codifies this valid syntax as an invalid persisted definition.\n\nPlease backfill from authoritative catalog state, or otherwise reconcile missing/unnamed AST constraints with mo_foreign_keys rows, and add upgrade tests for both ALTER-added and unnamed legacy FKs.\n\nLocal validation otherwise passed: all 15 added/modified tests repeated independently under race 100x, all three owning packages under full race, and build/vet/non-race for v4_0_6, bootstrap, plan, compile, sysview, and frontend.
|
XuPeng-SH
left a comment
There was a problem hiding this comment.
One blocking upgrade regression remains on exact head a9e70ae. The ALTER-added and unnamed-FK gaps from my previous review are now covered, but explicit legacy RESTRICT actions are no longer preserved.
Before this update, the migration parsed the original CREATE definition and kept an explicit ON DELETE/UPDATE RESTRICT distinct from an omitted action. The new catalog/SHOW CREATE path cannot recover that distinction because both legacy catalog rows and SHOW CREATE render RESTRICT. legacyCatalogReferenceActionName then unconditionally rewrites every RESTRICT to NO_ACTION. The changed TestLegacyForeignKeyMetadataUpdatesPreserveOrderAndActions confirms the regression: its fk_restrict expectation was changed from RESTRICT to NO_ACTION. A 4.0.5 table created with an explicit RESTRICT will therefore report NO ACTION after upgrade, contradicting the PR contract and MySQL metadata.
Please combine the authoritative current-catalog reconciliation with the historical definition where it is available: preserve explicit/default action syntax for CREATE-time constraints, while using catalog plus SHOW CREATE as the fallback needed for ALTER-added and unnamed constraints. Add upgrade controls for legacy explicit RESTRICT versus omitted action, including the ALTER path where the distinction may be irrecoverable and must have a documented conservative policy.
Local validation: the three owning packages v4_0_6, plan, and sysview pass. This is a semantic migration issue, not a compile/test failure.
LeftHandCold
left a comment
There was a problem hiding this comment.
Requesting changes on exact head a9e70ae after full diff and upgrade-closure review.
Two blocking metadata defects remain:
-
The legacy migration rewrites every catalog
RESTRICTaction toNO_ACTION. For CREATE-time constraints,mo_tables.rel_createsqlstill preserves whether RESTRICT was explicit or omitted, so a 4.0.5 table with explicitON DELETE/UPDATE RESTRICTis misreported after upgrade. Preserve the historical syntax when it can be reconciled, and use catalog plus SHOW CREATE only as the fallback for ALTER-added/unnamed constraints. -
REFERENTIAL_CONSTRAINTS.UNIQUE_CONSTRAINT_NAMEis derived asmin(idx.type)from every index row sharing a referenced column. Withparent(id PRIMARY KEY, KEY secondary(id)), the join contains PRIMARY and MULTIPLE and returns MULTIPLE; named UNIQUE constraints are also reported as a type instead of their name. Match the exact PRIMARY/UNIQUE index by the full ordered referenced-column list and projectidx.name.
The earlier ALTER-added and unnamed-FK upgrade gaps are otherwise closed. Local validation passed for build, vet, focused tests, and full owning-package tests in pkg/bootstrap/versions/v4_0_6, pkg/sql/plan, and pkg/util/sysview; dependent pkg/bootstrap and pkg/sql/compile build/vet also passed. CI UT/BVT is green, while the upgrade compatibility jobs on this run were skipped.
同时增加了相关 UT/BVT,覆盖显式/默认动作、ALTER-added、unnamed FK、过期历史定义、竞争 secondary index 和命名复合 UNIQUE key。 |
同时增加了相关 UT/BVT,覆盖显式/默认动作、ALTER-added、unnamed FK、过期历史定义、竞争 secondary index 和命名复合 UNIQUE key。 |
What type of PR is this?
Which issue(s) this PR fixes:
issue #25388
What this PR does / why we need it: