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:
22
src/backend/utils/cache/lsyscache.c
vendored
22
src/backend/utils/cache/lsyscache.c
vendored
@@ -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 *
|
||||
|
Reference in New Issue
Block a user