From cee8db3f680b737b64d747530b48d30828cf4790 Mon Sep 17 00:00:00 2001 From: Alvaro Herrera Date: Mon, 15 Apr 2024 15:07:47 +0200 Subject: ATTACH PARTITION: Don't match a PK with a UNIQUE constraint When matching constraints in AttachPartitionEnsureIndexes() we weren't testing the constraint type, which could make a UNIQUE key lacking a not-null constraint incorrectly satisfy a primary key requirement. Fix this by testing that the constraint types match. (Other possible mismatches are verified by comparing index properties.) Discussion: https://postgr.es/m/202402051447.wimb4xmtiiyb@alvherre.pgsql --- src/backend/commands/tablecmds.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/backend/commands/tablecmds.c') diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 78b0829ffc4..027d68e5d2a 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -19550,6 +19550,11 @@ AttachPartitionEnsureIndexes(List **wqueue, Relation rel, Relation attachrel) /* no dice */ if (!OidIsValid(cldConstrOid)) continue; + + /* Ensure they're both the same type of constraint */ + if (get_constraint_type(constraintOid) != + get_constraint_type(cldConstrOid)) + continue; } /* bingo. */ -- cgit v1.2.3