Skip to content

fix: rebuild indexes when COPY ALTER changes primary keys (4.2) - #32253

Merged
XuPeng-SH merged 10 commits into
matrixorigin:4.2-devfrom
iamlinjunhong:issue-32056-4.2
Nov 10, 2026
Merged

XuPeng-SH merged 10 commits into
matrixorigin:4.2-devfrom
iamlinjunhong:issue-32056-4.2

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:

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.

@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: 5880f42a8bd2430cbbf1e512af0f03acf49baeaa

Review completed. Read the assessment.

XuPeng-SH pushed a commit that referenced this pull request Nov 5, 2026
## What type of PR is this?

- [x] BUG

## Which issue(s) this PR fixes:

- #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 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.

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

@aunjgr aunjgr 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.

Reviewed all 16 changed files at 5880f42. The COPY path now preserves primary-key impact across clauses, recognizes composite-key members, retains source lineage through chained changes, and only skips key dedup when the copied values are demonstrably unchanged. I also checked unaffected-index/fake-PK controls, conversion collisions, rollback and post-ALTER indexed DML/prepared-query oracles. No blocking findings.

Reused the exact-head green CI and assessed the supplied focused planner/SQL evidence; no redundant local suite run.

@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: 5880f42a8bd2430cbbf1e512af0f03acf49baeaa

Assessment: request_changes

The PK-impact accumulation and index-rebuild fix reuse the existing COPY planner coherently. One correctness gap remains: preserving replacement-column defaults now exposes a compiler precheck that can override the planner's source-aware PK dedup decision.

Model: gpt-6.1-sol / max

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

  • P1 pkg/sql/plan/build_alter_table.go:299: On a populated ordinary table with id INT PRIMARY KEY, run a COPY ALTER containing DROP PRIMARY KEY, DROP COLUMN id, ADD COLUMN id INT DEFAULT 8, MODIFY COLUMN id INT DEFAULT 8, ADD PRIMARY KEY(id). The new source-preservation behavior omits id from the copy projection, so every copied row receives 8. skipPkDedup correctly returns false here, but compile.getAlterCopyPkPrecheck only compares the old/new same-named column types.
    Impact: The compiler checks the old unique id values and sets SkipPkDedup=true again, also enabling pipeline flushing. Large copies written as persisted objects bypass the CN in-memory duplicate check, leaving the replacement PK values unchecked and permitting duplicate primary keys instead of rejecting and rolling back the ALTER. Preserve the source-identity/generated-value restriction through the compiler precheck; add a replacement-PK regression that exercises the persisted COPY path.
    Evidence: build_alter_modify_column.go:122 no longer restores the old id source; build_alter_table.go:372-394 omits absent sources. compile/alter.go:802-824 ignores replacement/source identity and :1013 promotes SkipPkDedup after checking old columns; :1253 enables pipeline flush. bind_insert.go:2060-2106 removes target PK dedup when this flag is true. disttae/txn.go:704 skips file-backed writes, and tae/txn/txnimpl/table.go:1189 skips persisted-source dedup under the default incremental policy (txnif/consts.go:78). source-probe-v2.log reproduces the mismatched planner/compiler decision for absent default and constant sources using extracted current functions; the unchanged-source control passes. This is an internal boundary probe, not an end-to-end SQL reproduction.

Validation:

  • Read the complete frozen delta, linked issue #32056 and its comment, and both discussion-index entries; traced planner clauses/source lineage, compiler precheck, insert dedup, index cloning/rebuild, and transaction failure paths.

  • Isolation preflight passed: preflight.log and checks/1793894169428786844-2.json.

  • Static audit passed at the assigned clean head: diff whitespace check and gofmt on all 10 changed Go files; static-audit.log and its matching check receipt.

  • Extracted-function counterexample executed with the supplied test-exec: source-probe-v2.log shows two expected invariant failures in compiler precheck selection and a passing unchanged-source control; source-probe/provenance.json pins the extracted owner files and adaptations. Matching check receipt records exit 1.

  • Focused planner suite was attempted via the repository CGo wrapper; it stopped before compilation because cgo/libmo.so is absent (planner-focused.log, checks/1793894184452338730-2.json). This is an environment/setup diagnostic.

  • Reconciled the PR body's reported focused planner/SQL passes (52/52 twice, 17/17 and 26/26) with the changed fixtures; these small-input cases do not exercise persisted replacement-PK COPY.

Limitations:

  • No fresh full SQL or persisted-object reproduction was run because the checkout lacks the native CGo prerequisite. The concrete finding rests on source tracing and an extracted internal predicate counterexample.

  • The supplied validation reports have no retained raw execution artifacts in local_validation. The reported full DDL directory run failed 20 comparisons and is not counted as a pass; the interrupted shutdown diagnostic and historical damaged cohorts remain outside the demonstrated repair scope.

@iamlinjunhong

Copy link
Copy Markdown
Contributor Author

Regarding review 5826323028 at 5880f42a8bd2430cbbf1e512af0f03acf49baeaa: the reported replacement-PK corruption path is blocked by an existing precheck condition that the extracted probe did not model.

  • The real engine's GetTableDef sets every source column's Typ.Table to its table name. Frontend Resolve preserves that metadata. A newly added/modified column's AST-derived type has an empty Table field.
  • alterCopyPkColumnValueUnchanged already compares oldTyp.GetTable() == newTyp.GetTable(). Consequently the replacement fails eligibility before source SQL is executed: getAlterCopyPkPrecheck returns no columns, SkipPkDedup stays false, and pipeline flush stays disabled. This guard is present at both the PR base and head.
  • A diagnostic Go overlay on the unmodified head recorded old.Table="t", new.Table="" for both default and constant DECIMAL replacements. DECIMAL(10,0) deliberately removes INT's additional AST/catalog scale mismatch. An extracted predicate probe with empty Table on both sides demonstrates a synthetic metadata state, not this resolved SQL path.

Fresh verification with Go 1.26.4 and the repository CGo wrapper on Darwin/arm64:

  • The exact INT scenario and a DECIMAL(10,0) variant each used 40,000 rows, explicitly flushed with mo_ctl('dn','flush',...). Both DEFAULT 8 and NOT NULL/constant-0 replacements returned MySQL 1062. SHOW CREATE, row count, distinct keys, key sum, and payloads remained unchanged; a subsequent INSERT and key lookup succeeded.
  • A real-planner/compiler check with engine-style source metadata covered default, constant, renamed and composite replacement keys. All retained target dedup, issued no source precheck SQL, and kept pipeline flush off; adding a PK on an unchanged original column retained the optimization.
  • Existing exact-head CI attempt 2 is green. The new focused checks do not claim a fresh Linux coverage run or execution of a persisted target write after the dedup rejection.

Under #32056's acceptance boundary, source preservation must keep COPY data and index references consistent. The reported trigger does not violate that boundary at this head, so this PR does not add speculative compiler hardening for the synthetic state. This is a refutation of the stated trigger, not a claim that hypothetical metadata variants have been repaired. No production changes were made; diagnostic fixtures/logs remain in the task evidence directory.

@XuPeng-SH

XuPeng-SH commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 5880f42a8bd2430cbbf1e512af0f03acf49baeaa

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: 5880f42a8bd2430cbbf1e512af0f03acf49baeaa

Assessment: request_changes

Withdraw the prior DROP/ADD/MODIFY finding: the author's metadata refutation is correct. A distinct chained-rename case preserves engine metadata while changing the copied PK source, allowing the compiler to validate the wrong column and disable target deduplication.

Model: gpt-6.1-sol / max

Session: 01a1a004-90c3-73b1-acc9-3d4636452003 · slot 0 · generation 0

  • P1 pkg/sql/plan/build_alter_rename_column.go:196: For an ordinary table t(id DECIMAL(10,0) PRIMARY KEY, src DECIMAL(10,0) NOT NULL, payload INT) containing repeated src values, execute: ALTER TABLE t DROP PRIMARY KEY, ADD PRIMARY KEY(src), DROP COLUMN id, RENAME COLUMN src TO mid, RENAME COLUMN mid TO id. The unsafe consequence applies when COPY writes objects under pessimistic incremental TN deduplication.
    Impact: The new mapping copies src into target id. Both types retain Table="t", so the compiler prechecks the unique original id values and enables SkipPkDedup and pipeline flushing. Object-backed writes bypass the remaining workspace and persisted-source checks, allowing duplicate target primary keys instead of rejecting the ALTER.
    Evidence: RENAME preserves type metadata at lines163-169. The candidate emits SELECT src; the baseline emitted nonexistent SELECT mid. The planner correctly retains target dedup, but compile/alter.go:812-821 ignores source identity and line1013 overrides that decision. reachability.md and attempt-1/source-probe-stdlib.log document matching Table metadata, different column identities and compiler eligibility=[id]. Require matching source-column identity before applying this optimization, and cover the chained-rename object-copy path.

Validation:

  • Reconciled all six discussion entries, accepting the author's original-trigger refutation and distinguishing the revised case.

  • Source/provenance/receipt audit passed: source-audit.log and checks/1794282314958401772-4.json, exit 0, clean frozen head.

  • Reused attempt-1/source-probe-stdlib.log and matching receipt 1794281267573502031-5.json: three controls passed; the chained-rename target-dedup invariant failed as expected.

  • Frozen CI records 14 successful checks, 13 skipped and two neutral; it does not establish execution of the revised case.

Limitations:

  • No public SQL or persisted-target reproduction was completed. The consequence is source-derived; the extracted probe models clause effects and uses field-subset types.

  • Native planner validation stopped before compilation because libmo.so was missing; the actual-protobuf probe timed out resolving modules. Author-reported Darwin diagnostics were not independently reproduced.

@XuPeng-SH

XuPeng-SH commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 63384fe9b2fbe95da545c611cb97f56ff659db4c

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: 63384fe9b2fbe95da545c611cb97f56ff659db4c

Assessment: approve

The COPY ALTER fix consistently tracks PK impact and source identity while reusing existing index dependency and plugin owners. Generated-value preservation and FK/schema retries cover the adjacent correctness paths. The withdrawn replacement-column report remains withdrawn; the distinct chained-rename concern is resolved. No actionable findings remain.

Model: gpt-6.1-sol / max

Session: 01a1a004-90c3-73b1-acc9-3d4636452003 · slot 0 · generation 0

Validation:

  • Reviewed the complete 37-file delta, affected owners/consumers, all eight discussion entries and linked issue #32056.

  • Local static audit passed: clean frozen HEAD, diff whitespace, gofmt on 30 Go files, complete protobuf/schema consistency, plugin-dispatch review and discussion coverage. Receipt: checks/1794306250220365324-4.json; log: review-audit.log.

  • Frozen-head CI records 14 successful checks, including UT, coverage, static analysis and proxy/pessimistic multi-CN BVT; 13 skipped and two neutral checks are not counted as passes.

  • Assessed attributed Linux race checks, repeated 37/190/17-case SQL comparisons, 6,000-row persisted duplicate rejection and controlled FK/RC interleavings, accounting for the GROUP BY rebase controls.

Limitations:

  • No local Go/SQL runtime suites were repeated; local_validation is empty and raw author execution logs were not supplied.

  • Successful forced remote COPY, full DDL-directory success, throughput gains and historical-corruption repair are not established by the supplied evidence.

@XuPeng-SH
XuPeng-SH merged commit 60e184e into matrixorigin:4.2-dev Nov 10, 2026
XuPeng-SH added a commit that referenced this pull request Nov 10, 2026
…2483)

## What type of PR is this?

- [x] BUG

## Which issue(s) this PR fixes:

Reverts #32253. Related to #32056.

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

Fully revert squash commit `60e184e9a6ceaeef2b2a08540856788e30ee3ff4`
after confirming a COPY ALTER FULLTEXT regression through real SQL. For
a two-row table with an INT primary key and FULLTEXT index, `ALTER TABLE
... ALGORITHM=COPY, MODIFY id INT NOT NULL, ADD extra INT DEFAULT 7`
duplicates every posting and changes the same MATCH relevance score from
`0.09061906` to `0.72495246`. The immediate pre-merge version keeps one
posting per term and preserves the score.

The COPY INSERT already maintains the affected plugin index; the later
ALTER plugin rebuild populates it again. This revert restores the exact
pre-merge tree while a focused correction is prepared separately.

This intentionally also removes the useful
primary-key/source/deduplication, generated-value, AUTO_INCREMENT and
foreign-key changes in #32253, along with that PR's tests. The original
#32056 behavior and other pre-existing COPY limitations return. It does
not repair indexes already affected by the regression, or resolve
inherited prefix-unique, cluster-table unique, or pending async-index
defects.

### Validation

- Full repository tree matches pre-merge parent
`ba5d0fd13f2a6f46f23bba615e11f6fe2b85899f` exactly; all 37 files from
#32253 are reversed without unrelated changes.
- Reused the real one-CN SQL comparison on that identical parent tree:
physical posting counts remain one and MATCH score remains `0.09061906`
after the operation. The corresponding merged-tree experiment duplicates
postings and changes the score.
- All six affected production packages passed normal and `-race` tests:
`pkg/defines`, `pkg/pb/pipeline`, `pkg/sql/colexec/preinsert`,
`pkg/sql/compile`, `pkg/sql/plan`, and `pkg/util/executor`.
- Changed Go files are gofmt clean; diff whitespace and `go vet` passed.
Repository molint completed with only existing recover diagnostics in
files unchanged by the revert. Configured incremental golangci-lint
passed with zero issues.
- CI has not yet run for this revert.
XuPeng-SH added a commit that referenced this pull request Dec 1, 2026
)

## What type of PR is this?

- [ ] API-change
- [x] BUG
- [x] Improvement
- [ ] Documentation
- [ ] Feature
- [x] Test and CI
- [x] Code Refactoring

## Which issue(s) this PR fixes:

Related to #32056 on `4.2-dev`. Replaces #32253 after #32483.

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

COPY ALTER on a composite primary key could leave secondary indexes with
old encoded locators; the earlier correction could also populate
FULLTEXT twice. Assign one population owner per replacement index, using
the final schema and source projection to decide whether to clone or
rebuild. Preserve generated values, foreign keys and stored
AUTO_INCREMENT zero values, and merge the target branch's ENUM domain
semantics into the shared proof. Format-specific snapshot reset remains
with the corresponding index plugin.

ISCP and CDC recovery use their existing task and transaction owners. A
stale ISCP owner cannot commit repair after a lease handoff or undo a
concurrent index retirement. Startup selects candidate keys outside the
fenced write transaction, repairs at most 128 per transaction, and
rescans before starting the worker. This avoids making a long catalog
scan part of every heartbeat conflict window. CDC catalog transitions
and daemon ownership changes commit together; cleanup retains ownership
of in-flight work until it finishes. See [the
design](docs/design/alter-copy-index-ownership-42.md).

A concurrent CDC restart can still conflict with a heartbeat. Direct
MySQL driver errors now retain their code, SQLSTATE and message; wrapped
or joined errors remain generic so an uncertain commit is not presented
as a known rollback. This change does not automatically replay a control
request. Callers should inspect task state before issuing a new request.
The managed recovery test restarts the same failed task after its
previous heartbeat expires; a separate two-CN test forces the actual
conflict and verifies rollback and a subsequent independent request.

COPY and allocator reconciliation share the same mapping of inherited
AUTO_INCREMENT columns. PREINSERT preserves stored zeros in those
columns and applies the initiating session’s SQL mode to newly promoted
columns. The pipeline carries the inherited names to remote workers.
Generated-to-ordinary conversion can retain a referenced materialized
key when its projected source, type and declared nullability match. Idle
watermark writes select only active completed generations and still
check the durable compare-and-swap result for every live job.

The removed protobuf field numbers and names remain reserved.

## Review follow-up on `f3f5c35`

That revision used `4.2-dev` at `4d84605`. CAGRA and IVF-PQ submit the
complete rebuild from the physical index definitions passed to CREATE,
ADD and foreground REINDEX. ISCP now commits that model and its source
cursor together. COPY builds the source and target projections in one
pass over the final schema and preserves the source row count when every
visible column is recomputed.

- On `7251508`, an embedded CN over MySQL registered both async
GPU-index jobs without source coverage and the single-column generated
COPY failed to parse. On the rebased head both jobs registered the
complete statement array and source coverage. COPY retained both
original hidden keys and recomputed both values. A generated-primary-key
collision rolled back, and the same ALTER succeeded with one row. The
DDL-only CPU harness linked the real GPU plugins and rolled back the
jobs before native execution. The stock CPU binary also passed its
unsupported-index control.
- The CPU initializer fault and retry test, physical table identity
checks, and all 28 inline/backfilled ENUM and YEAR index lookups from
the updated base passed. Focused race tests passed in `pkg/iscp`,
`pkg/util/fault` and `pkg/vectorindex/cuvs`. All four vector
compile-plugin packages passed.
- In a one-CPU ABBA microbenchmark of COPY projection construction, the
median at 128 columns fell from 90.3 to 14.7 µs. At 512 columns it fell
from 1.036 ms to 55.9 µs and from 65,544 to 49,152 bytes per operation.
The GPU fixture now deletes the closest row after the build transaction
acquires its source snapshot and compares indexed search with a forced
scan. Native NVIDIA execution is still pending.

## Validation

Head
[d1b748c](d1b748c)
is rebased onto `4.2-dev@167a1a9`. The control for this review was
the same rebased PR immediately before the fixes (`a7806d00a6`).

- A MASTER key includes the indexed column’s physical sequence number.
COPY ADD FIRST used to leave a row visible to a table scan and invisible
to a forced index lookup. The compiler checks the materialized sequence
numbers before cloning. On partitioned tables the destination leaves own
their data and use the existing MASTER bulk backfill. Forced and
independent scans now return the same rows after either moving or
appending a column.
- With two FKs from one child, changing the parent’s `DECIMAL(10,2)` to
`DECIMAL(10,1)` changed `-1.23` to `-1.2` on the control, leaving one
orphan. COPY now checks every referencing constraint against the final
column definition. It rejects that ALTER with 1833, preserves the old
value and leaves zero orphans. The existing INPLACE parent/child VARCHAR
widening behavior also passed.
- Nine distributed SQL scripts passed 1,015/1,015 checks in the
repository’s normal comparison mode. Both edited scripts also passed
116/116 with strict JDBC metadata comparison. Two older scripts have
eight existing JDBC display-width differences in strict mode, reproduced
on the control. Eight full CPU package suites, five targeted race
packages and five embedded integration tests passed, including an FK
added after planning, CDC restart and ISCP handoff. The
repository-pinned static analyzers passed all 37 CPU-buildable changed
Go packages. Both changed protobuf schemas reproduced their generated Go
files byte for byte.

**Earlier validation.** Revision `8320b1f4f2` was rebased onto `4.2-dev`
at `47e43f24a5`. Local validation used Go 1.26.4 on macOS arm64 with the
CPU native libraries.

- A live CN passed all 551 checks across the four COPY ALTER BVT files
(306) and the release branch's CHECK suite (245). Two prepared index
reads on another connection found the row after the composite
primary-key change, and the indexed UPDATE changed the base row. After
COPY, invalid UPDATE and duplicate-key UPDATE returned MySQL 3819,
preserved the generated value and the secondary-index entry, and a valid
update succeeded.
- A COPY that renamed an existing auto column and promoted an ordinary
column kept the stored zero and allocated IDs 1 and 2. With
`NO_AUTO_VALUE_ON_ZERO` the duplicate zero rolled the ALTER back. A
reused binary prepared INSERT also followed the session mode on each
execution.
- Both UNIQUE and primary generated parent keys could become ordinary
columns. Their stored values survived, valid child inserts succeeded,
and an invalid child or a value-changing parent expression was rejected.
- An overdue retired generation issued no watermark write while a live
generation committed. A stale live CAS rolled back and a retirement
during commit prevented stale in-memory publication. Normal tests passed
in 13 owning Go packages and race tests in 10. The embedded CPU
lifecycle suite covered snapshot retry, rollback, handoff, and both cuVS
providers' generated clear statements preserving relation IDs. The
merged protobuf schemas regenerated byte-for-byte. Repository err-check,
molint and incremental golangci-lint passed across 38 CPU-buildable
packages.
- CAGRA and IVF-PQ now share the snapshot SQL generator used by
foreground DDL and ISCP recovery. Both hooks previously panicked on
incomplete index definitions or missing or mistyped build settings. They
now return a diagnostic before returning any executable SQL and preserve
resolver cancellation. Across four valid configurations per algorithm
all 24 statements were byte-identical to the old providers. In a
seven-round, single-CPU comparison in the same binary, allocations per
call fell from 50 to 43. The median fell from 2.044 µs to 1.910 µs
(CAGRA) and 1.864 µs (IVF-PQ). These figures measure SQL generation.
- In the earlier source-mapping benchmark with 1,024 columns and one
auto column, the result went from 1,041 allocations and 182,000 bytes
per call to 2 allocations and 256 bytes. The median of five single-CPU
samples went from 98.7 to 5.61 µs.

Earlier validation on the release branch follows.

On Linux x86_64 with Go 1.26.4 and CPU native prerequisites:

- Complete `-race` package runs passed for `pkg/frontend`,
`pkg/sql/plan`, `pkg/sql/compile`, `pkg/iscp` and
`pkg/vectorindex/sqlexec`; taskservice's relevant changed tests were
also run with `-race`. The frontend and planner runs used test-only
overlays to relocate temporary outputs.
- Real embedded two-CN `-race` tests passed for CDC managed restart, CDC
lease/control conflicts and ISCP handoff. The ISCP case crosses the
128-key boundary, injects a healthy heartbeat during selection, and
makes another job active after the scan. Existing takeover and
concurrent-unregister checks remain. The public MySQL error response was
separately checked with an injected direct driver error; it is not a
reproduction of a public SQL conflict.
- One-CN public SQL tests covered COPY/index lifecycle, foreign-key
timing, CTAS policy, index-versus-scan results and rollback. CPU
CAGRA/IVF-PQ planner and compile-hook tests passed; an HNSW control
verified the GPU fixture's COPY/add-column SQL shape. The GPU fixture
now uses the supported BIGINT key.
- The merged protobuf source was regenerated and matched its Go output.
At `263b1a9a`, before the final ISCP and test changes,
repository-configured full `make static-check-analysis` passed. The
final affected packages passed gofmt, `go vet`, configured incremental
golangci-lint (0 issues), and the ISCP package and two-CN handoff
regression under `-race`.

## Performance, compatibility and remaining validation

On Linux x86_64, each side copied 100,000 rows on a local CN. The table
shows median ALTER milliseconds across six paired samples after warm-up,
alternating execution order. Every fixed index returned the same 100
matching keys as its base-table scan.

| COPY case | Control | Fixed | Forced-index matches, control → fixed |
| --- | ---: | ---: | ---: |
| Regular index, ADD FIRST | 48.9 | 51.5 | 100 → 100 |
| MASTER, append column | 55.7 | 48.5 | 100 → 100 |
| MASTER, ADD FIRST | 50.9 | 621.5 | 0 → 100 |
| Partitioned MASTER, append column | 227.6 | 582.9 | 0 → 100 |
| Partitioned MASTER, ADD FIRST | 204.3 | 544.2 | 0 → 100 |

The two controls with correct output retained the clone path. Rebuilding
adds real DDL work. The independent repeat of MASTER ADD FIRST and
partitioned MASTER append measured 825.2 ms and 688.9 ms on the fix,
with substantial run-to-run variation. Partitioned COPY scans each
replacement partition once per MASTER key part.

ISCP recovery temporarily materializes candidate keys and adds
recovery-only scans and bounded transactions; normal per-row SQL is
unchanged. A blocked batch or heartbeat overlapping a batch can still
delay or fail an attempt. CDC control conflicts remain visible to the
caller and a commit-phase error may have an uncertain outcome.

**Native CAGRA and IVF-PQ validation remains open.** A supported Linux
x86_64 NVIDIA environment is unavailable. The hardware test covers
native construction, atomic model and watermark publication, subsequent
CDC and indexed search for both algorithms. Its result is still
outstanding. [Native GPU review
finding](#32497 (review))

This targets a stopped 4.2 upgrade; old CN writers do not provide the
new ownership fences, and partitioned old writers or already-submitted
external sink operations are not fenced by local cancellation. Existing
unrelated limitations include pending IVF initialization during an
unrelated clone-eligible COPY and partition COPY child-index loss. ALTER
algorithm selection is unchanged.

This branch was successfully deployed

No deployments
ci — 17040f39 Deployed Nov 10, 2026 by XuPeng-SH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants