* InitCatCachePhase2 -- external interface for CatalogCacheInitializeCache * * One reason to call this routine is to ensure that the relcache has * created entries for all the catalogs and indexes referenced by catcaches. * Therefore, provide an option to open the index as well as fixing the * cache itself. An exception is the indexes on pg_am, which we don't use * (cf. IndexScanOK). */
| 1030 | * (cf. IndexScanOK). |
| 1031 | */ |
| 1032 | void |
| 1033 | InitCatCachePhase2(CatCache *cache, bool touch_index) |
| 1034 | { |
| 1035 | if (cache->cc_tupdesc == NULL) |
| 1036 | CatalogCacheInitializeCache(cache); |
| 1037 | |
| 1038 | if (touch_index && |
| 1039 | cache->id != AMOID && |
| 1040 | cache->id != AMNAME) |
| 1041 | { |
| 1042 | Relation idesc; |
| 1043 | |
| 1044 | /* |
| 1045 | * We must lock the underlying catalog before opening the index to |
| 1046 | * avoid deadlock, since index_open could possibly result in reading |
| 1047 | * this same catalog, and if anyone else is exclusive-locking this |
| 1048 | * catalog and index they'll be doing it in that order. |
| 1049 | */ |
| 1050 | LockRelationOid(cache->cc_reloid, AccessShareLock); |
| 1051 | idesc = index_open(cache->cc_indexoid, AccessShareLock); |
| 1052 | |
| 1053 | /* |
| 1054 | * While we've got the index open, let's check that it's unique (and |
| 1055 | * not just deferrable-unique, thank you very much). This is just to |
| 1056 | * catch thinkos in definitions of new catcaches, so we don't worry |
| 1057 | * about the pg_am indexes not getting tested. |
| 1058 | */ |
| 1059 | Assert(idesc->rd_index->indisunique && |
| 1060 | idesc->rd_index->indimmediate); |
| 1061 | |
| 1062 | index_close(idesc, AccessShareLock); |
| 1063 | UnlockRelationOid(cache->cc_reloid, AccessShareLock); |
| 1064 | } |
| 1065 | } |
| 1066 | |
| 1067 | |
| 1068 | /* |
no test coverage detected