Repository navigation
fix: support ADD INDEX in COPY ALTER TABLE - #29052
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? |
59620ff to
37b940e
Compare
37b940e to
16454ed
Compare
XuPeng-SH
left a comment
There was a problem hiding this comment.
REQUEST_CHANGES at exact head 16454ed.\n\n[P2] Bind newly added indexes before validating dependent self-referencing foreign keys.\n\nIn pkg/sql/plan/build_alter_table.go:495-507, pending indexes are materialized after addAlterCopyForeignKeys runs at line 438. Consequently, finalTableDef lacks UNIQUE indexes introduced by the same COPY ALTER statement.\n\nConcrete input:\n\nCREATE TABLE t (\n id INT PRIMARY KEY,\n parent_code INT,\n ref_code INT\n);\n\nALTER TABLE t\n ADD COLUMN note INT,\n ADD UNIQUE INDEX uk_parent(parent_code),\n ADD CONSTRAINT fk_self\n FOREIGN KEY (ref_code) REFERENCES t(parent_code);\n\nEven with an empty table, addAlterCopyForeignKeys -> checkFkColsAreValid -> selectForeignKeyReferencedIndex cannot find uk_parent and returns a failed-to-add-FK error before index planning. Reordering the SQL clauses does not avoid this internal ordering.\n\nMove pending-index materialization before foreign-key binding, after column mutations. Add planner tests for both clause orders and a public SQL regression proving successful creation and subsequent FK enforcement.\n\nThe previous teardown concern is addressed: exact-head CI ran the case 71/71, and the supplied same-instance rerun/cleanup evidence was reviewed. No additional confirmed blocker was found.\n\nReviewed exact head: 16454ed
16454ed to
cfdef0c
Compare
|
Addressed the new COPY ALTER review finding in cfdef0c. Pending indexes are now materialized before foreign-key binding, so a self-referencing FK can use a UNIQUE index added by the same ALTER regardless of clause order. Added planner coverage for both orders and a distributed SQL regression that verifies successful creation, valid inserts, FK rejection, and teardown. Local validation: pkg/sql/plan and pkg/sql/compile passed; the exact BVT passed 78/78; go vet and golangci-lint passed with 0 issues. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
APPROVE at exact head cfdef0c.\n\nThe previous P2 is resolved: pending indexes are materialized before foreign-key binding against the final COPY schema. Planner tests cover both UNIQUE/FK clause orders with newly added columns, and the SQL regression verifies successful creation and subsequent FK enforcement.\n\nReviewed index dispatch, COPY insert versus plugin rebuild ownership, hidden-table handling, rollback/retry, ISCP/CDC and index-update teardown, and generated protobuf consistency. No P0/P1/P2 blockers remain. Exact-head BVT passed 78/78 with no failures, skips, or abnormal results. Coverage percentage was not used as a gate.\n\nReviewed exact head: cfdef0c
Merge Queue Status
This pull request spent 6 minutes 49 seconds in the queue, with no time running CI. Waiting for any of
All conditions
ReasonPull request #29052 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.
HintYou 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. Tick the box to put this pull request back in the merge queue (same as
|
What type of PR is this?
Which issue(s) this PR fixes:
issue #28052
What this PR does / why we need it:
COPY ALTER rejected statements that combined column changes with ADD INDEX clauses. This change:
Validation:
.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=20m ./pkg/sql/plan ./pkg/sql/compilego vet ./pkg/sql/plan ./pkg/sql/compilewith the repository CGO environmentmake -j8 buildgenerated_column.sql: 325/325 statements passedalter_table_algorithm_lock.sql: 21 passed, 5 pre-existing ignored, 0 failed