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-2020, 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 void RelationGetExclusionInfo(Relation indexRelation,
69  Oid **operators,
70  Oid **procs,
71  uint16 **strategies);
72 
73 extern void RelationInitIndexAccessInfo(Relation relation);
74 
75 /* caller must include pg_publication.h */
76 struct PublicationActions;
77 extern struct PublicationActions *GetRelationPublicationActions(Relation relation);
78 
79 extern void RelationInitTableAccessMethod(Relation relation);
80 
81 /*
82  * Routines to support ereport() reports of relation-related errors
83  */
84 extern int errtable(Relation rel);
85 extern int errtablecol(Relation rel, int attnum);
86 extern int errtablecolname(Relation rel, const char *colname);
87 extern int errtableconstraint(Relation rel, const char *conname);
88 
89 /*
90  * Routines for backend startup
91  */
92 extern void RelationCacheInitialize(void);
93 extern void RelationCacheInitializePhase2(void);
94 extern void RelationCacheInitializePhase3(void);
95 
96 /*
97  * Routine to create a relcache entry for an about-to-be-created relation
98  */
99 extern Relation RelationBuildLocalRelation(const char *relname,
100  Oid relnamespace,
101  TupleDesc tupDesc,
102  Oid relid,
103  Oid accessmtd,
104  Oid relfilenode,
105  Oid reltablespace,
106  bool shared_relation,
107  bool mapped_relation,
108  char relpersistence,
109  char relkind);
110 
111 /*
112  * Routines to manage assignment of new relfilenode to a relation
113  */
114 extern void RelationSetNewRelfilenode(Relation relation, char persistence);
115 extern void RelationAssumeNewRelfilenode(Relation relation);
116 
117 /*
118  * Routines for flushing/rebuilding relcache entries in various scenarios
119  */
120 extern void RelationForgetRelation(Oid rid);
121 
122 extern void RelationCacheInvalidateEntry(Oid relationId);
123 
124 extern void RelationCacheInvalidate(void);
125 
126 extern void RelationCloseSmgrByOid(Oid relationId);
127 
128 #ifdef USE_ASSERT_CHECKING
129 extern void AssertPendingSyncs_RelationCache(void);
130 #else
131 #define AssertPendingSyncs_RelationCache() do {} while (0)
132 #endif
133 extern void AtEOXact_RelationCache(bool isCommit);
134 extern void AtEOSubXact_RelationCache(bool isCommit, SubTransactionId mySubid,
135  SubTransactionId parentSubid);
136 
137 /*
138  * Routines to help manage rebuilding of relcache init files
139  */
140 extern bool RelationIdIsInInitFile(Oid relationId);
141 extern void RelationCacheInitFilePreInvalidate(void);
142 extern void RelationCacheInitFilePostInvalidate(void);
143 extern void RelationCacheInitFileRemove(void);
144 
145 /* should be used only by relcache.c and catcache.c */
146 extern bool criticalRelcachesBuilt;
147 
148 /* should be used only by relcache.c and postinit.c */
149 extern bool criticalSharedRelcachesBuilt;
150 
151 #endif /* RELCACHE_H */
void RelationCacheInitFileRemove(void)
Definition: relcache.c:6340
void AtEOSubXact_RelationCache(bool isCommit, SubTransactionId mySubid, SubTransactionId parentSubid)
Definition: relcache.c:3215
List * RelationGetDummyIndexExpressions(Relation relation)
Definition: relcache.c:4808
int errtable(Relation rel)
Definition: relcache.c:5498
int errtableconstraint(Relation rel, const char *conname)
Definition: relcache.c:5552
void RelationCacheInitializePhase2(void)
Definition: relcache.c:3802
int errtablecolname(Relation rel, const char *colname)
Definition: relcache.c:5539
List * RelationGetIndexList(Relation relation)
Definition: relcache.c:4515
void RelationForgetRelation(Oid rid)
Definition: relcache.c:2745
uint32 SubTransactionId
Definition: c.h:579
bool criticalRelcachesBuilt
Definition: relcache.c:138
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:5515
void AtEOXact_RelationCache(bool isCommit)
Definition: relcache.c:3070
struct RelationData * Relation
Definition: relcache.h:27
unsigned short uint16
Definition: c.h:428
bool RelationIdIsInInitFile(Oid relationId)
Definition: relcache.c:6260
void RelationCacheInitFilePreInvalidate(void)
Definition: relcache.c:6300
Oid RelationGetReplicaIndex(Relation relation)
Definition: relcache.c:4724
void RelationInitTableAccessMethod(Relation relation)
Definition: relcache.c:1753
void RelationAssumeNewRelfilenode(Relation relation)
Definition: relcache.c:3739
#define AssertPendingSyncs_RelationCache()
Definition: relcache.h:131
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:3344
void RelationCacheInitializePhase3(void)
Definition: relcache.c:3861
Relation * RelationPtr
Definition: relcache.h:35
Datum * RelationGetIndexRawAttOptions(Relation relation)
Definition: relcache.c:5391
List * RelationGetIndexExpressions(Relation relation)
Definition: relcache.c:4749
void RelationCloseSmgrByOid(Oid relationId)
Definition: relcache.c:2935
void RelationClose(Relation relation)
Definition: relcache.c:2111
void RelationCacheInvalidateEntry(Oid relationId)
Definition: relcache.c:2789
uintptr_t Datum
Definition: postgres.h:367
void RelationCacheInitFilePostInvalidate(void)
Definition: relcache.c:6325
bool criticalSharedRelcachesBuilt
Definition: relcache.c:144
int16 attnum
Definition: pg_attribute.h:79
void RelationGetExclusionInfo(Relation indexRelation, Oid **operators, Oid **procs, uint16 **strategies)
Definition: relcache.c:5183
List * RelationGetFKeyList(Relation relation)
Definition: relcache.c:4406
void RelationCacheInitialize(void)
Definition: relcache.c:3765
struct PublicationActions * GetRelationPublicationActions(Relation relation)
Definition: relcache.c:5307
Bitmapset * RelationGetIndexAttrBitmap(Relation relation, IndexAttrBitmapKind attrKind)
Definition: relcache.c:4945
bytea ** RelationGetIndexAttOptions(Relation relation, bool copy)
Definition: relcache.c:5437
Oid RelationGetPrimaryKeyIndex(Relation relation)
Definition: relcache.c:4703
void RelationCacheInvalidate(void)
Definition: relcache.c:2832
Relation RelationIdGetRelation(Oid relationId)
Definition: relcache.c:2005
List * RelationGetStatExtList(Relation relation)
Definition: relcache.c:4634
Definition: c.h:617
Definition: pg_list.h:50
List * RelationGetIndexPredicate(Relation relation)
Definition: relcache.c:4862
void RelationSetNewRelfilenode(Relation relation, char persistence)
Definition: relcache.c:3588
void RelationInitIndexAccessInfo(Relation relation)
Definition: relcache.c:1373