[Bug]: COPY ALTER ADD COLUMN FIRST makes MASTER-indexed rows invisible
Maintainers usually reply within 1 day
@XuPeng-SH is already working on this.
Since Nov 26, 2026.
Assessment
This issue has not been assessed yet.
Description
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 sameADD 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.goconstructs lookup prefixes usingserial_full(getColSeqFromColDef(...), value).pkg/sql/plan/apply_indices.go:getColSeqFromColDefreturnsColDef.Seqnum.pkg/sql/compile/alter.go:cloneUnaffectedIndexesclones 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).
- Dominant language
- Go
- Stars
- 1.9k
- Forks
- 312
- Avg merge
- 22h 59m
- Merged PRs (30d)
- 736
Getting set up
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from matrixorigin/matrixone
-
kind/bug
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
matrixorigin/matrixone#33363 ·
Maintainers usually reply within 1 day
-
kind/bug
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
matrixorigin/matrixone#33362 ·
Maintainers usually reply within 1 day
-
SLEEP rejects NULL and negative durations that MySQL acceptsPossibly taken @XuPeng-SH claimed this 7 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
matrixorigin/matrixone#32653 ·
Maintainers usually reply within 1 day
-
[Bug]: TestChangeWatchProxy loses its first tenant connection during PingContext in Ubuntu CIPossibly taken @XuPeng-SH claimed this today. Openkind/bug needs-triage
matrixorigin/matrixone#33371 · 1 assignee ·
Maintainers usually reply within 1 day
-
[Bug]: TestDaemonClaimSQLRoundTrip exhausts its shared deadline during the stale claim update in Ubuntu CIPossibly taken @XuPeng-SH claimed this today. Openkind/bug needs-triage
matrixorigin/matrixone#33370 · 1 assignee ·
Maintainers usually reply within 1 day
All issues in matrixorigin/matrixone
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
zalando/postgres-operator#3257 ·
Maintainers usually reply within 2 days
-
[inputs.internal] README lists go_version tag on internal_gather instead of internal_agentPossibly taken @cvas22 claimed this today. Open
Difficulty 1/5 Under an hour Newbie friendliness 90/100
influxdata/telegraf#20264 ·
Maintainers usually reply within 1 day
-
[Bug] Standalone migration breaks existing Ingress routes using the envoy-http Service port nameOpenaccepted bug wg/enterprise-environment
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
vllm-project/semantic-router#7483 · 1 comment ·
Maintainers usually reply within 1 day
-
needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
stacklok/toolhive-catalog#2076 ·
Maintainers usually reply within 1 day