Relation conrel, Relation tgrel, Relation rel,
HeapTuple contuple, bool recurse, List **otherrelids,
LOCKMODE lockmode);
+static void AlterConstrUpdateConstraintEntry(ATAlterConstraint *cmdcon, Relation conrel,
+ HeapTuple contuple);
static ObjectAddress ATExecValidateConstraint(List **wqueue,
Relation rel, char *constrName,
bool recurse, bool recursing, LOCKMODE lockmode);
(currcon->condeferrable != cmdcon->deferrable ||
currcon->condeferred != cmdcon->initdeferred))
{
- HeapTuple copyTuple;
- Form_pg_constraint copy_con;
-
- copyTuple = heap_copytuple(contuple);
- copy_con = (Form_pg_constraint) GETSTRUCT(copyTuple);
- copy_con->condeferrable = cmdcon->deferrable;
- copy_con->condeferred = cmdcon->initdeferred;
- CatalogTupleUpdate(conrel, ©Tuple->t_self, copyTuple);
-
- InvokeObjectPostAlterHook(ConstraintRelationId, currcon->oid, 0);
-
- heap_freetuple(copyTuple);
+ AlterConstrUpdateConstraintEntry(cmdcon, conrel, contuple);
changed = true;
- /* Make new constraint flags visible to others */
- CacheInvalidateRelcache(rel);
-
/*
* Now we need to update the multiple entries in pg_trigger that
* implement the constraint.
AttrNumber colNum;
char *colName;
List *children;
- HeapTuple copyTuple;
- Form_pg_constraint copy_con;
/* The current implementation only works for NOT NULL constraints */
Assert(currcon->contype == CONSTRAINT_NOTNULL);
- copyTuple = heap_copytuple(contuple);
- copy_con = (Form_pg_constraint) GETSTRUCT(copyTuple);
- copy_con->connoinherit = cmdcon->noinherit;
-
- CatalogTupleUpdate(conrel, ©Tuple->t_self, copyTuple);
-
- InvokeObjectPostAlterHook(ConstraintRelationId, currcon->oid, 0);
-
+ AlterConstrUpdateConstraintEntry(cmdcon, conrel, contuple);
CommandCounterIncrement();
- heap_freetuple(copyTuple);
changed = true;
- /* Make new constraint flags visible to others */
- CacheInvalidateRelcache(rel);
-
/* Fetch the column number and name */
colNum = extractNotNullColumn(contuple);
colName = get_attname(currcon->conrelid, colNum, false);
systable_endscan(pscan);
}
+/*
+ * Update the constraint entry for the given ATAlterConstraint command, and
+ * invoke the appropriate hooks.
+ */
+static void
+AlterConstrUpdateConstraintEntry(ATAlterConstraint *cmdcon, Relation conrel,
+ HeapTuple contuple)
+{
+ HeapTuple copyTuple;
+ Form_pg_constraint copy_con;
+
+ Assert(cmdcon->alterDeferrability || cmdcon->alterInheritability);
+
+ copyTuple = heap_copytuple(contuple);
+ copy_con = (Form_pg_constraint) GETSTRUCT(copyTuple);
+
+ if (cmdcon->alterDeferrability)
+ {
+ copy_con->condeferrable = cmdcon->deferrable;
+ copy_con->condeferred = cmdcon->initdeferred;
+ }
+ if (cmdcon->alterInheritability)
+ copy_con->connoinherit = cmdcon->noinherit;
+
+ CatalogTupleUpdate(conrel, ©Tuple->t_self, copyTuple);
+ InvokeObjectPostAlterHook(ConstraintRelationId, copy_con->oid, 0);
+
+ /* Make new constraint flags visible to others */
+ CacheInvalidateRelcacheByRelid(copy_con->conrelid);
+
+ heap_freetuple(copyTuple);
+}
+
/*
* ALTER TABLE VALIDATE CONSTRAINT
*