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-2017, 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 	STATEXTNAMENSP,
90 	STATEXTOID,
91 	STATRELATTINH,
92 	SUBSCRIPTIONNAME,
93 	SUBSCRIPTIONOID,
94 	SUBSCRIPTIONRELMAP,
95 	TABLESPACEOID,
96 	TRFOID,
97 	TRFTYPELANG,
98 	TSCONFIGMAP,
99 	TSCONFIGNAMENSP,
100 	TSCONFIGOID,
101 	TSDICTNAMENSP,
102 	TSDICTOID,
103 	TSPARSERNAMENSP,
104 	TSPARSEROID,
105 	TSTEMPLATENAMENSP,
106 	TSTEMPLATEOID,
107 	TYPENAMENSP,
108 	TYPEOID,
109 	USERMAPPINGOID,
110 	USERMAPPINGUSERSERVER
111 
112 #define SysCacheSize (USERMAPPINGUSERSERVER + 1)
113 };
114 
115 extern void InitCatalogCache(void);
116 extern void InitCatalogCachePhase2(void);
117 
118 extern HeapTuple SearchSysCache(int cacheId,
119 			   Datum key1, Datum key2, Datum key3, Datum key4);
120 extern void ReleaseSysCache(HeapTuple tuple);
121 
122 /* convenience routines */
123 extern HeapTuple SearchSysCacheCopy(int cacheId,
124 				   Datum key1, Datum key2, Datum key3, Datum key4);
125 extern bool SearchSysCacheExists(int cacheId,
126 					 Datum key1, Datum key2, Datum key3, Datum key4);
127 extern Oid GetSysCacheOid(int cacheId,
128 			   Datum key1, Datum key2, Datum key3, Datum key4);
129 
130 extern HeapTuple SearchSysCacheAttName(Oid relid, const char *attname);
131 extern HeapTuple SearchSysCacheCopyAttName(Oid relid, const char *attname);
132 extern bool SearchSysCacheExistsAttName(Oid relid, const char *attname);
133 
134 extern Datum SysCacheGetAttr(int cacheId, HeapTuple tup,
135 				AttrNumber attributeNumber, bool *isNull);
136 
137 extern uint32 GetSysCacheHashValue(int cacheId,
138 					 Datum key1, Datum key2, Datum key3, Datum key4);
139 
140 /* list-search interface.  Users of this must import catcache.h too */
141 struct catclist;
142 extern struct catclist *SearchSysCacheList(int cacheId, int nkeys,
143 				   Datum key1, Datum key2, Datum key3, Datum key4);
144 
145 extern void SysCacheInvalidate(int cacheId, uint32 hashValue);
146 
147 extern bool RelationInvalidatesSnapshotsOnly(Oid relid);
148 extern bool RelationHasSysCache(Oid relid);
149 extern bool RelationSupportsSysCache(Oid relid);
150 
151 /*
152  * The use of the macros below rather than direct calls to the corresponding
153  * functions is encouraged, as it insulates the caller from changes in the
154  * maximum number of keys.
155  */
156 #define SearchSysCache1(cacheId, key1) \
157 	SearchSysCache(cacheId, key1, 0, 0, 0)
158 #define SearchSysCache2(cacheId, key1, key2) \
159 	SearchSysCache(cacheId, key1, key2, 0, 0)
160 #define SearchSysCache3(cacheId, key1, key2, key3) \
161 	SearchSysCache(cacheId, key1, key2, key3, 0)
162 #define SearchSysCache4(cacheId, key1, key2, key3, key4) \
163 	SearchSysCache(cacheId, key1, key2, key3, key4)
164 
165 #define SearchSysCacheCopy1(cacheId, key1) \
166 	SearchSysCacheCopy(cacheId, key1, 0, 0, 0)
167 #define SearchSysCacheCopy2(cacheId, key1, key2) \
168 	SearchSysCacheCopy(cacheId, key1, key2, 0, 0)
169 #define SearchSysCacheCopy3(cacheId, key1, key2, key3) \
170 	SearchSysCacheCopy(cacheId, key1, key2, key3, 0)
171 #define SearchSysCacheCopy4(cacheId, key1, key2, key3, key4) \
172 	SearchSysCacheCopy(cacheId, key1, key2, key3, key4)
173 
174 #define SearchSysCacheExists1(cacheId, key1) \
175 	SearchSysCacheExists(cacheId, key1, 0, 0, 0)
176 #define SearchSysCacheExists2(cacheId, key1, key2) \
177 	SearchSysCacheExists(cacheId, key1, key2, 0, 0)
178 #define SearchSysCacheExists3(cacheId, key1, key2, key3) \
179 	SearchSysCacheExists(cacheId, key1, key2, key3, 0)
180 #define SearchSysCacheExists4(cacheId, key1, key2, key3, key4) \
181 	SearchSysCacheExists(cacheId, key1, key2, key3, key4)
182 
183 #define GetSysCacheOid1(cacheId, key1) \
184 	GetSysCacheOid(cacheId, key1, 0, 0, 0)
185 #define GetSysCacheOid2(cacheId, key1, key2) \
186 	GetSysCacheOid(cacheId, key1, key2, 0, 0)
187 #define GetSysCacheOid3(cacheId, key1, key2, key3) \
188 	GetSysCacheOid(cacheId, key1, key2, key3, 0)
189 #define GetSysCacheOid4(cacheId, key1, key2, key3, key4) \
190 	GetSysCacheOid(cacheId, key1, key2, key3, key4)
191 
192 #define GetSysCacheHashValue1(cacheId, key1) \
193 	GetSysCacheHashValue(cacheId, key1, 0, 0, 0)
194 #define GetSysCacheHashValue2(cacheId, key1, key2) \
195 	GetSysCacheHashValue(cacheId, key1, key2, 0, 0)
196 #define GetSysCacheHashValue3(cacheId, key1, key2, key3) \
197 	GetSysCacheHashValue(cacheId, key1, key2, key3, 0)
198 #define GetSysCacheHashValue4(cacheId, key1, key2, key3, key4) \
199 	GetSysCacheHashValue(cacheId, key1, key2, key3, key4)
200 
201 #define SearchSysCacheList1(cacheId, key1) \
202 	SearchSysCacheList(cacheId, 1, key1, 0, 0, 0)
203 #define SearchSysCacheList2(cacheId, key1, key2) \
204 	SearchSysCacheList(cacheId, 2, key1, key2, 0, 0)
205 #define SearchSysCacheList3(cacheId, key1, key2, key3) \
206 	SearchSysCacheList(cacheId, 3, key1, key2, key3, 0)
207 #define SearchSysCacheList4(cacheId, key1, key2, key3, key4) \
208 	SearchSysCacheList(cacheId, 4, key1, key2, key3, key4)
209 
210 #define ReleaseSysCacheList(x)	ReleaseCatCacheList(x)
211 
212 #endif							/* SYSCACHE_H */
213