* InitCatalogCache - initialize the caches * * Note that no database access is done here; we only allocate memory * and initialize the cache structure. Interrogation of the database * to complete initialization of a cache happens upon first use * of that cache. */
| 1247 | * of that cache. |
| 1248 | */ |
| 1249 | void |
| 1250 | InitCatalogCache(void) |
| 1251 | { |
| 1252 | int cacheId; |
| 1253 | |
| 1254 | StaticAssertStmt(SysCacheSize == (int) lengthof(cacheinfo), |
| 1255 | "SysCacheSize does not match syscache.c's array"); |
| 1256 | |
| 1257 | Assert(!CacheInitialized); |
| 1258 | |
| 1259 | SysCacheRelationOidSize = SysCacheSupportingRelOidSize = 0; |
| 1260 | |
| 1261 | for (cacheId = 0; cacheId < SysCacheSize; cacheId++) |
| 1262 | { |
| 1263 | SysCache[cacheId] = InitCatCache(cacheId, |
| 1264 | cacheinfo[cacheId].reloid, |
| 1265 | cacheinfo[cacheId].indoid, |
| 1266 | cacheinfo[cacheId].nkeys, |
| 1267 | cacheinfo[cacheId].key, |
| 1268 | cacheinfo[cacheId].nbuckets); |
| 1269 | if (!PointerIsValid(SysCache[cacheId])) |
| 1270 | elog(ERROR, "could not initialize cache %u (%d)", |
| 1271 | cacheinfo[cacheId].reloid, cacheId); |
| 1272 | /* Accumulate data for OID lists, too */ |
| 1273 | SysCacheRelationOid[SysCacheRelationOidSize++] = |
| 1274 | cacheinfo[cacheId].reloid; |
| 1275 | SysCacheSupportingRelOid[SysCacheSupportingRelOidSize++] = |
| 1276 | cacheinfo[cacheId].reloid; |
| 1277 | SysCacheSupportingRelOid[SysCacheSupportingRelOidSize++] = |
| 1278 | cacheinfo[cacheId].indoid; |
| 1279 | /* see comments for RelationInvalidatesSnapshotsOnly */ |
| 1280 | Assert(!RelationInvalidatesSnapshotsOnly(cacheinfo[cacheId].reloid)); |
| 1281 | } |
| 1282 | |
| 1283 | Assert(SysCacheRelationOidSize <= lengthof(SysCacheRelationOid)); |
| 1284 | Assert(SysCacheSupportingRelOidSize <= lengthof(SysCacheSupportingRelOid)); |
| 1285 | |
| 1286 | /* Sort and de-dup OID arrays, so we can use binary search. */ |
| 1287 | pg_qsort(SysCacheRelationOid, SysCacheRelationOidSize, |
| 1288 | sizeof(Oid), oid_compare); |
| 1289 | SysCacheRelationOidSize = |
| 1290 | qunique(SysCacheRelationOid, SysCacheRelationOidSize, sizeof(Oid), |
| 1291 | oid_compare); |
| 1292 | |
| 1293 | pg_qsort(SysCacheSupportingRelOid, SysCacheSupportingRelOidSize, |
| 1294 | sizeof(Oid), oid_compare); |
| 1295 | SysCacheSupportingRelOidSize = |
| 1296 | qunique(SysCacheSupportingRelOid, SysCacheSupportingRelOidSize, |
| 1297 | sizeof(Oid), oid_compare); |
| 1298 | |
| 1299 | CacheInitialized = true; |
| 1300 | } |
| 1301 | |
| 1302 | /* |
| 1303 | * InitCatalogCachePhase2 - finish initializing the caches |
no test coverage detected