Repository navigation
revert: undo COPY ALTER index rebuild changes on 4.2-dev (#32253) - #32483
Merged
Merged
Conversation
…2) (matrixorigin#32253)" This reverts commit 60e184e.
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? |
4 of 7 tasks
Open
46 tasks
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
Which issue(s) this PR fixes:
Reverts #32253. Related to #32056.
What this PR does / why we need it:
Fully revert squash commit
60e184e9a6ceaeef2b2a08540856788e30ee3ff4after 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 7duplicates every posting and changes the same MATCH relevance score from0.09061906to0.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
ba5d0fd13f2a6f46f23bba615e11f6fe2b85899fexactly; all 37 files from fix: rebuild indexes when COPY ALTER changes primary keys (4.2) #32253 are reversed without unrelated changes.0.09061906after the operation. The corresponding merged-tree experiment duplicates postings and changes the score.-racetests:pkg/defines,pkg/pb/pipeline,pkg/sql/colexec/preinsert,pkg/sql/compile,pkg/sql/plan, andpkg/util/executor.go vetpassed. Repository molint completed with only existing recover diagnostics in files unchanged by the revert. Configured incremental golangci-lint passed with zero issues.