summaryrefslogtreecommitdiff
path: root/src/backend/commands/tablecmds.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/commands/tablecmds.c')
-rw-r--r--src/backend/commands/tablecmds.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index fd350d2dec9..3453c4d8b3c 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -6308,12 +6308,12 @@ static void
ATExecAlterConstraint(Relation rel, AlterTableCmd *cmd,
bool recurse, bool recursing, LOCKMODE lockmode)
{
+ Constraint *cmdcon;
Relation conrel;
SysScanDesc scan;
ScanKeyData key;
HeapTuple contuple;
Form_pg_constraint currcon = NULL;
- Constraint *cmdcon = NULL;
bool found = false;
Assert(IsA(cmd->def, Constraint));
@@ -6359,10 +6359,11 @@ ATExecAlterConstraint(Relation rel, AlterTableCmd *cmd,
HeapTuple copyTuple;
HeapTuple tgtuple;
Form_pg_constraint copy_con;
- Form_pg_trigger copy_tg;
+ List *otherrelids = NIL;
ScanKeyData tgkey;
SysScanDesc tgscan;
Relation tgrel;
+ ListCell *lc;
/*
* Now update the catalog, while we have the door open.
@@ -6395,8 +6396,16 @@ ATExecAlterConstraint(Relation rel, AlterTableCmd *cmd,
while (HeapTupleIsValid(tgtuple = systable_getnext(tgscan)))
{
+ Form_pg_trigger copy_tg;
+
copyTuple = heap_copytuple(tgtuple);
copy_tg = (Form_pg_trigger) GETSTRUCT(copyTuple);
+
+ /* Remember OIDs of other relation(s) involved in FK constraint */
+ if (copy_tg->tgrelid != RelationGetRelid(rel))
+ otherrelids = list_append_unique_oid(otherrelids,
+ copy_tg->tgrelid);
+
copy_tg->tgdeferrable = cmdcon->deferrable;
copy_tg->tginitdeferred = cmdcon->initdeferred;
simple_heap_update(tgrel, &copyTuple->t_self, copyTuple);
@@ -6413,9 +6422,16 @@ ATExecAlterConstraint(Relation rel, AlterTableCmd *cmd,
heap_close(tgrel, RowExclusiveLock);
/*
- * Invalidate relcache so that others see the new attributes.
+ * Invalidate relcache so that others see the new attributes. We must
+ * inval both the named rel and any others having relevant triggers.
+ * (At present there should always be exactly one other rel, but
+ * there's no need to hard-wire such an assumption here.)
*/
CacheInvalidateRelcache(rel);
+ foreach(lc, otherrelids)
+ {
+ CacheInvalidateRelcacheByRelid(lfirst_oid(lc));
+ }
}
systable_endscan(scan);