[Bug]: COPY ALTER DECIMAL parent key to UNSIGNED leaves persistent incoming-FK orphans
I maintainer di solito rispondono entro 1 giorno
@matrix-meow ci sta già lavorando.
Dal 27/11/2026.
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
Description
Tested on MatrixOne main c0cef5c9cce2164fedd201c188bfffe4d2d09a96 (version() = 8.0.30-MatrixOne-v1.3.0, git_version() = c0cef5c), single CN.
In non-strict mode, COPY ALTER can convert an incoming-FK-referenced DECIMAL parent key to UNSIGNED, keep the FK declared and enforced, yet leave existing child rows permanently orphaned.
The non-strict negative-to-zero conversion itself is not the bug. The integrity defect is that COPY rewrites the parent key without rejecting the operation or revalidating the existing incoming FK rows.
Minimal reproduction
CREATE TABLE p(id DECIMAL(10,2) PRIMARY KEY);
CREATE TABLE c(
pid DECIMAL(10,2),
CONSTRAINT fk_c_p FOREIGN KEY(pid) REFERENCES p(id)
);
INSERT INTO p VALUES(-1.00);
INSERT INTO c VALUES(-1.00);
SET SESSION foreign_key_checks=1;
SET SESSION sql_mode='ONLY_FULL_GROUP_BY';
ALTER TABLE p ALGORITHM=COPY,MODIFY id DECIMAL(10,2) UNSIGNED;
-- Actual: succeeds with Warning 1264
-- Expected: reject the referenced-parent conversion and atomically preserve the valid FK
SELECT id FROM p;
-- Actual: 0.00
SELECT pid FROM c;
-- Actual: -1.00
SELECT c.pid
FROM c LEFT JOIN p ON p.id=c.pid
WHERE p.id IS NULL;
-- Actual: -1.00 (an orphaned child row)
SHOW CREATE TABLE c;
-- The same FOREIGN KEY(pid) REFERENCES p(id) is still declared.
A single parent row is intentional: using two negative parent keys can fail earlier with PK duplicate error 1062 and mask this incoming-FK path.
The orphan is persistent and visible from fresh connections. Inserting a child that matches the new parent value succeeds, inserting another unmatched child still fails with 1452, and the old orphan remains. This is therefore not disabled foreign_key_checks or a client/session-cache artifact.
Controls and affected variants
These controls establish the expected boundary:
- Strict mode rejects the same ALTER with 1264 and preserves the signed type, both rows, the valid join, and the FK.
- A same-signed-type COPY succeeds and preserves the valid join.
- A parent table with no incoming reference performs the normal non-strict truncation successfully.
- Omitting ALGORITHM selects COPY in this shape and reproduces the same orphan; explicit INPLACE is rejected as requiring COPY and preserves the original valid state.
- Colliding negative values in a base PK or single-column UNIQUE are rejected atomically with 1062; this report does not allege duplicate-key publication.
- Child-side UNSIGNED conversion and self-FK parent conversion are rejected atomically with 1452. The defect reported here is specifically the external table's incoming-parent path.
The same root cause was also reproduced with:
- a referenced UNIQUE parent key;
- a composite parent key;
- a cross-database FK;
- a STORED generated parent key whose dependency source column is changed to UNSIGNED.
For the generated case, the source and generated parent values are both correctly recomputed from -1.00 to 0.00, while the child remains -1.00. Thus generated recomputation works; the missing incoming-FK validation is the defect.
Root cause
The COPY FK affected-column analysis omits numeric signedness:
checkColumnForeignkeyConstraintinpkg/sql/plan/build_alter_modify_column.goreturns early when ID, width, scale, enum/collation/padding/auto-increment attributes match, without comparingNumericAttributes.alterCopyForeignKeyColumnMayChangeValuesinpkg/sql/plan/build_alter_table.go, used for direct FK endpoints, likewise does not compareNumericAttributes.alterCopyColumnTypeMayChangeValues, which seeds the STORED-generated dependency closure, also omits that attribute.
Consequently DECIMAL signed-to-UNSIGNED with unchanged ID/width/scale produces an empty affected set. The live FK guard in pkg/sql/compile/alter.go performs outgoing/self/incoming validation from that set, so the external incoming reference never enters a reject-or-revalidate path. The replacement parent rows are populated and the FK binding is restored without checking the pre-existing child rows.
Validation
The direct-parent reproduction, strict/signed/no-reference controls, PK/UNIQUE collision controls, child/self-FK controls, fresh-connection reads, and continued FK enforcement passed 30/30 probe assertions in each of two independent fresh-database runs. Referenced UNIQUE, composite, and cross-database variants produced the same -1.00 orphan.
The STORED-generated variant and its controls independently passed 28/28 assertions in each of two runs. Earlier probe outputs with SHOW COLUMNS or SQL-alias oracle mistakes are not used as evidence.
Duplicate check and related work
Open and closed issue/PR searches covered DECIMAL UNSIGNED, incoming FK, orphan rows, generated dependencies, NumericAttributes, and the affected guard functions. No matching issue or open fix was found.
Merged PR #31739 introduced NumericAttributes and the strict/non-strict DECIMAL conversion used here, but its tests do not include FK validation. Merged PR #28770 previously added incoming-parent scale protection; the corresponding guards still omit signedness. Open #30940 covers UNSIGNED/ZEROFILL metadata and value-domain behavior, not incoming-FK orphans. #28242 concerns blocking safe generated-column MODIFY, and #30256/#30261/#32056/#33316-#33318 cover different ALTER paths.
- Lingua principale
- Go
- Stelle
- 1.9k
- Fork
- 312
- Merge medio
- 22h 59m
- PR unite (30g)
- 736
Preparare l'ambiente
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di matrixorigin/matrixone
-
kind/bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
matrixorigin/matrixone#33363 ·
I maintainer di solito rispondono entro 1 giorno
-
kind/bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
matrixorigin/matrixone#33362 ·
I maintainer di solito rispondono entro 1 giorno
-
SLEEP rejects NULL and negative durations that MySQL acceptsForse già presa @XuPeng-SH l’ha presa 7 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
matrixorigin/matrixone#32653 ·
I maintainer di solito rispondono entro 1 giorno
-
[Bug]: TestChangeWatchProxy loses its first tenant connection during PingContext in Ubuntu CIForse già presa @XuPeng-SH l’ha presa oggi. Apertakind/bug needs-triage
matrixorigin/matrixone#33371 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
[Bug]: TestDaemonClaimSQLRoundTrip exhausts its shared deadline during the stale claim update in Ubuntu CIForse già presa @XuPeng-SH l’ha presa oggi. Apertakind/bug needs-triage
matrixorigin/matrixone#33370 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di matrixorigin/matrixone
Issue simili
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
pg-sharding/spqr#3314 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
zalando/postgres-operator#3257 ·
I maintainer di solito rispondono entro 2 giorni
-
[inputs.internal] README lists go_version tag on internal_gather instead of internal_agentForse già presa @cvas22 l’ha presa oggi. Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
influxdata/telegraf#20264 ·
I maintainer di solito rispondono entro 1 giorno