1 /*-------------------------------------------------------------------------
2  *
3  * syscache.h
4  *	  System catalog cache definitions.
5  *
6  * See also lsyscache.h, which provides convenience routines for
7  * common cache-lookup operations.
8  *
9  * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group
10  * Portions Copyright (c) 1994, Regents of the University of California
11  *
12  * src/include/utils/syscache.h
13  *
14  *-------------------------------------------------------------------------
15  */
16 #ifndef SYSCACHE_H
17 #define SYSCACHE_H
18 
19 #include "access/attnum.h"
20 #include "access/htup.h"
21 /* we intentionally do not include utils/catcache.h here */
22 
23 /*
24  *		SysCache identifiers.
25  *
26  *		The order of these identifiers must match the order
27  *		of the entries in the array cacheinfo[] in syscache.c.
28  *		Keep them in alphabetical order (renumbering only costs a
29  *		backend rebuild).
30  */
31 
32 enum SysCacheIdentifier
33 {
34 	AGGFNOID = 0,
35 	AMNAME,
36 	AMOID,
37 	AMOPOPID,
38 	AMOPSTRATEGY,
39 	AMPROCNUM,
40 	ATTNAME,
41 	ATTNUM,
42 	AUTHMEMMEMROLE,
43 	AUTHMEMROLEMEM,
44 	AUTHNAME,
45 	AUTHOID,
46 	CASTSOURCETARGET,
47 	CLAAMNAMENSP,
48 	CLAOID,
49 	COLLNAMEENCNSP,
50 	COLLOID,
51 	CONDEFAULT,
52 	CONNAMENSP,
53 	CONSTROID,
54 	CONVOID,
55 	DATABASEOID,
56 	DEFACLROLENSPOBJ,
57 	ENUMOID,
58 	ENUMTYPOIDNAME,
59 	EVENTTRIGGERNAME,
60 	EVENTTRIGGEROID,
61 	FOREIGNDATAWRAPPERNAME,
62 	FOREIGNDATAWRAPPEROID,
63 	FOREIGNSERVERNAME,
64 	FOREIGNSERVEROID,
65 	FOREIGNTABLEREL,
66 	INDEXRELID,
67 	LANGNAME,
68 	LANGOID,
69 	NAMESPACENAME,
70 	NAMESPACEOID,
71 	OPERNAMENSP,
72 	OPEROID,
73 	OPFAMILYAMNAMENSP,
74 	OPFAMILYOID,
75 	PARTRELID,
76 	PROCNAMEARGSNSP,
77 	PROCOID,
78 	PUBLICATIONNAME,
79 	PUBLICATIONOID,
80 	PUBLICATIONREL,
81 	PUBLICATIONRELMAP,
82 	RANGETYPE,
83 	RELNAMENSP,
84 	RELOID,
85 	REPLORIGIDENT,
86 	REPLORIGNAME,
87 	RULERELNAME,
88 	SEQRELID,
89 	STATEXTDATASTXOID,
90 	STATEXTNAMENSP,
91 	STATEXTOID,
92 	STATRELATTINH,
93 	SUBSCRIPTIONNAME,
94 	SUBSCRIPTIONOID,
95 	SUBSCRIPTIONRELMAP,
96 	TABLESPACEOID,
97 	TRFOID,
98 	TRFTYPELANG,
99 	TSCONFIGMAP,
100 	TSCONFIGNAMENSP,
101 	TSCONFIGOID,
102 	TSDICTNAMENSP,
103 	TSDICTOID,
104 	TSPARSERNAMENSP,
105 	TSPARSEROID,
106 	TSTEMPLATENAMENSP,
107 	TSTEMPLATEOID,
108 	TYPENAMENSP,
109 	TYPEOID,
110 	USERMAPPINGOID,
111 	USERMAPPINGUSERSERVER
112 
113 #define SysCacheSize (USERMAPPINGUSERSERVER + 1)
114 };
115 
116 extern void InitCatalogCache(void);
117 extern void InitCatalogCachePhase2(void);
118 
119 extern HeapTuple SearchSysCache(int cacheId,
120 								Datum key1, Datum key2, Datum key3, Datum key4);
121 
122 /*
123  * The use of argument specific numbers is encouraged. They're faster, and
124  * insulates the caller from changes in the maximum number of keys.
125  */
126 extern HeapTuple SearchSysCache1(int cacheId,
127 								 Datum key1);
128 extern HeapTuple SearchSysCache2(int cacheId,
129 								 Datum key1, Datum key2);
130 extern HeapTuple SearchSysCache3(int cacheId,
131 								 Datum key1, Datum key2, Datum key3);
132 extern HeapTuple SearchSysCache4(int cacheId,
133 								 Datum key1, Datum key2, Datum key3, Datum key4);
134 
135 extern void ReleaseSysCache(HeapTuple tuple);
136 
137 /* convenience routines */
138 extern HeapTuple SearchSysCacheCopy(int cacheId,
139 									Datum key1, Datum key2, Datum key3, Datum key4);
140 extern bool SearchSysCacheExists(int cacheId,
141 								 Datum key1, Datum key2, Datum key3, Datum key4);
142 extern Oid	GetSysCacheOid(int cacheId, AttrNumber oidcol,
143 						   Datum key1, Datum key2, Datum key3, Datum key4);
144 
145 extern HeapTuple SearchSysCacheAttName(Oid relid, const char *attname);
146 extern HeapTuple SearchSysCacheCopyAttName(Oid relid, const char *attname);
147 extern bool SearchSysCacheExistsAttName(Oid relid, const char *attname);
148 
149 extern HeapTuple SearchSysCacheAttNum(Oid relid, int16 attnum);
150 extern HeapTuple SearchSysCacheCopyAttNum(Oid relid, int16 attnum);
151 
152 extern Datum SysCacheGetAttr(int cacheId, HeapTuple tup,
153 							 AttrNumber attributeNumber, bool *isNull);
154 
155 extern uint32 GetSysCacheHashValue(int cacheId,
156 								   Datum key1, Datum key2, Datum key3, Datum key4);
157 
158 /* list-search interface.  Users of this must import catcache.h too */
159 struct catclist;
160 extern struct catclist *SearchSysCacheList(int cacheId, int nkeys,
161 										   Datum key1, Datum key2, Datum key3);
162 
163 extern void SysCacheInvalidate(int cacheId, uint32 hashValue);
164 
165 extern bool RelationInvalidatesSnapshotsOnly(Oid relid);
166 extern bool RelationHasSysCache(Oid relid);
167 extern bool RelationSupportsSysCache(Oid relid);
168 
169 /*
170  * The use of the macros below rather than direct calls to the corresponding
171  * functions is encouraged, as it insulates the caller from changes in the
172  * maximum number of keys.
173  */
174 #define SearchSysCacheCopy1(cacheId, key1) \
175 	SearchSysCacheCopy(cacheId, key1, 0, 0, 0)
176 #define SearchSysCacheCopy2(cacheId, key1, key2) \
177 	SearchSysCacheCopy(cacheId, key1, key2, 0, 0)
178 #define SearchSysCacheCopy3(cacheId, key1, key2, key3) \
179 	SearchSysCacheCopy(cacheId, key1, key2, key3, 0)
180 #define SearchSysCacheCopy4(cacheId, key1, key2, key3, key4) \
181 	SearchSysCacheCopy(cacheId, key1, key2, key3, key4)
182 
183 #define SearchSysCacheExists1(cacheId, key1) \
184 	SearchSysCacheExists(cacheId, key1, 0, 0, 0)
185 #define SearchSysCacheExists2(cacheId, key1, key2) \
186 	SearchSysCacheExists(cacheId, key1, key2, 0, 0)
187 #define SearchSysCacheExists3(cacheId, key1, key2, key3) \
188 	SearchSysCacheExists(cacheId, key1, key2, key3, 0)
189 #define SearchSysCacheExists4(cacheId, key1, key2, key3, key4) \
190 	SearchSysCacheExists(cacheId, key1, key2, key3, key4)
191 
192 #define GetSysCacheOid1(cacheId, oidcol, key1) \
193 	GetSysCacheOid(cacheId, oidcol, key1, 0, 0, 0)
194 #define GetSysCacheOid2(cacheId, oidcol, key1, key2) \
195 	GetSysCacheOid(cacheId, oidcol, key1, key2, 0, 0)
196 #define GetSysCacheOid3(cacheId, oidcol, key1, key2, key3) \
197 	GetSysCacheOid(cacheId, oidcol, key1, key2, key3, 0)
198 #define GetSysCacheOid4(cacheId, oidcol, key1, key2, key3, key4) \
199 	GetSysCacheOid(cacheId, oidcol, key1, key2, key3, key4)
200 
201 #define GetSysCacheHashValue1(cacheId, key1) \
202 	GetSysCacheHashValue(cacheId, key1, 0, 0, 0)
203 #define GetSysCacheHashValue2(cacheId, key1, key2) \
204 	GetSysCacheHashValue(cacheId, key1, key2, 0, 0)
205 #define GetSysCacheHashValue3(cacheId, key1, key2, key3) \
206 	GetSysCacheHashValue(cacheId, key1, key2, key3, 0)
207 #define GetSysCacheHashValue4(cacheId, key1, key2, key3, key4) \
208 	GetSysCacheHashValue(cacheId, key1, key2, key3, key4)
209 
210 #define SearchSysCacheList1(cacheId, key1) \
211 	SearchSysCacheList(cacheId, 1, key1, 0, 0)
212 #define SearchSysCacheList2(cacheId, key1, key2) \
213 	SearchSysCacheList(cacheId, 2, key1, key2, 0)
214 #define SearchSysCacheList3(cacheId, key1, key2, key3) \
215 	SearchSysCacheList(cacheId, 3, key1, key2, key3)
216 
217 #define ReleaseSysCacheList(x)	ReleaseCatCacheList(x)
218 
219 #endif							/* SYSCACHE_H */
220