Repository navigation
feat: support ALTER TABLE AUTO_INCREMENT - #26658
mergify[bot] merged 16 commits into
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? |
gouhongshen
left a comment
There was a problem hiding this comment.
Codex automated review
All prior blockers are fixed: stale allocator names and cache keys, combined rename/reset handling, CREATE and COPY epoch publication, CREATE AUTO_INCREMENT=0 sentinel preservation, and repeated owned-CREATE reset rollback/cache retirement. The latest repeated-reset explanation is consistent with the code and tests. One distinct COPY regression remains for newly added AUTO_INCREMENT columns.
P1 - [P1] Preserve the initial offset for newly added AUTO_INCREMENT columns (pkg/sql/plan/build_alter_table.go:133)
ALTER TABLE ... ADD COLUMN ... AUTO_INCREMENT is accepted by the planner and always uses COPY. This assignment clears the copied definition's offset, while the temporary CREATE still initializes a new auto column from the session auto_increment_offset. For a new column, mapCloneAutoIncrColumns has no source mapping, so on an empty source table copiedMax and sourceOffsets are zero; reconcileAlterCopyAutoIncrement then computes zero and force-resets the temporary allocator. For example, with auto_increment_offset=10, CREATE TABLE t(a INT), and ALTER TABLE t ADD COLUMN c INT AUTO_INCREMENT, the first insert into empty t starts c at 1 here, whereas the base implementation preserved offset 9 and started at 10. Preserve the correct fresh/session initialization for new columns without inheriting stale state from dropped or reused identities, and add a regression test.
|
Addressed the fresh COPY-member initialization blocker in Root cause: a newly added AUTO_INCREMENT member has no source mapping. For an empty source, COPY reconciliation interpreted the absent mapping plus The fix now preserves that CREATE-owned allocator only for the exact tuple Regression coverage:
Validation on the exact pushed head:
The distributed BVT was authored but not executed locally; the new exact-head CI run is in progress. |
gouhongshen
left a comment
There was a problem hiding this comment.
Codex automated review
All prior blockers—stable column identity, rename/cache consistency, transaction and COPY epoch fencing, CREATE=0, repeated-reset rollback, and fresh-column initialization—are fixed. No independent blocking or non-blocking finding remains.
|
Addressed the old-head Proxy BVT failures and the
Fresh local validation on the rebased content:
The new exact-head CI is running. In particular, Proxy BVT and the aggregate Coverage check remain pending and are not claimed as passed yet. Please re-review this head. |
|
Follow-up on exact head The first
Both stopped while compiling The table-dump restore now forwards the already resolved stable Fresh validation:
The failed BVT jobs were deterministic compile failures, not SQL failures, and were not rerun on the superseded head. Fresh CI is expected on |
|
Fixed the exact-head Proxy BVT failure and rebased onto the latest Root cause:
Fix:
Validation on exact local head
The previous UT Coverage failures were also checked: the untouched Exact-head CI result:
There are no unresolved review threads. Re-review has been requested from |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Reviewed exact head b4192062d7b40c4fc49c18560b97ba73b7fd0d2e. The rename/stable-index blocker and the latest COPY hidden-column index mismatch are fixed; exact-head CI is green, and the full local incrservice, sql/compile, sql/plan, table_clone, and frontend suites pass. One blocking statement-lifecycle gap remains for partitioned tables.
AlterTable applies an ordinary ALTER to the logical table first through s.doAlterTable(c), then expands qry.RawSQL across the physical partition tables with repeated c.runSql(sql) calls. However, doAlterTable creates and finishes its own alterAutoIncrementResetCleanup. Therefore, after the logical-table reset (and after each earlier nested partition ALTER) returns successfully, its cleanup has already observed statementErr == nil and will never discard that transaction-private allocator reset. If a later partition ALTER fails, the outer ALTER returns an error and the workspace rolls back the SQL statement, but the logical-table/earlier-partition entries in incrservice.mu.private remain authoritative until the transaction closes. A subsequent INSERT in the same explicit transaction can allocate from the failed ALTER's offset even though its catalog/store changes were rolled back. The same leak repeats for every successful partition before the failing one.
Please make reset cleanup owned by the complete user-visible ALTER statement, not by each prematurely successful sub-ALTER. All reset table IDs installed by the logical table and nested partition executions must be registered with one outer failure boundary (or the allocator service must participate directly in statement rollback). Add a deterministic partitioned AUTO_INCREMENT regression with at least two partitions: inject failure on a later physical ALTER, roll back the failed statement while keeping the transaction open, then prove the logical table and every earlier partition discarded their private reset and the next implicit INSERT follows the pre-ALTER allocator state. Also cover cancellation at that same boundary.
This is not exercised by the current successful partition/BVT paths; it is the partial-success edge created by composing per-subcall cleanup with a multi-relation statement.
|
Addressed XuPeng-SH's statement-boundary cleanup CR in Changes:
Regression coverage:
Validation on the pushed content:
Local mo-tester/BVT runtime is unavailable, so the authored BVT execution remains gated by this exact head's CI. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Approved on exact head a125cff078ce3e7ea0b81d28bd22068d03614e84.
The latest change closes my previous partitioned-ALTER lifecycle blocker at the correct ownership boundary: one outer cleanup now spans the logical table plus all successful physical partition sub-alters. A later error or cancellation discards the complete successful prefix, while a failing nested sub-alter still cleans up its own reset. Cleanup uses a non-cancelled context, and the success path preserves the transaction-owned reset until commit.
I rechecked the ownership and failure/cancellation paths, including repeated reset/cache restoration behavior, and found no new correctness, performance, or unhappy-path blocker. Exact-head focused tests passed, as did 20 repetitions under the race detector for both the partition statement-boundary cleanup and real next-implicit-allocation restoration tests. Current CI is green.
Merge Queue Status
This pull request spent 5 minutes 37 seconds in the queue, with no time running CI. ReasonThe pull request can't be updated
HintYou should update or rebase your pull request manually. If you do, this pull request will automatically be requeued once the queue conditions match again. Requeued — the merge queue status continues in this comment ↓. |
aunjgr
left a comment
There was a problem hiding this comment.
Reviewed the exact head, including stable allocator identity, epoch fencing, rollback and cancellation cleanup, COPY reconciliation, and the outer cleanup spanning logical and partition ALTERs. The previously reported partition atomicity gap is closed. I found no remaining blocking issue.
# Conflicts: # pkg/pb/plan/plan.pb.go
Merge Queue Status
This pull request spent 43 minutes 48 seconds in the queue, including 43 minutes 24 seconds running CI. Required conditions to merge
|
What type of PR is this?
Which issue(s) this PR fixes:
issue #23143
What this PR does / why we need it:
Adds the final SQL planner/compiler entry point for
ALTER TABLE ... AUTO_INCREMENT = Non top of the already merged transactional allocator reset, COPY/CLONE reconciliation, epoch fencing, and mixed-version capability gate.Changes:
Nas the next value and stores allocator offsetN-1without unsigned underflow;(table_id, col_index)identity so an INPLACE column rename cannot turn a later reset into a silent no-op;Non-goals:
Validation:
GOWORK=off go list ./pkg/sql/plan ./pkg/sql/compile ./pkg/incrservice ./pkg/sql/colexec/table_clone ./pkg/vm/engine/disttaeGOWORK=off go build ./pkg/sql/plan ./pkg/sql/compile ./pkg/incrservice ./pkg/sql/colexec/table_clone ./pkg/vm/engine/disttaeGOWORK=off go vet ./pkg/sql/plan ./pkg/sql/compile ./pkg/incrservice ./pkg/sql/colexec/table_cloneGOWORK=off go test ./pkg/sql/plan ./pkg/sql/compile ./pkg/incrservice ./pkg/sql/colexec/table_clone ./pkg/vm/engine/disttae -count=1go test ./pkg/incrservice ./pkg/sql/compile ./pkg/sql/colexec/table_clone ./pkg/vm/engine/testGOWORK=off go test -race ./pkg/incrservice ./pkg/sql/compile -count=1git diff --checkPASS review=PASS validation=PENDINGonfe20c9ab2f8fc5fa2b59d9b6ae27835132230262test/distributed/cases/auto_increment/auto_increment.sql, includingRENAME COLUMN→ reset → insert; current exact-head CI is pending00b4bf708599724afc48711e1b03fda9eda5141a: CI run30844457239passed both Proxy multi-CN job91789323459and Pessimistic standalone job91789323542; this is historical evidence, not the current exact-head gate.fe20c9ab2f8fc5fa2b59d9b6ae27835132230262.QA required: yes — production SQL is covered by BVT, but the final restart, rolling-upgrade, old/new CN/TN, and multi-CN stale-cache acceptance matrix remains pending. The issue link must be changed to
Fixes #23143only after that closing gate is complete.