Repository navigation
fix: rebuild indexes when COPY ALTER changes primary keys - #32252
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? |
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
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.
🚫 Left the queue · pull request dequeued1 h 24 min in the queue, with no time running CI. So far
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.
To get back in the queue
Merge conditions not met when it left the queue
Tick the box to put this pull request back in the merge queue (same as
2 merge conditions met
Times in UTC · dashboard · how the merge queue works |
## 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]>
What type of PR is this?
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
4.2-dev counterpart: #32253.