[Bug]: COPY CHANGE/RENAME COLUMN leaves stale foreign-key column names in catalog
Maintainer thường phản hồi trong vòng 1 ngày
@matrix-meow đang làm issue này rồi.
Từ ngày 27/11/2026.
Đánh giá
Issue này chưa được đánh giá.
Mô tả
Description
Tested on MatrixOne main c0cef5c9cce2164fedd201c188bfffe4d2d09a96 (version() = 8.0.30-MatrixOne-v1.3.0, git_version() = c0cef5c), single CN, with the default lower_case_table_names=1.
COPY CHANGE COLUMN and RENAME COLUMN can succeed while leaving the old child and parent column names in mo_catalog.mo_foreign_keys. The stale text is visible through information_schema.KEY_COLUMN_USAGE.
The two entry points have the same root cause: the initial FK catalog rows contain normalized column names, but the rename updates use an exact equality predicate with a differently spelled old name.
Minimal reproduction: CHANGE with a differently cased old reference
CREATE TABLE p(
id INT PRIMARY KEY,
v INT UNIQUE
);
CREATE TABLE c(
id INT PRIMARY KEY,
v INT,
CONSTRAINT fk_c FOREIGN KEY(v) REFERENCES p(v)
);
INSERT INTO p VALUES(1,10);
INSERT INTO c VALUES(1,10);
ALTER TABLE c CHANGE V cv INT,ALGORITHM=COPY;
ALTER TABLE p CHANGE V pv INT,ALGORITHM=COPY;
SELECT COLUMN_NAME,REFERENCED_COLUMN_NAME
FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
WHERE CONSTRAINT_SCHEMA=DATABASE()
AND CONSTRAINT_NAME='fk_c';
Actual result:
v | v
Expected result:
cv | pv
Both ALTER statements succeed, and the visible columns really are cv and pv. Running only the child-side or only the parent-side ALTER leaves the corresponding side of the catalog row stale.
RENAME entry point
The same defect occurs when the original declaration used mixed case:
CREATE TABLE p2(id INT PRIMARY KEY,V INT UNIQUE);
CREATE TABLE c2(
id INT PRIMARY KEY,
V INT,
CONSTRAINT fk_r FOREIGN KEY(V) REFERENCES p2(V)
);
ALTER TABLE c2 RENAME COLUMN V TO cv,ALGORITHM=COPY;
ALTER TABLE p2 RENAME COLUMN V TO pv,ALGORITHM=COPY;
SELECT COLUMN_NAME,REFERENCED_COLUMN_NAME
FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
WHERE CONSTRAINT_SCHEMA=DATABASE()
AND CONSTRAINT_NAME='fk_r';
Actual result is again v | v; expected is cv | pv.
Positive controls and impact boundary
These controls update both catalog names correctly:
CHANGE v cv INTwhen the declared old name is lowercasev;RENAME COLUMN v TO ...after an all-lowercase declaration.
Thus COPY/FK renaming is not generally broken. SHOW CREATE TABLE also displays the new column names and the FK over cv/pv, and the base rows remain intact.
The observed defect is limited to the textual FK catalog metadata. It must not be characterized as lost FK enforcement: after the stale catalog result, orphan child inserts still fail with 1452, deleting a referenced parent row still fails with 1451, and legal child inserts still succeed.
Root cause
Initial FK creation stores normalized column names in mo_foreign_keys.column_name and refer_column_name. COPY rename subsequently calls getSqlForRenameColumn in pkg/sql/plan/build_dml_util.go, whose updates require exact matches:
... WHERE ... AND column_name = <oldName>
... WHERE ... AND refer_column_name = <oldName>
However:
- CHANGE passes the parser-spelled
oldColNameOriginfrompkg/sql/plan/build_alter_change_column.go; in the first reproduction this isV, while the catalog containsv. - RENAME passes
oldCol.OriginNamefrompkg/sql/plan/build_alter_rename_column.go; after the mixed-case declaration this is alsoV, while the catalog containsv.
The ID-based table definition, SHOW CREATE, and DML enforcement therefore advance to the new schema even though the textual catalog update matches zero rows. information_schema.KEY_COLUMN_USAGE reads those stale catalog strings directly.
Validation
Both CHANGE and RENAME cases, their child/parent variants, lowercase positive controls, fresh-connection reads, SHOW CREATE, base rows, and FK enforcement were checked in two independent fresh-database runs. The results were identical.
Duplicate check
Open and closed issue searches covered KEY_COLUMN_USAGE, REFERENCED_COLUMN_NAME, mo_foreign_keys, CHANGE/RENAME COLUMN, case normalization, and stale FK column names. No matching issue was found.
Open #30256 covers final-schema binding for multi-clause COPY/INPLACE ALTER; each reproduction here has one column clause and fails because of the old-name source used by the FK catalog update. Closed #26328 concerns table IDs/reference topology during DATABASE CLONE, while this report has correct ID-based definitions and enforcement. #31362 and #31659 concern other FK/constraint-name metadata and do not own this path.
- Ngôn ngữ chính
- Go
- Star
- 1.9k
- Fork
- 312
- Merge trung bình
- 22 giờ 59 phút
- Pull request đã merge (30 ngày)
- 736
Chuẩn bị môi trường
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của matrixorigin/matrixone
-
kind/bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
matrixorigin/matrixone#33363 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
kind/bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
matrixorigin/matrixone#33362 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
SLEEP rejects NULL and negative durations that MySQL acceptsCó thể đã có người làm @XuPeng-SH đã nhận 7 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
matrixorigin/matrixone#32653 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug]: TestChangeWatchProxy loses its first tenant connection during PingContext in Ubuntu CICó thể đã có người làm @XuPeng-SH đã nhận hôm nay. Đang mởkind/bug needs-triage
matrixorigin/matrixone#33371 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug]: TestDaemonClaimSQLRoundTrip exhausts its shared deadline during the stale claim update in Ubuntu CICó thể đã có người làm @XuPeng-SH đã nhận hôm nay. Đang mởkind/bug needs-triage
matrixorigin/matrixone#33370 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của matrixorigin/matrixone
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
pg-sharding/spqr#3314 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 80/100
slavakurilyak/awesome-ai-agents#1051 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 73/100
google-gemini/gemini-api-cli#247 ·
Maintainer thường phản hồi trong vòng 1 ngày