[Bug]: COPY ALTER ADD COLUMN FIRST makes MASTER-indexed rows invisible

Aperta
#33,316 0 commenti 0 reazioni 1 assegnatario Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@XuPeng-SH ci sta già lavorando.

Dal 26/11/2026.

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

kind/bug severity/s0

Description

Tested on MatrixOne main c0cef5c9cce2164fedd201c188bfffe4d2d09a96 (version() = 8.0.30-MatrixOne-v1.3.0, git_version() = c0cef5c), single CN.

After COPY ALTER inserts a column before existing columns, an unaffected MASTER index makes existing rows disappear from filtered queries. The base rows and hidden MASTER entries still exist, but the MASTER index join returns no matching rows.

Minimal reproduction

CREATE TABLE m(
  a VARCHAR(30),
  b VARCHAR(30),
  INDEX mi USING MASTER(a)
);
INSERT INTO m VALUES('x','payload');

SELECT a,b FROM m WHERE a='x';
-- Before ALTER: ('x','payload')

ALTER TABLE m ADD COLUMN lead INT DEFAULT 7 FIRST,ALGORITHM=COPY;

SELECT a,b FROM m WHERE a='x';
-- Actual: empty set
-- Expected: ('x','payload')

SELECT COUNT(*) FROM m WHERE a='x';
-- Actual: 0
-- Expected: 1

SELECT a,b FROM m IGNORE INDEX(mi) WHERE a='x';
-- Positive control: ('x','payload')

SELECT COUNT(*) FROM m IGNORE INDEX(mi) WHERE a='x';
-- Positive control: 1

The failure persists on a fresh connection. Two independent fresh-database reproductions produced identical results.

Positive controls and scope

  • An ordinary KEY ri(a) remains correct after the same ADD COLUMN ... FIRST.
  • A MASTER index remains correct when the new column is appended at the end instead of inserted before existing columns.
  • IGNORE INDEX(mi) returns the original row, proving that the base row was not lost.
  • Rebuilding the affected index with ALTER TABLE m ALGORITHM=COPY,MODIFY COLUMN a VARCHAR(40) makes the query return the row again.
  • Single-column and composite MASTER indexes, with and without an explicit primary key, reproduce the problem. Duplicate keys and duplicate complete rows were also covered.
  • The hidden MASTER entries remain present after ALTER; this is not physical loss of hidden-index rows.

Root cause

MASTER lookup keys include the source column's physical Seqnum:

  • pkg/sql/plan/apply_indices_master.go constructs lookup prefixes using serial_full(getColSeqFromColDef(...), value).
  • pkg/sql/plan/apply_indices.go:getColSeqFromColDef returns ColDef.Seqnum.
  • pkg/sql/compile/alter.go:cloneUnaffectedIndexes clones an unaffected index's old hidden entries without rewriting those keys.

ADD COLUMN ... FIRST changes the existing columns' physical sequence numbers in the replacement table. New queries therefore generate prefixes using the new sequence numbers, while the cloned MASTER entries still contain the old sequence numbers. Appending a column does not renumber existing columns, and MODIFY on an indexed column rebuilds the entries, explaining both positive controls.

Expected behavior

COPY ALTER must preserve MASTER-index query results for every existing row. If column renumbering requires MASTER entries to be rewritten, the unaffected-index clone path must rewrite them or rebuild the index; it must not publish an index that silently returns false-empty results.

Duplicate check

Open and closed searches covered USING MASTER with ALTER TABLE, MASTER with ADD COLUMN or ALGORITHM=COPY, serial_full, Seqnum, COPY ALTER FIRST, and MASTER wrong results. No matching issue was found.

This differs from #32245, which tracks missing ordinary/unique hidden-index entries: here the MASTER entries remain complete but their Seqnum key labels no longer match the replacement schema. It also differs from #32056 (stale composite-PK references in ordinary indexes), #33108 (FK-action index maintenance), and #25586 (MASTER LIMIT/OFFSET paging).

Lingua principale
Go
Stelle
1.9k
Fork
312
Merge medio
22h 59m
PR unite (30g)
736

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di matrixorigin/matrixone

Tutte le issue di matrixorigin/matrixone

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.