@@ -398,6 +398,10 @@ static bool ATExecAlterConstraintInternal(List **wqueue, ATAlterConstraint *cmdc
398
398
static void AlterConstrTriggerDeferrability(Oid conoid, Relation tgrel, Relation rel,
399
399
bool deferrable, bool initdeferred,
400
400
List **otherrelids);
401
+ static void ATExecAlterChildConstr(List **wqueue, ATAlterConstraint *cmdcon,
402
+ Relation conrel, Relation tgrel, Relation rel,
403
+ HeapTuple contuple, bool recurse, List **otherrelids,
404
+ LOCKMODE lockmode);
401
405
static ObjectAddress ATExecValidateConstraint(List **wqueue,
402
406
Relation rel, char *constrName,
403
407
bool recurse, bool recursing, LOCKMODE lockmode);
@@ -12031,41 +12035,13 @@ ATExecAlterConstraintInternal(List **wqueue, ATAlterConstraint *cmdcon,
12031
12035
/*
12032
12036
* If the table at either end of the constraint is partitioned, we need to
12033
12037
* handle every constraint that is a child of this one.
12034
- *
12035
- * Note that this doesn't handle recursion the normal way, viz. by
12036
- * scanning the list of child relations and recursing; instead it uses the
12037
- * conparentid relationships. This may need to be reconsidered.
12038
12038
*/
12039
12039
if (recurse && changed &&
12040
12040
(rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE ||
12041
12041
(OidIsValid(refrelid) &&
12042
12042
get_rel_relkind(refrelid) == RELKIND_PARTITIONED_TABLE)))
12043
- {
12044
- ScanKeyData pkey;
12045
- SysScanDesc pscan;
12046
- HeapTuple childtup;
12047
-
12048
- ScanKeyInit(&pkey,
12049
- Anum_pg_constraint_conparentid,
12050
- BTEqualStrategyNumber, F_OIDEQ,
12051
- ObjectIdGetDatum(currcon->oid));
12052
-
12053
- pscan = systable_beginscan(conrel, ConstraintParentIndexId,
12054
- true, NULL, 1, &pkey);
12055
-
12056
- while (HeapTupleIsValid(childtup = systable_getnext(pscan)))
12057
- {
12058
- Form_pg_constraint childcon = (Form_pg_constraint) GETSTRUCT(childtup);
12059
- Relation childrel;
12060
-
12061
- childrel = table_open(childcon->conrelid, lockmode);
12062
- ATExecAlterConstraintInternal(wqueue, cmdcon, conrel, tgrel, childrel,
12063
- childtup, recurse, otherrelids, lockmode);
12064
- table_close(childrel, NoLock);
12065
- }
12066
-
12067
- systable_endscan(pscan);
12068
- }
12043
+ ATExecAlterChildConstr(wqueue, cmdcon, conrel, tgrel, rel, contuple,
12044
+ recurse, otherrelids, lockmode);
12069
12045
12070
12046
/*
12071
12047
* Update the catalog for inheritability. No work if the constraint is
@@ -12203,6 +12179,54 @@ AlterConstrTriggerDeferrability(Oid conoid, Relation tgrel, Relation rel,
12203
12179
systable_endscan(tgscan);
12204
12180
}
12205
12181
12182
+ /*
12183
+ * Invokes ATExecAlterConstraintInternal for each constraint that is a child of
12184
+ * the specified constraint.
12185
+ *
12186
+ * Note that this doesn't handle recursion the normal way, viz. by scanning the
12187
+ * list of child relations and recursing; instead it uses the conparentid
12188
+ * relationships. This may need to be reconsidered.
12189
+ *
12190
+ * The arguments to this function have the same meaning as the arguments to
12191
+ * ATExecAlterConstraintInternal.
12192
+ */
12193
+ static void
12194
+ ATExecAlterChildConstr(List **wqueue, ATAlterConstraint *cmdcon,
12195
+ Relation conrel, Relation tgrel, Relation rel,
12196
+ HeapTuple contuple, bool recurse, List **otherrelids,
12197
+ LOCKMODE lockmode)
12198
+ {
12199
+ Form_pg_constraint currcon;
12200
+ Oid conoid;
12201
+ ScanKeyData pkey;
12202
+ SysScanDesc pscan;
12203
+ HeapTuple childtup;
12204
+
12205
+ currcon = (Form_pg_constraint) GETSTRUCT(contuple);
12206
+ conoid = currcon->oid;
12207
+
12208
+ ScanKeyInit(&pkey,
12209
+ Anum_pg_constraint_conparentid,
12210
+ BTEqualStrategyNumber, F_OIDEQ,
12211
+ ObjectIdGetDatum(conoid));
12212
+
12213
+ pscan = systable_beginscan(conrel, ConstraintParentIndexId,
12214
+ true, NULL, 1, &pkey);
12215
+
12216
+ while (HeapTupleIsValid(childtup = systable_getnext(pscan)))
12217
+ {
12218
+ Form_pg_constraint childcon = (Form_pg_constraint) GETSTRUCT(childtup);
12219
+ Relation childrel;
12220
+
12221
+ childrel = table_open(childcon->conrelid, lockmode);
12222
+ ATExecAlterConstraintInternal(wqueue, cmdcon, conrel, tgrel, childrel,
12223
+ childtup, recurse, otherrelids, lockmode);
12224
+ table_close(childrel, NoLock);
12225
+ }
12226
+
12227
+ systable_endscan(pscan);
12228
+ }
12229
+
12206
12230
/*
12207
12231
* ALTER TABLE VALIDATE CONSTRAINT
12208
12232
*
0 commit comments