Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1755440

Browse files
committed
Flush relcache entries when their FKs are meddled with
Back in commit100340e, we made relcache entries keep lists of theforeign keys applying to the relation -- but we forgot to updateCacheInvalidateHeapTuple to flush those entries when new FKs got createdor existing ones updated/deleted. No bugs appear to have been reportedthat would be explained by this ommission, but I noticed the problemwhile working on an unrelated bugfix which clearly showed it. Fix byadding relcache flush on relevant foreign key changes.Backpatch to 9.6, like the aforementioned commit.Discussion:https://postgr.es/m/201901211927.7mmhschxlejh@alvherre.pgsqlReviewed-by: Tom Lane
1 parentee27584 commit1755440

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

‎src/backend/utils/cache/inval.c

Lines changed: 19 additions & 0 deletions
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+
elseif (tupleRelId==ConstraintRelationId)
1209+
{
1210+
Form_pg_constraintconstrtup= (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)

[8]ページ先頭

©2009-2025 Movatter.jp