1 /*-------------------------------------------------------------------------
2  *
3  * relcache.h
4  *	  Relation descriptor cache definitions.
5  *
6  *
7  * Portions Copyright (c) 1996-2017, 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 "access/tupdesc.h"
18 #include "nodes/bitmapset.h"
19 
20 
21 typedef struct RelationData *Relation;
22 
23 /* ----------------
24  *		RelationPtr is used in the executor to support index scans
25  *		where we have to keep track of several index relations in an
26  *		array.  -cim 9/10/89
27  * ----------------
28  */
29 typedef Relation *RelationPtr;
30 
31 /*
32  * Routines to open (lookup) and close a relcache entry
33  */
34 extern Relation RelationIdGetRelation(Oid relationId);
35 extern void RelationClose(Relation relation);
36 
37 /*
38  * Routines to compute/retrieve additional cached information
39  */
40 extern List *RelationGetFKeyList(Relation relation);
41 extern List *RelationGetIndexList(Relation relation);
42 extern List *RelationGetStatExtList(Relation relation);
43 extern Oid	RelationGetOidIndex(Relation relation);
44 extern Oid	RelationGetPrimaryKeyIndex(Relation relation);
45 extern Oid	RelationGetReplicaIndex(Relation relation);
46 extern List *RelationGetIndexExpressions(Relation relation);
47 extern List *RelationGetDummyIndexExpressions(Relation relation);
48 extern List *RelationGetIndexPredicate(Relation relation);
49 
50 typedef enum IndexAttrBitmapKind
51 {
52 	INDEX_ATTR_BITMAP_ALL,
53 	INDEX_ATTR_BITMAP_KEY,
54 	INDEX_ATTR_BITMAP_PRIMARY_KEY,
55 	INDEX_ATTR_BITMAP_IDENTITY_KEY
56 } IndexAttrBitmapKind;
57 
58 extern Bitmapset *RelationGetIndexAttrBitmap(Relation relation,
59 						   IndexAttrBitmapKind keyAttrs);
60 
61 extern void RelationGetExclusionInfo(Relation indexRelation,
62 						 Oid **operators,
63 						 Oid **procs,
64 						 uint16 **strategies);
65 
66 extern void RelationSetIndexList(Relation relation,
67 					 List *indexIds, Oid oidIndex);
68 
69 extern void RelationInitIndexAccessInfo(Relation relation);
70 
71 /* caller must include pg_publication.h */
72 struct PublicationActions;
73 extern struct PublicationActions *GetRelationPublicationActions(Relation relation);
74 
75 /*
76  * Routines to support ereport() reports of relation-related errors
77  */
78 extern int	errtable(Relation rel);
79 extern int	errtablecol(Relation rel, int attnum);
80 extern int	errtablecolname(Relation rel, const char *colname);
81 extern int	errtableconstraint(Relation rel, const char *conname);
82 
83 /*
84  * Routines for backend startup
85  */
86 extern void RelationCacheInitialize(void);
87 extern void RelationCacheInitializePhase2(void);
88 extern void RelationCacheInitializePhase3(void);
89 
90 /*
91  * Routine to create a relcache entry for an about-to-be-created relation
92  */
93 extern Relation RelationBuildLocalRelation(const char *relname,
94 						   Oid relnamespace,
95 						   TupleDesc tupDesc,
96 						   Oid relid,
97 						   Oid relfilenode,
98 						   Oid reltablespace,
99 						   bool shared_relation,
100 						   bool mapped_relation,
101 						   char relpersistence,
102 						   char relkind);
103 
104 /*
105  * Routine to manage assignment of new relfilenode to a relation
106  */
107 extern void RelationSetNewRelfilenode(Relation relation, char persistence,
108 						  TransactionId freezeXid, MultiXactId minmulti);
109 
110 /*
111  * Routines for flushing/rebuilding relcache entries in various scenarios
112  */
113 extern void RelationForgetRelation(Oid rid);
114 
115 extern void RelationCacheInvalidateEntry(Oid relationId);
116 
117 extern void RelationCacheInvalidate(bool debug_discard);
118 
119 extern void RelationCloseSmgrByOid(Oid relationId);
120 
121 extern void AtEOXact_RelationCache(bool isCommit);
122 extern void AtEOSubXact_RelationCache(bool isCommit, SubTransactionId mySubid,
123 						  SubTransactionId parentSubid);
124 
125 /*
126  * Routines to help manage rebuilding of relcache init files
127  */
128 extern bool RelationIdIsInInitFile(Oid relationId);
129 extern void RelationCacheInitFilePreInvalidate(void);
130 extern void RelationCacheInitFilePostInvalidate(void);
131 extern void RelationCacheInitFileRemove(void);
132 
133 /* should be used only by relcache.c and catcache.c */
134 extern bool criticalRelcachesBuilt;
135 
136 /* should be used only by relcache.c and postinit.c */
137 extern bool criticalSharedRelcachesBuilt;
138 
139 #endif							/* RELCACHE_H */
140