Repository navigation
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? |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Request changes — two merge blockers remain.
- High: COPY reconciliation treats the hidden fake primary key as a user AUTO_INCREMENT column and breaks unrelated ALTER TABLE statements.
constructTableClone iterates every column with Typ.AutoIncr and now runs SELECT MAX(column) against the source table. MatrixOne's __mo_fake_pk_col is Hidden + AutoIncr, but it is not SQL-visible. Therefore a COPY-based ALTER on a table without a user primary key attempts to query MAX(__mo_fake_pk_col) and fails with:
invalid input: column __mo_fake_pk_col does not exist
This is deterministic in the current CI, not flaky: the standalone PESSIMISTIC, standalone multi-CN PROXY, and compose PESSIMISTIC jobs all show the same error, including ordinary statements such as ALTER TABLE pri01 ADD CONSTRAINT PRIMARY KEY(col1). One BVT file alone then cascades into 72 failed assertions.
Please fix this as a classification/ownership issue rather than only suppressing this one query. The planner already distinguishes user-visible AUTO_INCREMENT columns (AutoIncr && !Hidden), but both source maximum collection and destination reconciliation need the same contract. updateDstAutoIncrColumns currently calls GetAutoColumnFromDef, which intentionally includes hidden allocator columns, so merely skipping the source query is insufficient: a table containing both a visible AUTO_INCREMENT column and an internal hidden allocator column could still apply the user's requested offset to the hidden column. Preserve/rebuild internal fake-PK allocator state separately, and apply ALTER ... AUTO_INCREMENT reconciliation only to the user-visible column(s).
Please add regressions for at least:
- a hidden-fake-PK-only table undergoing an unrelated COPY ALTER (no internal
MAX(__mo_fake_pk_col)query and ALTER succeeds); - a definition containing both a visible AUTO_INCREMENT column and a hidden allocator column (the request affects only the visible column);
- the existing requested-offset-vs-copied-maximum cases after that separation.
The new focused tests currently pass because their synthetic table definitions contain only a visible AUTO_INCREMENT column, which is exactly why they miss this production table category.
- The PR introduces staticcheck failures and cannot pass SCA.
Current head reports:
pkg/incrservice/private_table_cache.go:132: SA4004, theforloop is unconditionally terminated;pkg/vm/engine/tae/logtail/mgr.go:290: SA4011, ineffectivebreak(it only exits theswitch, and the following condition performs the actual loop exit).
Please remove the dead/redundant control flow and rerun SCA. These are straightforward, but they are introduced by this PR and the current SCA job fails on them.
I rechecked the core AUTO_INCREMENT paths: lower-than-existing-max reconciliation, transaction-private rollback cleanup, copied-row maximum reconciliation, quoted identifiers, and table-version fencing are materially improved from the previous revision. The blocker above is a missed system category at the COPY boundary, not a rejection of the overall design.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Request changes on two common-path data-correctness issues. These are independent of 2PC/recovery. The previous hidden-column classification and SCA blockers appear fixed, and the epoch plumbing is a meaningful improvement, but the following invariants are still not closed.
[P1] COPY ALTER mixes source and destination column-index coordinate systems
buildTableCloneMeta records both the source data maxima and allocator offsets by source col_index (pkg/sql/compile/operator.go:2285-2296,2303-2337). updateDstAutoIncrColumns later looks up those maps using the destination AutoColumn.ColIndex (pkg/sql/colexec/table_clone/table_clone.go:542-553). A COPY ALTER that drops, adds, or reorders a column before the auto-increment column changes that index.
Minimal counterexample:
- Source schema is
(x INT, id BIGINT AUTO_INCREMENT PRIMARY KEY), soidhas source index 1; source max is 200 and allocator offset is 250. ALTER TABLE ... DROP COLUMN x, AUTO_INCREMENT = 100takes the COPY path;idnow has destination index 0 and the requested offset is 99.- The source maps contain key 1, but the destination lookup reads key 0, so both source safeguards become zero and the code calls
SetOffset(..., "id", 99, ...)instead of 250. - A later generated value can collide with copied data. The hidden
__mo_fake_pk_colallocator has the same identity problem when its index moves.
I reproduced this deterministically at the exact PR head: a focused unit test expected offset 250 and gomock observed 99. Please carry a stable source-to-destination identity/mapping through TableCloneCtx (including rename semantics) rather than using positional indices across schemas. Cover drop/add/reorder/rename before a visible AUTO_INCREMENT column and before the hidden fake-PK column.
[P1] Legacy CN writes silently bypass the epoch fence after ALTER
Both setAutoIncrEpochDependency and registerWriteAutoIncrEpoch return success when AutoIncrEpochKnown == false (pkg/vm/engine/tae/rpc/handle.go:419-442). The test in pkg/vm/engine/tae/rpc/rpc_test.go:84-93 explicitly codifies that the same legacy V0 write is accepted after the table epoch advances.
That is not a safe rolling-upgrade boundary. An old CN can retain a preallocated AUTO_INCREMENT range from before the ALTER; the DDL lock prevents overlapping statements but does not invalidate that private range on every legacy CN. After the ALTER commits, the old CN can generate from the stale range, send Known=false, and TN accepts the write without checking the advanced epoch. This defeats the fence on ordinary 1PC writes and can commit values below the reset point or duplicate existing values.
Please make mixed-version behavior fail-safe: for example, capability-gate ALTER TABLE ... AUTO_INCREMENT until all writers support epochs, reject unknown-epoch user writes once the table has entered the fenced epoch regime, or provide a synchronous cluster-wide invalidation protocol with an equivalent correctness proof. Add a mixed-version test with a stale legacy CN allocation before ALTER and a write after ALTER; accepting Known=false must not be the success criterion.
Validation performed on bdcaba31648a7452aceec6e37e41ad20223be991
- Existing tests passed for
pkg/incrservice,pkg/sql/colexec/table_clone,pkg/sql/compile,pkg/sql/plan,pkg/vm/engine/disttae, andpkg/vm/engine/tae/rpc. - Race tests passed for
pkg/incrserviceandpkg/sql/colexec/table_clone. go vetpassed for the directly affected SQL/increment packages;make err-checkandgit diff --checkpassed.- Required CI is green, but its matrix does not exercise schema-index remapping, and the legacy-CN test currently asserts the unsafe outcome.
I did not find a new blocking leak, deadlock, or unbounded-growth issue in the normal paths. The request-changes decision is specifically about the two reproducible correctness gaps above.
gouhongshen
left a comment
There was a problem hiding this comment.
Codex automated review
No blocking correctness, compatibility, concurrency, resource-handling, performance, or test-coverage regressions found in the PR diff. The reviewed CI checks are successful.
What type of PR is this?
Which issue(s) this PR fixes:
issue #23143
What this PR does / why we need it:
Make
ALTER TABLE t AUTO_INCREMENT = Nwork, updating the starting offset for auto-increment columns.Changes across five layers:
api.proto,plan.proto): newAlterKind_UpdateAutoIncrementenum,AlterTableAutoIncrementmessage, and oneof fieldsbuild_ddl.go,build_alter_table.go,deepcopy.go): handleTableOptionAutoIncrementin both inplace and copy paths; offset = Value - 1; explicit error when table has no AUTO_INCREMENT columncompile/ddl.go,api.go): buildUpdateAutoIncrementrequest (engine no-ops), then post-processing callsincrservice.SetOffsetto update the offsetservice.go,types.go,store_mem.go,store_sql.go): newSetOffsetinterface and implementations with never-decrease guarddisttae/txn_table.go,tae/catalog/schema.go,tae/txn/txnimpl/table.go): whitelistAlterKind_UpdateAutoIncrementto avoid panic on unknown kind