Skip to content

fix fk meta - #26469

Open
daviszhen wants to merge 15 commits into
matrixorigin:mainfrom
daviszhen:0730-fix-fk-meta
Open

fix fk meta#26469
daviszhen wants to merge 15 commits into
matrixorigin:mainfrom
daviszhen:0730-fix-fk-meta

Conversation

@daviszhen

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #25388

What this PR does / why we need it:

  • information_schema.KEY_COLUMN_USAGE 改为从 mo_foreign_keys 提供 FK 本地列到引用列的映射及复合键顺序。
  • information_schema.REFERENTIAL_CONSTRAINTS 正确展示默认 NO ACTION、显式 RESTRICT,并按父表 ID 关联索引以避免同名列导致重复。
  • 新建 FK 持久化默认动作为 NO_ACTION,显式动作保持原值。
  • v4_0_6 租户升级解析历史 rel_createsql,回填旧复合 FK 的列序和默认/显式动作语义。
  • 增加 planner、升级、sysview UT,以及 FK BVT 覆盖默认/显式动作、复合 FK 与无关索引场景。

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

…xone into 0730-fix-fk-meta

# Conflicts:
#	pkg/bootstrap/versions/v4_0_6/upgrade_test.go

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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

Labels

kind/bug Something isn't working size/XXL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants