Skip to content

fix(plan): use final table identity for ALTER foreign keys - #30298

Merged
XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
iamlinjunhong:fix/30260-alter-rename-foreign-key
Oct 15, 2026
Merged

XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
iamlinjunhong:fix/30260-alter-rename-foreign-key

Conversation

@iamlinjunhong

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:

What this PR does / why we need it:

A single ALTER TABLE that combines RENAME TO with ADD FOREIGN KEY fails with an old-table-name lookup in either clause order. Post-DDL foreign key validation now uses the final table name. Ordered foreign key catalog additions/deletions retain their original identity, then table-name updates run last so new, existing, incoming, and self references publish the final identity together.

The change stays within the INPLACE planner and preserves the existing execution and transaction boundaries. Invalid existing rows reject the ALTER and roll back the rename, constraint changes, and catalog changes. It adds one bounded scan of ALTER options with no additional catalog SQL executions.

Validation on macOS arm64, Go 1.27.1, CPU native build:

  • Confirmed the regression fails before the production fix through both planner and SQL frontend tests, then passes after the fix.
  • Full pkg/sql/plan package passed; focused coverage includes both clause orders, ordered constraint replacement/add-drop, quoted composite self references, incoming/outgoing metadata, FK enforcement, rollback, no-op renames, and checks-disabled planner controls. Existing self-reference catalog regression also passed.
  • Active foreign_key/fk_alter_rename.sql passed normal mo-tester comparison twice on the same test-owned single-CN instance (26/26 statements each); database and FK catalog teardown were verified after each run.
  • gofmt, go vet, and incremental golangci-lint passed for the changed Go packages.

CI remains pending. The issue should remain open after merge for reporter verification.

@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 →

@XuPeng-SH

XuPeng-SH commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: 3b84e8a9a0d6f4e42a673a61b29b9b05b290e395

Review completed. Read the assessment.

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

mo-bot review · mo-bot-local · review

Commit: 3b84e8a9a0d6f4e42a673a61b29b9b05b290e395

Assessment: approve

Reviewed the complete five-file delta and surrounding planner, executor, catalog and transaction paths. The design correctly preserves the original identity for binding and execution while using the final identity for validation and catalog publication. It reuses existing SQL builders and rollback ownership without introducing another execution path. No actionable defects remain.

Model: gpt-6-astra / xhigh

Session: 01a13dcf-1586-7a01-9000-d45e20995cf8 · slot 1 · generation 1

Validation:

  • Verified the clean frozen HEAD and exact patch. Reviewed all supplied comments; none contained unresolved technical concerns.

  • Isolation preflight passed. Native provenance verification matched 192 source inputs and 62 retained artifacts before execution.

  • Planner regression and ordered-state tests passed in rename-tests.jsonl. Receipt 1792071191586180248-2.json records overall exit 1 because the reviewer-added SQL probe had an unused import; that invocation did not execute SQL tests.

  • After correcting only the diagnostic overlay, SQL tests passed: both clause orders, quoted composite self-references, incoming/outgoing metadata, enforcement, rollback, ordered replacement/add-drop, and the existing self-reference catalog regression. rename-sql-v2.jsonl matches successful receipt 1792071258632899559-2.json.

  • The SQL package completed in 6.402 seconds; the added regression's scenario body took approximately 469 ms. Production overhead is one linear ALTER-option scan and small rename-SQL storage, with no additional catalog statements or SELECT/DML-path changes.

  • Reused frozen-head CI results showing successful Ubuntu UT, Linux/arm64 SCA, proxy BVT and pessimistic multi-CN BVT.

  • Command, source fingerprint, exit status, logs and artifact hashes were reconciled in /home/xupeng/.local/state/mo-bot/jobs/b8410dacc674ff359243ff7d/attempt-1/review-audit.json. Final audit receipt 1792071347552786990-2.json passed.

Limitations:

  • Full-suite and mo-tester runs were not repeated locally. Author-reported runs lack retained raw logs in the supplied packet; local behavioral checks and frozen CI provide independent coverage.

  • Multiple effective renames still encounter the unchanged TN old-name rejection. The diagnostic probe verified rollback preserved the original table/data and removed the attempted FK catalog changes.

  • The linked issue's standalone body was not supplied; its behavioral contract was assessed from the PR description and regressions. No throughput improvement is claimed.

@mergify mergify Bot added the queued label Oct 15, 2026
@mergify

mergify Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-15 13:39 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-10-15 15:22 UTC · at 6e2fd28ddf3fddba5769d87de3abf97051c8d797

This pull request spent 1 hour 42 minutes 44 seconds in the queue, with no time running CI.

Reason

Pull request #30298 has been dequeued

Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.

The author needs to enable "Allow edits from maintainers" on this pull request.

Hint

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.
If you do update this pull request, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Waiting for any of
  • check-neutral = CI Required
  • check-skipped = CI Required
  • check-success = CI Required
All conditions

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

This branch was previously deployed

1 inactive deployment
ci — 6e2fd28d Deployed Oct 15, 2026 by mergify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dequeued kind/bug Something isn't working size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants