Skip to content

fix: rebuild indexes when COPY ALTER changes primary keys - #32252

Merged
XuPeng-SH merged 7 commits into
matrixorigin:mainfrom
iamlinjunhong:issue-32056-main
Nov 5, 2026
Merged

XuPeng-SH merged 7 commits into
matrixorigin:mainfrom
iamlinjunhong:issue-32056-main

Conversation

@iamlinjunhong

@iamlinjunhong iamlinjunhong commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • BUG

Which issue(s) this PR fixes:

What this PR does / why we need it:

COPY ALTER can reuse secondary indexes even when a composite primary key member changes, leaving index entries inconsistent with the rebuilt table. Track primary key impacts across ALTER clauses and rebuild affected indexes; preserve index copying for unrelated column changes. The regression coverage includes MODIFY, CHANGE, DROP, DML, prepared queries, collision rollback, and index consistency.

Validation and limitations

  • On the current main merged tree, the planner package build, vet, and full package tests passed on Darwin arm64. CI remains to run.
  • Before the upstream merge, SQL regression comparisons passed 52/52 twice and the full main ddl run passed (9249 total, 0 failures). The task patch is unchanged by the merge, but SQL and the full service build have not been rerun on the merged tree.
  • A prior shutdown diagnostic was interrupted before normal completion; its cause and relationship to workload timing remain unresolved. This change does not claim to fix that path or repair historical corrupt indexes.
  • Rebuilding affected indexes adds necessary work during relevant ALTER operations; unrelated indexes retain the copy optimization.

4.2-dev counterpart: #32253.

@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 Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: b56baf50c55ca807d0a781a2a64fc489f53e1261

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: b56baf50c55ca807d0a781a2a64fc489f53e1261

Assessment: approve

The fix recognizes composite primary-key membership and preserves key impact across ALTER clauses. It reuses existing index invalidation and rebuild machinery while retaining cloning for unaffected changes. No actionable defects found.

Model: gpt-6.1-sol / max

Session: 01a1a004-9884-72c0-ad39-f096c4209c4a · slot 1 · generation 0

Validation:

  • Reviewed the complete six-file delta, linked issue #32056 and both discussion items.

  • Reused frozen-head successful build, UT, SCA, coverage and proxy/pessimistic BVT results after checking planner and SQL case selection.

  • Local formatting, whitespace and source/discussion/SQL-pair audits passed; receipts and retained logs are reconciled in validation-ledger.json.

Limitations:

  • Local Go and SQL execution was not repeated. The author's detailed SQL counts predate the merge; exact-head CI was assessed separately.

  • Historical corrupt-index repair and the disclosed shutdown diagnostic are outside this fix.

@mergify mergify Bot added the queued label Nov 5, 2026
@mergify

mergify Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

🚫 Left the queue · pull request dequeued

1 h 24 min in the queue, with no time running CI.

So far

  • ✅ Entered the queue Thu 5 Nov, 15:08 · rule main · triggered by rule Automatic queue on approval for main
  • ⏹️ Testing stopped · in place
  • 🚫 Left the queue 16:32 · baf141d

Reason

Pull request #32252 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.

To get back in the queue

  • Push a change if one is needed: the pull request is queued again once its queue conditions match.
  • If no change is needed, tick the box below to queue it again as it is.

Merge conditions not met when it left the queue

  • any of · required by GitHub branch protection:
    • check-neutral = CI Required
    • check-skipped = CI Required
    • check-success = CI Required

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

  • Requeue this pull request
2 merge conditions met
  • #review-threads-unresolved = 0 · required by GitHub branch protection
  • github-review-approved · required by GitHub branch protection

Times in UTC · dashboard · how the merge queue works

@XuPeng-SH
XuPeng-SH merged commit 04b3cf3 into matrixorigin:main Nov 5, 2026
@mergify mergify Bot added dequeued and removed queued labels Nov 5, 2026
XuPeng-SH added a commit that referenced this pull request Nov 10, 2026
## What type of PR is this?

- [x] BUG

## Which issue(s) this PR fixes:

Related to #32056

## What this PR does / why we need it:

COPY ALTER can reuse secondary indexes even when a composite primary key
member changes, leaving index entries inconsistent with the rebuilt
table. Track primary key impacts across ALTER clauses, rebuild affected
indexes, and preserve source-column and deduplication behavior for the
4.2 implementation. Unrelated column changes retain index copying.
Regression coverage includes MODIFY, CHANGE, DROP, DML, prepared
queries, collision rollback, and index consistency.

The COPY path now verifies the original source-column identity before
allowing primary-key prechecks to skip target deduplication. It carries
one affected-index name set through cloning and plugin rebuilding, and
preserves materialized generated values, AUTO_INCREMENT zero, and
unchanged ENUM/SET representations when their source values can safely
be copied. If a generated value must change, dependent indexes are
rebuilt and incoming or self-referencing foreign keys are protected.
COPY retries rebuild the plan when a lock or refreshed schema
invalidates its earlier foreign-key view. Dropping one of several
foreign keys to the same parent retains the child reference until the
last key is removed. Unaffected indexes remain eligible for cloning.

Main counterpart: #32252.

### Validation and limitations

CI for the updated branch is pending.

- On Linux/amd64 with Go 1.26.6, all affected Go production packages
passed `-race`; incremental `gofmt`, `go vet`, and configured
`golangci-lint` passed.
- On 4.2-dev base `c8264f1`, `alter_copy_source_42`,
`alter_copy_primary_index`, and `alter_copy_dedup_42` passed normal
expected-result comparisons twice (37, 190, and 17 cases per run). This
covers generated columns, foreign keys, secondary indexes,
deduplication, and rollback.
- After rebasing onto `4ecdd9e` (which changes GROUP BY), the group and
compile packages passed `-race`. A public VARCHAR(3) PK precheck
accepted two distinct UTF-8 values with the same prefix and rejected
duplicate values with 1062 while retaining the source table.
- Controlled FK interleavings and safe-change controls passed under
`-race`; additional test-only barriers verified re-planning after the RC
snapshot was advanced. Multi-FK and self-referencing cases were also
exercised through SQL.
- A public SQL reproduction with 6,000 flushed source rows and scoped
small-object fault injection rejected duplicate target primary keys with
MySQL 1062 and preserved the source table. The original PR head
committed duplicate target keys for the same scenario.
- A two-CN public AUTO COPY test passed with the normal DDL placement on
the coordinator. Forcing the test-only multi-CN override bypassed that
DDL guard: the worker received the new field but failed to resolve the
uncommitted target (1146). The same forced test fails on clean 4.2-dev
base `c8264f1`; it does not demonstrate successful remote COPY.
- The earlier author validation on Darwin arm64 passed the then-current
planner package and focused SQL comparisons. The earlier full 4.2 ddl
run failed 20 cases, matching the clean upstream baseline case for case;
the full directory with a non-hidden resource path was not verified.
This is not a passing directory run.
- A prior shutdown diagnostic was interrupted before normal completion;
its cause and relationship to workload timing remain unresolved. This
change does not claim to fix that path or repair historical corrupt
indexes.
- Rebuilding affected indexes adds necessary work during relevant ALTER
operations; unrelated indexes retain the copy optimization. No
throughput benchmark is claimed. Normal cross-CN scheduling filters by
build commit ID; custom builds with empty or reused IDs do not establish
mixed-version isolation.

---------

Co-authored-by: XuPeng-SH <[email protected]>

This branch was successfully deployed

No deployments
ci — baf141df Deployed Nov 5, 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