summaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorTom Lane2014-05-14 18:55:48 +0000
committerTom Lane2014-05-14 18:56:08 +0000
commitb23b0f5588d2e2f15edff66e072e339a8c9616a7 (patch)
tree4f4fc7804d31955fd244a899867e14ee2ebea922 /src/include
parentac53295d667e7727d7b70ddf11d82c067870501f (diff)
Code review for recent changes in relcache.c.
rd_replidindex should be managed the same as rd_oidindex, and rd_keyattr and rd_idattr should be managed like rd_indexattr. Omissions in this area meant that the bitmapsets computed for rd_keyattr and rd_idattr would be leaked during any relcache flush, resulting in a slow but permanent leak in CacheMemoryContext. There was also a tiny probability of relcache entry corruption if we ran out of memory at just the wrong point in RelationGetIndexAttrBitmap. Otherwise, the fields were not zeroed where expected, which would not bother the code any AFAICS but could greatly confuse anyone examining the relcache entry while debugging. Also, create an API function RelationGetReplicaIndex rather than letting non-relcache code be intimate with the mechanisms underlying caching of that value (we won't even mention the memory leak there). Also, fix a relcache flush hazard identified by Andres Freund: RelationGetIndexAttrBitmap must not assume that rd_replidindex stays valid across index_open. The aspects of this involving rd_keyattr date back to 9.3, so back-patch those changes.
Diffstat (limited to 'src/include')
-rw-r--r--src/include/utils/rel.h20
-rw-r--r--src/include/utils/relcache.h1
2 files changed, 10 insertions, 11 deletions
diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h
index 4d73700185c..af4f53f1121 100644
--- a/src/include/utils/rel.h
+++ b/src/include/utils/rel.h
@@ -101,22 +101,20 @@ typedef struct RelationData
Form_pg_class rd_rel; /* RELATION tuple */
TupleDesc rd_att; /* tuple descriptor */
Oid rd_id; /* relation's object id */
- List *rd_indexlist; /* list of OIDs of indexes on relation */
- Bitmapset *rd_indexattr; /* identifies columns used in indexes */
- Bitmapset *rd_keyattr; /* cols that can be ref'd by foreign keys */
- Bitmapset *rd_idattr; /* included in replica identity index */
- Oid rd_oidindex; /* OID of unique index on OID, if any */
LockInfoData rd_lockInfo; /* lock mgr's info for locking relation */
RuleLock *rd_rules; /* rewrite rules */
MemoryContext rd_rulescxt; /* private memory cxt for rd_rules, if any */
TriggerDesc *trigdesc; /* Trigger info, or NULL if rel has none */
- /*
- * The index chosen as the relation's replication identity or InvalidOid.
- * Only set correctly if RelationGetIndexList has been
- * called/rd_indexvalid > 0.
- */
- Oid rd_replidindex;
+ /* data managed by RelationGetIndexList: */
+ List *rd_indexlist; /* list of OIDs of indexes on relation */
+ Oid rd_oidindex; /* OID of unique index on OID, if any */
+ Oid rd_replidindex; /* OID of replica identity index, if any */
+
+ /* data managed by RelationGetIndexAttrBitmap: */
+ Bitmapset *rd_indexattr; /* identifies columns used in indexes */
+ Bitmapset *rd_keyattr; /* cols that can be ref'd by foreign keys */
+ Bitmapset *rd_idattr; /* included in replica identity index */
/*
* rd_options is set whenever rd_rel is loaded into the relcache entry.
diff --git a/src/include/utils/relcache.h b/src/include/utils/relcache.h
index 3e1c1385a4d..e4ca70f1404 100644
--- a/src/include/utils/relcache.h
+++ b/src/include/utils/relcache.h
@@ -39,6 +39,7 @@ extern void RelationClose(Relation relation);
*/
extern List *RelationGetIndexList(Relation relation);
extern Oid RelationGetOidIndex(Relation relation);
+extern Oid RelationGetReplicaIndex(Relation relation);
extern List *RelationGetIndexExpressions(Relation relation);
extern List *RelationGetIndexPredicate(Relation relation);