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

Commit 1755440

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 ee27584 commit 1755440

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/backend/utils/cache/inval.c

+19
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
* Also, whenever we see an operation on a pg_class, pg_attribute, or
5555
* pg_index tuple, we register a relcache flush operation for the relation
5656
* described by that tuple (as specified in CacheInvalidateHeapTuple()).
57+
* Likewise for pg_constraint tuples for foreign keys on relations.
5758
*
5859
* We keep the relcache flush requests in lists separate from the catcache
5960
* tuple flush requests. This allows us to issue all the pending catcache
@@ -100,6 +101,7 @@
100101
#include "access/htup_details.h"
101102
#include "access/xact.h"
102103
#include "catalog/catalog.h"
104+
#include "catalog/pg_constraint.h"
103105
#include "miscadmin.h"
104106
#include "storage/sinval.h"
105107
#include "storage/smgr.h"
@@ -1203,6 +1205,23 @@ CacheInvalidateHeapTuple(Relation relation,
12031205
relationId = indextup->indexrelid;
12041206
databaseId = MyDatabaseId;
12051207
}
1208+
else if (tupleRelId == ConstraintRelationId)
1209+
{
1210+
Form_pg_constraint constrtup = (Form_pg_constraint) GETSTRUCT(tuple);
1211+
1212+
/*
1213+
* Foreign keys are part of relcache entries, too, so send out an
1214+
* inval for the table that the FK applies to.
1215+
*/
1216+
if (constrtup->contype == CONSTRAINT_FOREIGN &&
1217+
OidIsValid(constrtup->conrelid))
1218+
{
1219+
relationId = constrtup->conrelid;
1220+
databaseId = MyDatabaseId;
1221+
}
1222+
else
1223+
return;
1224+
}
12061225
else
12071226
return;
12081227

0 commit comments

Comments
 (0)