Skip to content

fix(plan): support MySQL-compatible chained RENAME TABLE - #24470

Merged
mergify[bot] merged 5 commits into
matrixorigin:mainfrom
VioletQwQ-0:fix/chained-rename-table-24408
May 19, 2026
Merged

fix(plan): support MySQL-compatible chained RENAME TABLE#24470
mergify[bot] merged 5 commits into
matrixorigin:mainfrom
VioletQwQ-0:fix/chained-rename-table-24408

Conversation

@VioletQwQ-0

Copy link
Copy Markdown
Collaborator

What type of PR is this?

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

Which issue(s) this PR fixes:

issue #24408

What this PR does / why we need it:

Fix RENAME TABLE a TO tmp, b TO a, tmp TO b failing with table already exists — the standard MySQL atomic swap pattern used for zero-downtime ETL refreshes.

Root cause

buildRenameTable validated all rename pairs against the same catalog snapshot. For the 3-pair swap, pair 2 (b → a) checked whether a exists in the catalog — it does, because pair 1 (a → tmp) hasn't executed yet. The execution phase (Scope.RenameTable) already processes pairs sequentially, but requests never reached it.

Fix

Track rename effects across pairs during compilation by maintaining two maps:

  • removed: names that prior pairs renamed away (available as destinations)
  • nameMapping: names that prior pairs introduced → original table metadata

Three validation changes:

  1. Source resolve: if the name was introduced by a prior pair, use the tracked metadata (deep-copied with updated Name for execution compatibility); if removed, report NoSuchTable
  2. Destination check: skip catalog lookup if the name was removed by a prior pair; check nameMapping for conflicts from prior pairs
  3. Update maps after each pair processes

Verified scenarios

Scenario Result
3-pair atomic swap (a→tmp, b→a, tmp→b) ✓ data swapped correctly
2-pair rename (a→c, b→a)
Real conflict (x→y when y exists) ✓ still errors
Double-rename same source (m→x, m→y) ✓ errors on second pair
Non-existent source in chain ✓ errors

🤖 Generated with Claude Code

The binder's buildRenameTable validated all rename pairs against the
same catalog snapshot, so the standard 3-pair atomic swap pattern
(RENAME TABLE a TO tmp, b TO a, tmp TO b) failed with "table already
exists" on the second pair.

Track rename effects across pairs during compilation: maintain a
removed set and a nameMapping that records where each name moved.
Source resolution consults the mapping first; destination conflict
checks skip names that were already renamed away.

Fixes matrixorigin#24408

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@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 →

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

Review: support MySQL-compatible chained RENAME TABLE

Approve

The fix correctly identifies the root cause (validation against a static catalog snapshot) and resolves it with a clean two-map approach (removed + nameMapping). Source resolution and conflict detection both respect intermediate rename state, and the invariants are maintained correctly after each pair. Existing conflict detection and double-rename errors still work as expected.

Two non-blocking observations for follow-up:

  1. Cross-database renames — dstKey is built using the source schemaName rather than opt.Name.ToTableName().SchemaName, so RENAME TABLE db1.t TO db2.t chains would mismatch. This pre-exists the PR; worth a follow-up to extract the destination schema.

  2. Longer-chain and no-op test cases — chains of 4+ pairs and a-to-a no-ops are untested. Not blocking, but worth adding for robustness.

LGTM for the stated scope.

@mergify mergify Bot added the queued label May 19, 2026
@mergify

mergify Bot commented May 19, 2026

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • Entered queue2026-05-19 14:12 UTC · Rule: main
  • Checks passed · in-place
  • Merged2026-05-19 15:14 UTC · at e0030c5d1c9cb953cb17b89e81ee91067700c1e6 · squash

This pull request spent 1 hour 1 minute 24 seconds in the queue, including 1 hour 18 seconds running CI.

Required conditions to merge
  • #approved-reviews-by >= 1 [🛡 GitHub branch protection]
  • #changes-requested-reviews-by = 0 [🛡 GitHub branch protection]
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-decision = APPROVED [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-neutral = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-skipped = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / SCA Test on Ubuntu/x86
    • check-neutral = Matrixone CI / SCA Test on Ubuntu/x86
    • check-skipped = Matrixone CI / SCA Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-neutral = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-skipped = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
  • any of [🛡 GitHub branch protection]:
    • check-skipped = Matrixone Utils CI / Coverage
    • check-neutral = Matrixone Utils CI / Coverage
    • check-success = Matrixone Utils CI / Coverage

@mergify
mergify Bot merged commit 92f73d3 into matrixorigin:main May 19, 2026
23 of 24 checks passed
@mergify mergify Bot removed the queued label May 19, 2026
@VioletQwQ-0
VioletQwQ-0 deleted the fix/chained-rename-table-24408 branch May 20, 2026 06:52
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/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants