PostgreSQL Source Code  git master
relcache.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * relcache.h
4  * Relation descriptor cache definitions.
5  *
6  *
7  * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * src/include/utils/relcache.h
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef RELCACHE_H
15 #define RELCACHE_H
16 
17 #include "postgres.h"
18 #include "access/tupdesc.h"
19 #include "nodes/bitmapset.h"
20 
21 
22 /*
23  * Name of relcache init file(s), used to speed up backend startup
24  */
25 #define RELCACHE_INIT_FILENAME "pg_internal.init"
26 
27 typedef struct RelationData *Relation;
28 
29 /* ----------------
30  * RelationPtr is used in the executor to support index scans
31  * where we have to keep track of several index relations in an
32  * array. -cim 9/10/89
33  * ----------------
34  */
35 typedef Relation *RelationPtr;
36 
37 /*
38  * Routines to open (lookup) and close a relcache entry
39  */
40 extern Relation RelationIdGetRelation(Oid relationId);
41 extern void RelationClose(Relation relation);
42 
43 /*
44  * Routines to compute/retrieve additional cached information
45  */
46 extern List *RelationGetFKeyList(Relation relation);
47 extern List *RelationGetIndexList(Relation relation);
48 extern List *RelationGetStatExtList(Relation relation);
49 extern Oid RelationGetPrimaryKeyIndex(Relation relation);
50 extern Oid RelationGetReplicaIndex(Relation relation);
51 extern List *RelationGetIndexExpressions(Relation relation);
52 extern List *RelationGetDummyIndexExpressions(Relation relation);
53 extern List *RelationGetIndexPredicate(Relation relation);
54 extern Datum *RelationGetIndexRawAttOptions(Relation relation);
55 extern bytea **RelationGetIndexAttOptions(Relation relation, bool copy);
56 
57 typedef enum IndexAttrBitmapKind
58 {
64 
65 extern Bitmapset *RelationGetIndexAttrBitmap(Relation relation,
66  IndexAttrBitmapKind attrKind);
67 
68 extern Bitmapset *RelationGetIdentityKeyBitmap(Relation relation);
69 
70 extern void RelationGetExclusionInfo(Relation indexRelation,
71  Oid **operators,
72  Oid **procs,
73  uint16 **strategies);
74 
75 extern void RelationInitIndexAccessInfo(Relation relation);
76 
77 /* caller must include pg_publication.h */
78 struct PublicationActions;
79 extern struct PublicationActions *GetRelationPublicationActions(Relation relation);
80 
81 extern void RelationInitTableAccessMethod(Relation relation);
82 
83 /*
84  * Routines to support ereport() reports of relation-related errors
85  */
86 extern int errtable(Relation rel);
87 extern int errtablecol(Relation rel, int attnum);
88 extern int errtablecolname(Relation rel, const char *colname);
89 extern int errtableconstraint(Relation rel, const char *conname);
90 
91 /*
92  * Routines for backend startup
93  */
94 extern void RelationCacheInitialize(void);
95 extern void RelationCacheInitializePhase2(void);
96 extern void RelationCacheInitializePhase3(void);
97 
98 /*
99  * Routine to create a relcache entry for an about-to-be-created relation
100  */
101 extern Relation RelationBuildLocalRelation(const char *relname,
102  Oid relnamespace,
103  TupleDesc tupDesc,
104  Oid relid,
105  Oid accessmtd,
106  Oid relfilenode,
107  Oid reltablespace,
108  bool shared_relation,
109  bool mapped_relation,
110  char relpersistence,
111  char relkind);
112 
113 /*
114  * Routines to manage assignment of new relfilenode to a relation
115  */
116 extern void RelationSetNewRelfilenode(Relation relation, char persistence);
117 extern void RelationAssumeNewRelfilenode(Relation relation);
118 
119 /*
120  * Routines for flushing/rebuilding relcache entries in various scenarios
121  */
122 extern void RelationForgetRelation(Oid rid);
123 
124 extern void RelationCacheInvalidateEntry(Oid relationId);
125 
126 extern void RelationCacheInvalidate(void);
127 
128 extern void RelationCloseSmgrByOid(Oid relationId);
129 
130 #ifdef USE_ASSERT_CHECKING
131 extern void AssertPendingSyncs_RelationCache(void);
132 #else
133 #define AssertPendingSyncs_RelationCache() do {} while (0)
134 #endif
135 extern void AtEOXact_RelationCache(bool isCommit);
136 extern void AtEOSubXact_RelationCache(bool isCommit, SubTransactionId mySubid,
137  SubTransactionId parentSubid);
138 
139 /*
140  * Routines to help manage rebuilding of relcache init files
141  */
142 extern bool RelationIdIsInInitFile(Oid relationId);
143 extern void RelationCacheInitFilePreInvalidate(void);
144 extern void RelationCacheInitFilePostInvalidate(void);
145 extern void RelationCacheInitFileRemove(void);
146 
147 /* should be used only by relcache.c and catcache.c */
148 extern bool criticalRelcachesBuilt;
149 
150 /* should be used only by relcache.c and postinit.c */
151 extern bool criticalSharedRelcachesBuilt;
152 
153 #endif /* RELCACHE_H */
void RelationCacheInitFileRemove(void)
Definition: relcache.c:6480
void AtEOSubXact_RelationCache(bool isCommit, SubTransactionId mySubid, SubTransactionId parentSubid)
Definition: relcache.c:3223
List * RelationGetDummyIndexExpressions(Relation relation)
Definition: relcache.c:4866
int errtable(Relation rel)
Definition: relcache.c:5636
int errtableconstraint(Relation rel, const char *conname)
Definition: relcache.c:5690
void RelationCacheInitializePhase2(void)
Definition: relcache.c:3811
int errtablecolname(Relation rel, const char *colname)
Definition: relcache.c:5677
Bitmapset * RelationGetIdentityKeyBitmap(Relation relation)
Definition: relcache.c:5247
List * RelationGetIndexList(Relation relation)
Definition: relcache.c:4573
void RelationForgetRelation(Oid rid)
Definition: relcache.c:2753
uint32 SubTransactionId
Definition: c.h:591
bool criticalRelcachesBuilt
Definition: relcache.c:137
NameData relname
Definition: pg_class.h:38
unsigned int Oid
Definition: postgres_ext.h:31
IndexAttrBitmapKind
Definition: relcache.h:57
int errtablecol(Relation rel, int attnum)
Definition: relcache.c:5653
void AtEOXact_RelationCache(bool isCommit)
Definition: relcache.c:3078
struct RelationData * Relation
Definition: relcache.h:27
unsigned short uint16
Definition: c.h:440
bool RelationIdIsInInitFile(Oid relationId)
Definition: relcache.c:6400
void RelationCacheInitFilePreInvalidate(void)
Definition: relcache.c:6440
Oid RelationGetReplicaIndex(Relation relation)
Definition: relcache.c:4782
void RelationInitTableAccessMethod(Relation relation)
Definition: relcache.c:1743
void RelationAssumeNewRelfilenode(Relation relation)
Definition: relcache.c:3749
#define AssertPendingSyncs_RelationCache()
Definition: relcache.h:133
Relation RelationBuildLocalRelation(const char *relname, Oid relnamespace, TupleDesc tupDesc, Oid relid, Oid accessmtd, Oid relfilenode, Oid reltablespace, bool shared_relation, bool mapped_relation, char relpersistence, char relkind)
Definition: relcache.c:3352
void RelationCacheInitializePhase3(void)
Definition: relcache.c:3870
Relation * RelationPtr
Definition: relcache.h:35
Datum * RelationGetIndexRawAttOptions(Relation relation)
Definition: relcache.c:5529
List * RelationGetIndexExpressions(Relation relation)
Definition: relcache.c:4807
void RelationCloseSmgrByOid(Oid relationId)
Definition: relcache.c:2943
void RelationClose(Relation relation)
Definition: relcache.c:2101
void RelationCacheInvalidateEntry(Oid relationId)
Definition: relcache.c:2797
uintptr_t Datum
Definition: postgres.h:411
void RelationCacheInitFilePostInvalidate(void)
Definition: relcache.c:6465
bool criticalSharedRelcachesBuilt
Definition: relcache.c:143
int16 attnum
Definition: pg_attribute.h:83
void RelationGetExclusionInfo(Relation indexRelation, Oid **operators, Oid **procs, uint16 **strategies)
Definition: relcache.c:5321
List * RelationGetFKeyList(Relation relation)
Definition: relcache.c:4464
void RelationCacheInitialize(void)
Definition: relcache.c:3775
struct PublicationActions * GetRelationPublicationActions(Relation relation)
Definition: relcache.c:5445
Bitmapset * RelationGetIndexAttrBitmap(Relation relation, IndexAttrBitmapKind attrKind)
Definition: relcache.c:5003
bytea ** RelationGetIndexAttOptions(Relation relation, bool copy)
Definition: relcache.c:5575
Oid RelationGetPrimaryKeyIndex(Relation relation)
Definition: relcache.c:4761
void RelationCacheInvalidate(void)
Definition: relcache.c:2840
Relation RelationIdGetRelation(Oid relationId)
Definition: relcache.c:1995
List * RelationGetStatExtList(Relation relation)
Definition: relcache.c:4692
Definition: c.h:621
Definition: pg_list.h:50
List * RelationGetIndexPredicate(Relation relation)
Definition: relcache.c:4920
void RelationSetNewRelfilenode(Relation relation, char persistence)
Definition: relcache.c:3598
void RelationInitIndexAccessInfo(Relation relation)
Definition: relcache.c:1360