1
0
mirror of https://github.com/postgres/postgres.git synced 2025-10-15 05:46:52 +03:00

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
This commit is contained in:
Alvaro Herrera
2024-04-15 15:07:47 +02:00
parent 9dfcac8e15
commit cee8db3f68
5 changed files with 52 additions and 0 deletions

View File

@@ -1133,6 +1133,28 @@ get_constraint_index(Oid conoid)
return InvalidOid;
}
/*
* get_constraint_type
* Return the pg_constraint.contype value for the given constraint.
*
* No frills.
*/
char
get_constraint_type(Oid conoid)
{
HeapTuple tp;
char contype;
tp = SearchSysCache1(CONSTROID, ObjectIdGetDatum(conoid));
if (!HeapTupleIsValid(tp))
elog(ERROR, "cache lookup failed for constraint %u", conoid);
contype = ((Form_pg_constraint) GETSTRUCT(tp))->contype;
ReleaseSysCache(tp);
return contype;
}
/* ---------- LANGUAGE CACHE ---------- */
char *