Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 4aead13

Browse files
committed
Flush relcache entries when their FKs are meddled with
Back in commit 100340e, we made relcache entries keep lists of the foreign keys applying to the relation -- but we forgot to update CacheInvalidateHeapTuple to flush those entries when new FKs got created or existing ones updated/deleted. No bugs appear to have been reported that would be explained by this ommission, but I noticed the problem while working on an unrelated bugfix which clearly showed it. Fix by adding relcache flush on relevant foreign key changes. Backpatch to 9.6, like the aforementioned commit. Discussion: https://postgr.es/m/201901211927.7mmhschxlejh@alvherre.pgsql Reviewed-by: Tom Lane
1 parent 058e275 commit 4aead13

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/backend/utils/cache/inval.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
*
5454
* Also, whenever we see an operation on a pg_class or pg_attribute tuple,
5555
* we register a relcache flush operation for the relation described by that
56-
* tuple.
56+
* tuple. Likewise for pg_constraint tuples for foreign keys on relations.
5757
*
5858
* We keep the relcache flush requests in lists separate from the catcache
5959
* tuple flush requests. This allows us to issue all the pending catcache
@@ -98,6 +98,7 @@
9898
#include "access/htup_details.h"
9999
#include "access/xact.h"
100100
#include "catalog/catalog.h"
101+
#include "catalog/pg_constraint.h"
101102
#include "miscadmin.h"
102103
#include "storage/sinval.h"
103104
#include "storage/smgr.h"
@@ -1193,6 +1194,23 @@ CacheInvalidateHeapTuple(Relation relation,
11931194
relationId = indextup->indexrelid;
11941195
databaseId = MyDatabaseId;
11951196
}
1197+
else if (tupleRelId == ConstraintRelationId)
1198+
{
1199+
Form_pg_constraint constrtup = (Form_pg_constraint) GETSTRUCT(tuple);
1200+
1201+
/*
1202+
* Foreign keys are part of relcache entries, too, so send out an
1203+
* inval for the table that the FK applies to.
1204+
*/
1205+
if (constrtup->contype == CONSTRAINT_FOREIGN &&
1206+
OidIsValid(constrtup->conrelid))
1207+
{
1208+
relationId = constrtup->conrelid;
1209+
databaseId = MyDatabaseId;
1210+
}
1211+
else
1212+
return;
1213+
}
11961214
else
11971215
return;
11981216

0 commit comments

Comments
 (0)