Skip to content

revert: undo COPY ALTER index rebuild changes on 4.2-dev (#32253) - #32483

Merged
XuPeng-SH merged 1 commit into
matrixorigin:4.2-devfrom
XuPeng-SH:codex/revert-32253-42
Nov 10, 2026
Merged

XuPeng-SH merged 1 commit into
matrixorigin:4.2-devfrom
XuPeng-SH:codex/revert-32253-42

Conversation

@XuPeng-SH

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • 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 fix: rebuild indexes when COPY ALTER changes primary keys (4.2) #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
XuPeng-SH requested a review from aunjgr as a code owner November 10, 2026 12:56
@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 →

@mergify mergify Bot added the kind/bug Something isn't working label Nov 10, 2026
@matrix-meow matrix-meow added the size/XL Denotes a PR that changes [1000, 1999] lines label Nov 10, 2026
@XuPeng-SH
XuPeng-SH merged commit a7bc200 into matrixorigin:4.2-dev Nov 10, 2026
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 — c8f35826 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.

2 participants