@@ -402,6 +402,8 @@ static void ATExecAlterChildConstr(List **wqueue, ATAlterConstraint *cmdcon,
402
402
Relation conrel, Relation tgrel, Relation rel,
403
403
HeapTuple contuple, bool recurse, List **otherrelids,
404
404
LOCKMODE lockmode);
405
+ static void AlterConstrUpdateConstraintEntry(ATAlterConstraint *cmdcon, Relation conrel,
406
+ HeapTuple contuple);
405
407
static ObjectAddress ATExecValidateConstraint(List **wqueue,
406
408
Relation rel, char *constrName,
407
409
bool recurse, bool recursing, LOCKMODE lockmode);
@@ -12093,23 +12095,9 @@ ATExecAlterConstraintInternal(List **wqueue, ATAlterConstraint *cmdcon,
12093
12095
(currcon->condeferrable != cmdcon->deferrable ||
12094
12096
currcon->condeferred != cmdcon->initdeferred))
12095
12097
{
12096
- HeapTuple copyTuple;
12097
- Form_pg_constraint copy_con;
12098
-
12099
- copyTuple = heap_copytuple(contuple);
12100
- copy_con = (Form_pg_constraint) GETSTRUCT(copyTuple);
12101
- copy_con->condeferrable = cmdcon->deferrable;
12102
- copy_con->condeferred = cmdcon->initdeferred;
12103
- CatalogTupleUpdate(conrel, ©Tuple->t_self, copyTuple);
12104
-
12105
- InvokeObjectPostAlterHook(ConstraintRelationId, currcon->oid, 0);
12106
-
12107
- heap_freetuple(copyTuple);
12098
+ AlterConstrUpdateConstraintEntry(cmdcon, conrel, contuple);
12108
12099
changed = true;
12109
12100
12110
- /* Make new constraint flags visible to others */
12111
- CacheInvalidateRelcache(rel);
12112
-
12113
12101
/*
12114
12102
* Now we need to update the multiple entries in pg_trigger that
12115
12103
* implement the constraint.
@@ -12140,27 +12128,14 @@ ATExecAlterConstraintInternal(List **wqueue, ATAlterConstraint *cmdcon,
12140
12128
AttrNumber colNum;
12141
12129
char *colName;
12142
12130
List *children;
12143
- HeapTuple copyTuple;
12144
- Form_pg_constraint copy_con;
12145
12131
12146
12132
/* The current implementation only works for NOT NULL constraints */
12147
12133
Assert(currcon->contype == CONSTRAINT_NOTNULL);
12148
12134
12149
- copyTuple = heap_copytuple(contuple);
12150
- copy_con = (Form_pg_constraint) GETSTRUCT(copyTuple);
12151
- copy_con->connoinherit = cmdcon->noinherit;
12152
-
12153
- CatalogTupleUpdate(conrel, ©Tuple->t_self, copyTuple);
12154
-
12155
- InvokeObjectPostAlterHook(ConstraintRelationId, currcon->oid, 0);
12156
-
12135
+ AlterConstrUpdateConstraintEntry(cmdcon, conrel, contuple);
12157
12136
CommandCounterIncrement();
12158
- heap_freetuple(copyTuple);
12159
12137
changed = true;
12160
12138
12161
- /* Make new constraint flags visible to others */
12162
- CacheInvalidateRelcache(rel);
12163
-
12164
12139
/* Fetch the column number and name */
12165
12140
colNum = extractNotNullColumn(contuple);
12166
12141
colName = get_attname(currcon->conrelid, colNum, false);
@@ -12320,6 +12295,39 @@ ATExecAlterChildConstr(List **wqueue, ATAlterConstraint *cmdcon,
12320
12295
systable_endscan(pscan);
12321
12296
}
12322
12297
12298
+ /*
12299
+ * Update the constraint entry for the given ATAlterConstraint command, and
12300
+ * invoke the appropriate hooks.
12301
+ */
12302
+ static void
12303
+ AlterConstrUpdateConstraintEntry(ATAlterConstraint *cmdcon, Relation conrel,
12304
+ HeapTuple contuple)
12305
+ {
12306
+ HeapTuple copyTuple;
12307
+ Form_pg_constraint copy_con;
12308
+
12309
+ Assert(cmdcon->alterDeferrability || cmdcon->alterInheritability);
12310
+
12311
+ copyTuple = heap_copytuple(contuple);
12312
+ copy_con = (Form_pg_constraint) GETSTRUCT(copyTuple);
12313
+
12314
+ if (cmdcon->alterDeferrability)
12315
+ {
12316
+ copy_con->condeferrable = cmdcon->deferrable;
12317
+ copy_con->condeferred = cmdcon->initdeferred;
12318
+ }
12319
+ if (cmdcon->alterInheritability)
12320
+ copy_con->connoinherit = cmdcon->noinherit;
12321
+
12322
+ CatalogTupleUpdate(conrel, ©Tuple->t_self, copyTuple);
12323
+ InvokeObjectPostAlterHook(ConstraintRelationId, copy_con->oid, 0);
12324
+
12325
+ /* Make new constraint flags visible to others */
12326
+ CacheInvalidateRelcacheByRelid(copy_con->conrelid);
12327
+
12328
+ heap_freetuple(copyTuple);
12329
+ }
12330
+
12323
12331
/*
12324
12332
* ALTER TABLE VALIDATE CONSTRAINT
12325
12333
*
0 commit comments