[Bug]: COPY ALTER clauses after DROP PRIMARY KEY use a nil primary-key definition
Maintainers usually reply within 1 day
@matrix-meow 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.
Within one COPY ALTER, DROP PRIMARY KEY leaves CopyTableDef.Pkey=nil for subsequent clauses. Later clauses do not handle that valid intermediate keyless state consistently:
- RENAME or CHANGE of any visible column causes a recovered nil-pointer panic.
- Adding an ordinary secondary index is rejected with
primary key cannot be empty for secondary index.
These symptoms are reported together because they have the same trigger and invalid intermediate table state, although the two downstream consumers fail at different locations.
Problem 1: DROP PRIMARY KEY followed by RENAME/CHANGE panics
CREATE TABLE t(id INT PRIMARY KEY,v INT);
INSERT INTO t VALUES(1,10);
ALTER TABLE t ALGORITHM=COPY,
DROP PRIMARY KEY,
RENAME COLUMN v TO w;
Actual result:
Error 20101: internal error: panic runtime error: invalid memory address or nil pointer dereference
...
github.com/matrixorigin/matrixone/pkg/sql/plan.updateRenameColumnInTableDef
pkg/sql/plan/build_alter_rename_column.go:184
The CHANGE variant on a fresh table also panics:
CREATE TABLE t(id INT PRIMARY KEY,v INT);
INSERT INTO t VALUES(1,10);
ALTER TABLE t ALGORITHM=COPY,
DROP PRIMARY KEY,
CHANGE COLUMN v w INT;
Its top planner frame is buildColumnAndConstraint at pkg/sql/plan/build_alter_change_column.go:372.
The renamed column need not be a former PK part. Both statements should succeed and leave a keyless table containing id and w with the original row.
Clause-order positive controls
Both reverse-order statements succeed and produce the expected keyless table with column w:
ALTER TABLE t ALGORITHM=COPY,
RENAME COLUMN v TO w,
DROP PRIMARY KEY;
ALTER TABLE t ALGORITHM=COPY,
CHANGE COLUMN v w INT,
DROP PRIMARY KEY;
Problem 2: DROP PRIMARY KEY followed by ADD INDEX is rejected
CREATE TABLE t(id INT PRIMARY KEY,v INT);
INSERT INTO t VALUES(1,10),(2,20);
ALTER TABLE t ALGORITHM=COPY,
DROP PRIMARY KEY,
ADD INDEX ix_v(v);
Actual result:
Error 20101: internal error: primary key cannot be empty for secondary index
Expected result is a keyless table with a usable KEY ix_v(v) and both original rows.
Index positive controls
The equivalent transition succeeds when split into two statements:
ALTER TABLE t ALGORITHM=COPY,DROP PRIMARY KEY;
ALTER TABLE t ALGORITHM=COPY,ADD INDEX ix_v(v);
These controls also succeed:
DROP PRIMARY KEY, ADD UNIQUE KEY uk_v(v)in one statement;- creating an originally keyless table as
CREATE TABLE t(v INT,KEY ix_v(v))and reading throughix_v.
Thus an ordinary secondary index on the final keyless table is valid; the failure is specific to the same-statement intermediate state.
Root cause
pkg/sql/plan/build_alter_add_primarykey.go:102-129 implements DropPrimaryKey and ends with:
tableDef.Pkey = nil
Clauses are then applied sequentially. The RENAME and CHANGE implementations iterate primaryKeyDef.Names without a nil guard (build_alter_rename_column.go:180-194 and build_alter_change_column.go:371-377). Separately, getTablePriKeyName(nil) returns an empty string, and buildSecondaryIndexDef rejects that empty key instead of constructing the ordinary index using the final keyless-table representation.
Validation and expected behavior
Each failure was reproduced in two independent fresh-database runs, in addition to the initial discovery runs. All failed statements preserved the original schema and rows, and the connection remained usable (SELECT 42 succeeded).
COPY ALTER should maintain a consistent keyless intermediate representation after DROP PRIMARY KEY, or every later clause must handle it safely. Clause order must not choose between success, a recovered planner panic, and an internal error for equivalent valid schema transitions.
Duplicate check
Open and closed issue searches covered DROP PRIMARY KEY combined with RENAME, CHANGE, ADD INDEX, nil Pkey, the affected planner functions, and the exact secondary-index error. No matching issue was found for either symptom.
The nearest item, closed #30415, covers DROP PRIMARY KEY + DROP COLUMN in handleDropColumnWithPrimaryKey; it does not cover RENAME/CHANGE or ADD INDEX. Open #30256 tracks final-schema binding for renamed/added dependencies, but does not cover these post-DROP nil-Pkey and keyless ordinary-index paths. #32245 concerns missing hidden-index entries and is unrelated to these planning-time failures.
- 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