| 921 | #endif |
| 922 | |
| 923 | static void |
| 924 | CatalogCacheInitializeCache(CatCache *cache) |
| 925 | { |
| 926 | Relation relation; |
| 927 | MemoryContext oldcxt; |
| 928 | TupleDesc tupdesc; |
| 929 | int i; |
| 930 | |
| 931 | CatalogCacheInitializeCache_DEBUG1; |
| 932 | |
| 933 | relation = table_open(cache->cc_reloid, AccessShareLock); |
| 934 | |
| 935 | /* |
| 936 | * switch to the cache context so our allocations do not vanish at the end |
| 937 | * of a transaction |
| 938 | */ |
| 939 | Assert(CacheMemoryContext != NULL); |
| 940 | |
| 941 | oldcxt = MemoryContextSwitchTo(CacheMemoryContext); |
| 942 | |
| 943 | /* |
| 944 | * copy the relcache's tuple descriptor to permanent cache storage |
| 945 | */ |
| 946 | tupdesc = CreateTupleDescCopyConstr(RelationGetDescr(relation)); |
| 947 | |
| 948 | /* |
| 949 | * save the relation's name and relisshared flag, too (cc_relname is used |
| 950 | * only for debugging purposes) |
| 951 | */ |
| 952 | cache->cc_relname = pstrdup(RelationGetRelationName(relation)); |
| 953 | cache->cc_relisshared = RelationGetForm(relation)->relisshared; |
| 954 | |
| 955 | /* |
| 956 | * return to the caller's memory context and close the rel |
| 957 | */ |
| 958 | MemoryContextSwitchTo(oldcxt); |
| 959 | |
| 960 | table_close(relation, AccessShareLock); |
| 961 | |
| 962 | CACHE_elog(DEBUG2, "CatalogCacheInitializeCache: %s, %d keys", |
| 963 | cache->cc_relname, cache->cc_nkeys); |
| 964 | |
| 965 | /* |
| 966 | * initialize cache's key information |
| 967 | */ |
| 968 | for (i = 0; i < cache->cc_nkeys; ++i) |
| 969 | { |
| 970 | Oid keytype; |
| 971 | RegProcedure eqfunc; |
| 972 | |
| 973 | CatalogCacheInitializeCache_DEBUG2; |
| 974 | |
| 975 | if (cache->cc_keyno[i] > 0) |
| 976 | { |
| 977 | Form_pg_attribute attr = TupleDescAttr(tupdesc, |
| 978 | cache->cc_keyno[i] - 1); |
| 979 | |
| 980 | keytype = attr->atttypid; |
no test coverage detected