mirror of
https://github.com/postgres/postgres.git
synced 2025-09-03 15:22:11 +03:00
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.
This commit is contained in:
@@ -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.
|
||||
|
Reference in New Issue
Block a user