mirror of
https://github.com/postgres/postgres.git
synced 2025-06-14 18:42:34 +03:00
refactor: re-add ATExecAlterChildConstr()
ATExecAlterChildConstr() was removed in commit 80d7f99049
, but it is
needed in some subsequent patches for the NOT ENFORCED feature, to
recurse over child constraints. This adds it back in slightly altered
form.
Author: Amul Sul <amul.sul@enterprisedb.com>
Reviewed-by: Alexandra Wang <alexandra.wang.oss@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/CAAJ_b962c5AcYW9KUt_R_ER5qs3fUGbe4az-SP-vuwPS-w-AGA%40mail.gmail.com
This commit is contained in:
@ -398,6 +398,10 @@ static bool ATExecAlterConstraintInternal(List **wqueue, ATAlterConstraint *cmdc
|
|||||||
static void AlterConstrTriggerDeferrability(Oid conoid, Relation tgrel, Relation rel,
|
static void AlterConstrTriggerDeferrability(Oid conoid, Relation tgrel, Relation rel,
|
||||||
bool deferrable, bool initdeferred,
|
bool deferrable, bool initdeferred,
|
||||||
List **otherrelids);
|
List **otherrelids);
|
||||||
|
static void ATExecAlterChildConstr(List **wqueue, ATAlterConstraint *cmdcon,
|
||||||
|
Relation conrel, Relation tgrel, Relation rel,
|
||||||
|
HeapTuple contuple, bool recurse, List **otherrelids,
|
||||||
|
LOCKMODE lockmode);
|
||||||
static ObjectAddress ATExecValidateConstraint(List **wqueue,
|
static ObjectAddress ATExecValidateConstraint(List **wqueue,
|
||||||
Relation rel, char *constrName,
|
Relation rel, char *constrName,
|
||||||
bool recurse, bool recursing, LOCKMODE lockmode);
|
bool recurse, bool recursing, LOCKMODE lockmode);
|
||||||
@ -12031,41 +12035,13 @@ ATExecAlterConstraintInternal(List **wqueue, ATAlterConstraint *cmdcon,
|
|||||||
/*
|
/*
|
||||||
* If the table at either end of the constraint is partitioned, we need to
|
* If the table at either end of the constraint is partitioned, we need to
|
||||||
* handle every constraint that is a child of this one.
|
* handle every constraint that is a child of this one.
|
||||||
*
|
|
||||||
* Note that this doesn't handle recursion the normal way, viz. by
|
|
||||||
* scanning the list of child relations and recursing; instead it uses the
|
|
||||||
* conparentid relationships. This may need to be reconsidered.
|
|
||||||
*/
|
*/
|
||||||
if (recurse && changed &&
|
if (recurse && changed &&
|
||||||
(rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE ||
|
(rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE ||
|
||||||
(OidIsValid(refrelid) &&
|
(OidIsValid(refrelid) &&
|
||||||
get_rel_relkind(refrelid) == RELKIND_PARTITIONED_TABLE)))
|
get_rel_relkind(refrelid) == RELKIND_PARTITIONED_TABLE)))
|
||||||
{
|
ATExecAlterChildConstr(wqueue, cmdcon, conrel, tgrel, rel, contuple,
|
||||||
ScanKeyData pkey;
|
recurse, otherrelids, lockmode);
|
||||||
SysScanDesc pscan;
|
|
||||||
HeapTuple childtup;
|
|
||||||
|
|
||||||
ScanKeyInit(&pkey,
|
|
||||||
Anum_pg_constraint_conparentid,
|
|
||||||
BTEqualStrategyNumber, F_OIDEQ,
|
|
||||||
ObjectIdGetDatum(currcon->oid));
|
|
||||||
|
|
||||||
pscan = systable_beginscan(conrel, ConstraintParentIndexId,
|
|
||||||
true, NULL, 1, &pkey);
|
|
||||||
|
|
||||||
while (HeapTupleIsValid(childtup = systable_getnext(pscan)))
|
|
||||||
{
|
|
||||||
Form_pg_constraint childcon = (Form_pg_constraint) GETSTRUCT(childtup);
|
|
||||||
Relation childrel;
|
|
||||||
|
|
||||||
childrel = table_open(childcon->conrelid, lockmode);
|
|
||||||
ATExecAlterConstraintInternal(wqueue, cmdcon, conrel, tgrel, childrel,
|
|
||||||
childtup, recurse, otherrelids, lockmode);
|
|
||||||
table_close(childrel, NoLock);
|
|
||||||
}
|
|
||||||
|
|
||||||
systable_endscan(pscan);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Update the catalog for inheritability. No work if the constraint is
|
* Update the catalog for inheritability. No work if the constraint is
|
||||||
@ -12203,6 +12179,54 @@ AlterConstrTriggerDeferrability(Oid conoid, Relation tgrel, Relation rel,
|
|||||||
systable_endscan(tgscan);
|
systable_endscan(tgscan);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Invokes ATExecAlterConstraintInternal for each constraint that is a child of
|
||||||
|
* the specified constraint.
|
||||||
|
*
|
||||||
|
* Note that this doesn't handle recursion the normal way, viz. by scanning the
|
||||||
|
* list of child relations and recursing; instead it uses the conparentid
|
||||||
|
* relationships. This may need to be reconsidered.
|
||||||
|
*
|
||||||
|
* The arguments to this function have the same meaning as the arguments to
|
||||||
|
* ATExecAlterConstraintInternal.
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
ATExecAlterChildConstr(List **wqueue, ATAlterConstraint *cmdcon,
|
||||||
|
Relation conrel, Relation tgrel, Relation rel,
|
||||||
|
HeapTuple contuple, bool recurse, List **otherrelids,
|
||||||
|
LOCKMODE lockmode)
|
||||||
|
{
|
||||||
|
Form_pg_constraint currcon;
|
||||||
|
Oid conoid;
|
||||||
|
ScanKeyData pkey;
|
||||||
|
SysScanDesc pscan;
|
||||||
|
HeapTuple childtup;
|
||||||
|
|
||||||
|
currcon = (Form_pg_constraint) GETSTRUCT(contuple);
|
||||||
|
conoid = currcon->oid;
|
||||||
|
|
||||||
|
ScanKeyInit(&pkey,
|
||||||
|
Anum_pg_constraint_conparentid,
|
||||||
|
BTEqualStrategyNumber, F_OIDEQ,
|
||||||
|
ObjectIdGetDatum(conoid));
|
||||||
|
|
||||||
|
pscan = systable_beginscan(conrel, ConstraintParentIndexId,
|
||||||
|
true, NULL, 1, &pkey);
|
||||||
|
|
||||||
|
while (HeapTupleIsValid(childtup = systable_getnext(pscan)))
|
||||||
|
{
|
||||||
|
Form_pg_constraint childcon = (Form_pg_constraint) GETSTRUCT(childtup);
|
||||||
|
Relation childrel;
|
||||||
|
|
||||||
|
childrel = table_open(childcon->conrelid, lockmode);
|
||||||
|
ATExecAlterConstraintInternal(wqueue, cmdcon, conrel, tgrel, childrel,
|
||||||
|
childtup, recurse, otherrelids, lockmode);
|
||||||
|
table_close(childrel, NoLock);
|
||||||
|
}
|
||||||
|
|
||||||
|
systable_endscan(pscan);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ALTER TABLE VALIDATE CONSTRAINT
|
* ALTER TABLE VALIDATE CONSTRAINT
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user