|
54 | 54 | * Also, whenever we see an operation on a pg_class, pg_attribute, or
|
55 | 55 | * pg_index tuple, we register a relcache flush operation for the relation
|
56 | 56 | * described by that tuple (as specified in CacheInvalidateHeapTuple()).
|
| 57 | + * Likewise for pg_constraint tuples for foreign keys on relations. |
57 | 58 | *
|
58 | 59 | * We keep the relcache flush requests in lists separate from the catcache
|
59 | 60 | * tuple flush requests. This allows us to issue all the pending catcache
|
|
100 | 101 | #include "access/htup_details.h"
|
101 | 102 | #include "access/xact.h"
|
102 | 103 | #include "catalog/catalog.h"
|
| 104 | +#include "catalog/pg_constraint.h" |
103 | 105 | #include "miscadmin.h"
|
104 | 106 | #include "storage/sinval.h"
|
105 | 107 | #include "storage/smgr.h"
|
@@ -1203,6 +1205,23 @@ CacheInvalidateHeapTuple(Relation relation,
|
1203 | 1205 | relationId = indextup->indexrelid;
|
1204 | 1206 | databaseId = MyDatabaseId;
|
1205 | 1207 | }
|
| 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 | + } |
1206 | 1225 | else
|
1207 | 1226 | return;
|
1208 | 1227 |
|
|
0 commit comments