[Bug]: CHANGE primary-key column exposes implicit PK part in secondary index DDL
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.
COPY ALTER CHANGE COLUMN on a single-column primary key destroys the implicit-PK alias marker stored in secondary-index parts. SHOW CREATE TABLE consequently exposes the PK as an extra user-declared index column, silently changing KEY ix_v(v) into KEY ix_v(v,id2).
Minimal reproduction
CREATE TABLE t(
id INT PRIMARY KEY,
v INT,
KEY ix_v(v)
);
INSERT INTO t VALUES(1,10),(2,20);
SHOW CREATE TABLE t;
-- KEY `ix_v` (`v`)
ALTER TABLE t ALGORITHM=COPY,CHANGE COLUMN id id2 INT;
SHOW CREATE TABLE t;
Actual final DDL:
CREATE TABLE `t` (
`id2` int NOT NULL,
`v` int DEFAULT NULL,
PRIMARY KEY (`id2`),
KEY `ix_v` (`v`,`id2`)
)
Expected final DDL:
CREATE TABLE `t` (
`id2` int NOT NULL,
`v` int DEFAULT NULL,
PRIMARY KEY (`id2`),
KEY `ix_v` (`v`)
)
The PK may remain an internal payload of the secondary index, but it must not become a new user-declared key part merely because the PK column was renamed with CHANGE.
Positive control
Pure RENAME preserves the declared index definition:
CREATE TABLE control(
id INT PRIMARY KEY,
v INT,
KEY ix_v(v)
);
INSERT INTO control VALUES(1,10),(2,20);
ALTER TABLE control ALGORITHM=COPY,RENAME COLUMN id TO id2;
SHOW CREATE TABLE control;
-- KEY `ix_v` (`v`)
Forced-index reads return both rows in both tables, so the reproduced defect is the persisted index metadata/regenerated DDL, not a claim of lost base rows.
Root cause
Ordinary secondary-index definitions append the table PK as an internal alias part (catalog.CreateAlias(pk)). During a renaming CHANGE, pkg/sql/plan/build_alter_change_column.go:359-368 resolves every alias and writes the plain new column name back into indexInfo.Parts:
partCol = catalog.ResolveAlias(partCol)
...
indexInfo.Parts[j] = newColName
The pure-RENAME implementation in build_alter_rename_column.go:132-160 explicitly preserves the alias marker. DDL regeneration in pkg/sql/plan/build_show_util.go suppresses only alias-marked implicit PK parts, so CHANGE makes the PK visible as an extra declared column.
Validation
The widened DDL and the pure-RENAME control were reproduced in two independent fresh-database runs, in addition to the initial discovery run. The results were identical in every run.
Duplicate check
Open and closed issue searches covered CHANGE COLUMN, primary-key rename, secondary-index alias parts, and unexpected PK columns in SHOW CREATE. No matching issue was found.
Closed #27658 concerns a stale public mo_indexes.PRIMARY column name after pure RENAME; this report instead concerns an existing secondary index's implicit alias part after CHANGE, while the pure-RENAME control is correct. Closed #26824 concerns user-created reserved alias names, and #32056/#32245 concern hidden-index data rather than SHOW CREATE alias suppression. Open #30256 covers renamed/added dependency binding but does not cover this existing-index metadata path.
- 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