35 #include "utils/fmgroids.h"
50 #define HASH_INDEX(h, sz) ((Index) ((h) & ((sz) - 1)))
58 #define CACHE_elog(...) elog(__VA_ARGS__)
60 #define CACHE_elog(...)
83 const Datum *cachekeys,
84 const Datum *searchkeys);
87 static void CatCachePrintStats(
int code,
Datum arg);
121 .
name =
"catcache reference",
131 .
name =
"catcache list reference",
291 case REGPROCEDUREOID:
296 case REGCOLLATIONOID:
298 case REGDICTIONARYOID:
300 case REGNAMESPACEOID:
308 *eqfunc = F_OIDVECTOREQ;
311 elog(
FATAL,
"type %u not supported as catcache key", keytype);
338 oneHash = (cc_hashfunc[3]) (v4);
342 oneHash = (cc_hashfunc[2]) (v3);
346 oneHash = (cc_hashfunc[1]) (v2);
350 oneHash = (cc_hashfunc[0]) (v1);
351 hashValue ^= oneHash;
354 elog(
FATAL,
"wrong number of hash keys: %d", nkeys);
409 elog(
FATAL,
"wrong number of hash keys: %d", nkeys);
423 const Datum *cachekeys,
424 const Datum *searchkeys)
429 for (
i = 0;
i < nkeys;
i++)
431 if (!(cc_fastequal[
i]) (cachekeys[
i], searchkeys[
i]))
438 #ifdef CATCACHE_STATS
441 CatCachePrintStats(
int code,
Datum arg)
444 long cc_searches = 0;
446 long cc_neg_hits = 0;
447 long cc_newloads = 0;
450 long cc_lsearches = 0;
457 if (cache->
cc_ntup == 0 && cache->cc_searches == 0)
459 elog(
DEBUG2,
"catcache %s/%u: %d tup, %ld srch, %ld+%ld=%ld hits, %ld+%ld=%ld loads, %ld invals, %d lists, %ld lsrch, %ld lhits",
466 cache->cc_hits + cache->cc_neg_hits,
468 cache->cc_searches - cache->cc_hits - cache->cc_neg_hits - cache->cc_newloads,
469 cache->cc_searches - cache->cc_hits - cache->cc_neg_hits,
474 cc_searches += cache->cc_searches;
475 cc_hits += cache->cc_hits;
476 cc_neg_hits += cache->cc_neg_hits;
477 cc_newloads += cache->cc_newloads;
478 cc_invals += cache->cc_invals;
480 cc_lsearches += cache->cc_lsearches;
481 cc_lhits += cache->cc_lhits;
483 elog(
DEBUG2,
"catcache totals: %d tup, %ld srch, %ld+%ld=%ld hits, %ld+%ld=%ld loads, %ld invals, %ld lists, %ld lsrch, %ld lhits",
488 cc_hits + cc_neg_hits,
490 cc_searches - cc_hits - cc_neg_hits - cc_newloads,
491 cc_searches - cc_hits - cc_neg_hits,
567 #ifndef CATCACHE_FORCE_RELEASE
657 #ifdef CATCACHE_STATS
687 "CacheMemoryContext",
740 #ifdef CATCACHE_STATS
816 #define InitCatCache_DEBUG2 \
818 elog(DEBUG2, "InitCatCache: rel=%u ind=%u id=%d nkeys=%d size=%d", \
819 cp->cc_reloid, cp->cc_indexoid, cp->id, \
820 cp->cc_nkeys, cp->cc_nbuckets); \
823 #define InitCatCache_DEBUG2
849 Assert(nbuckets > 0 && (nbuckets & -nbuckets) == nbuckets);
868 #ifdef CATCACHE_STATS
905 for (
i = 0;
i < nkeys; ++
i)
940 elog(
DEBUG1,
"rehashing catalog cache id %d for %s; %d tups, %d buckets",
978 elog(
DEBUG1,
"rehashing catalog cache id %d for %s; %d lists, %d buckets",
1014 #define CatalogCacheInitializeCache_DEBUG1 \
1015 elog(DEBUG2, "CatalogCacheInitializeCache: cache @%p rel=%u", cache, \
1018 #define CatalogCacheInitializeCache_DEBUG2 \
1020 if (cache->cc_keyno[i] > 0) { \
1021 elog(DEBUG2, "CatalogCacheInitializeCache: load %d/%d w/%d, %u", \
1022 i+1, cache->cc_nkeys, cache->cc_keyno[i], \
1023 TupleDescAttr(tupdesc, cache->cc_keyno[i] - 1)->atttypid); \
1025 elog(DEBUG2, "CatalogCacheInitializeCache: load %d/%d w/%d", \
1026 i+1, cache->cc_nkeys, cache->cc_keyno[i]); \
1030 #define CatalogCacheInitializeCache_DEBUG1
1031 #define CatalogCacheInitializeCache_DEBUG2
1091 keytype = attr->atttypid;
1093 Assert(attr->attnotnull);
1098 elog(
FATAL,
"sys attributes are not supported in caches");
1150 cache->
id != AMOID &&
1151 cache->
id != AMNAME)
1225 case AUTHMEMMEMROLE:
1337 #ifdef CATCACHE_STATS
1338 cache->cc_searches++;
1394 #ifdef CATCACHE_STATS
1405 #ifdef CATCACHE_STATS
1406 cache->cc_neg_hits++;
1496 hashValue, hashIndex);
1531 hashValue, hashIndex);
1554 #ifdef CATCACHE_STATS
1555 cache->cc_newloads++;
1593 #ifndef CATCACHE_FORCE_RELEASE
1660 List *
volatile ctlist;
1674 Assert(nkeys > 0 && nkeys < cache->cc_nkeys);
1676 #ifdef CATCACHE_STATS
1677 cache->cc_lsearches++;
1738 if (cl->
nkeys != nkeys)
1761 #ifdef CATCACHE_STATS
1811 ordered = (scandesc->
irel != NULL);
1858 hashValue, hashIndex);
1871 foreach(ctlist_item, ctlist)
1920 foreach(ctlist_item, ctlist)
1927 #ifndef CATCACHE_FORCE_RELEASE
1949 foreach(ctlist_item, ctlist)
2002 #ifndef CATCACHE_FORCE_RELEASE
2005 list->refcount == 0)
2046 #ifdef USE_ASSERT_CHECKING
2080 MAXIMUM_ALIGNOF + dtp->
t_len);
2088 (
const char *) dtp->
t_data,
2159 for (
i = 0;
i < nkeys;
i++)
2190 for (
i = 0;
i < nkeys;
i++)
2203 if (att->atttypid == NAMEOID)
2294 (*function) (ccp->
id, hashvalue, dbid);
2302 if (newhashvalue != hashvalue)
2303 (*function) (ccp->
id, newhashvalue, dbid);
2326 return psprintf(
"cache %s (%d), tuple %u/%u has count %d",
2344 return psprintf(
"cache %s (%d), list %p has count %d",
2345 list->my_cache->cc_relname,
list->my_cache->id,
#define AttributeNumberIsValid(attributeNumber)
#define PointerIsValid(pointer)
static bool chareqfast(Datum a, Datum b)
HeapTuple SearchCatCache2(CatCache *cache, Datum v1, Datum v2)
static bool int4eqfast(Datum a, Datum b)
HeapTuple SearchCatCache3(CatCache *cache, Datum v1, Datum v2, Datum v3)
void ReleaseCatCacheList(CatCList *list)
static void CatalogCacheInitializeCache(CatCache *cache)
static pg_noinline HeapTuple SearchCatCacheMiss(CatCache *cache, int nkeys, uint32 hashValue, Index hashIndex, Datum v1, Datum v2, Datum v3, Datum v4)
static bool int2eqfast(Datum a, Datum b)
static void ReleaseCatCacheWithOwner(HeapTuple tuple, ResourceOwner resowner)
static uint32 int4hashfast(Datum datum)
void InitCatCachePhase2(CatCache *cache, bool touch_index)
void ResetCatalogCaches(void)
static void ResOwnerReleaseCatCache(Datum res)
uint32 GetCatCacheHashValue(CatCache *cache, Datum v1, Datum v2, Datum v3, Datum v4)
static void CatCacheRemoveCTup(CatCache *cache, CatCTup *ct)
static char * ResOwnerPrintCatCache(Datum res)
static void RehashCatCache(CatCache *cp)
static uint32 CatalogCacheComputeTupleHashValue(CatCache *cache, int nkeys, HeapTuple tuple)
HeapTuple SearchCatCache4(CatCache *cache, Datum v1, Datum v2, Datum v3, Datum v4)
static void ResourceOwnerForgetCatCacheListRef(ResourceOwner owner, CatCList *list)
static CatCTup * CatalogCacheCreateEntry(CatCache *cache, HeapTuple ntp, SysScanDesc scandesc, Datum *arguments, uint32 hashValue, Index hashIndex)
static const ResourceOwnerDesc catcache_resowner_desc
static void ResOwnerReleaseCatCacheList(Datum res)
static void ResourceOwnerRememberCatCacheRef(ResourceOwner owner, HeapTuple tuple)
#define CatalogCacheInitializeCache_DEBUG1
static void CatCacheCopyKeys(TupleDesc tupdesc, int nkeys, int *attnos, Datum *srckeys, Datum *dstkeys)
static HeapTuple SearchCatCacheInternal(CatCache *cache, int nkeys, Datum v1, Datum v2, Datum v3, Datum v4)
CatCache * InitCatCache(int id, Oid reloid, Oid indexoid, int nkeys, const int *key, int nbuckets)
CatCList * SearchCatCacheList(CatCache *cache, int nkeys, Datum v1, Datum v2, Datum v3)
static char * ResOwnerPrintCatCacheList(Datum res)
static void ReleaseCatCacheListWithOwner(CatCList *list, ResourceOwner resowner)
static CatCacheHeader * CacheHdr
static uint32 namehashfast(Datum datum)
void CreateCacheMemoryContext(void)
static void ResetCatalogCache(CatCache *cache)
static const ResourceOwnerDesc catlistref_resowner_desc
void PrepareToInvalidateCacheTuple(Relation relation, HeapTuple tuple, HeapTuple newtuple, void(*function)(int, uint32, Oid))
static void GetCCHashEqFuncs(Oid keytype, CCHashFN *hashfunc, RegProcedure *eqfunc, CCFastEqualFN *fasteqfunc)
static uint32 CatalogCacheComputeHashValue(CatCache *cache, int nkeys, Datum v1, Datum v2, Datum v3, Datum v4)
static bool CatalogCacheCompareTuple(const CatCache *cache, int nkeys, const Datum *cachekeys, const Datum *searchkeys)
void CatCacheInvalidate(CatCache *cache, uint32 hashValue)
static void ResourceOwnerForgetCatCacheRef(ResourceOwner owner, HeapTuple tuple)
static bool nameeqfast(Datum a, Datum b)
static uint32 charhashfast(Datum datum)
static void RehashCatCacheLists(CatCache *cp)
HeapTuple SearchCatCache1(CatCache *cache, Datum v1)
#define InitCatCache_DEBUG2
static uint32 oidvectorhashfast(Datum datum)
static void ResourceOwnerRememberCatCacheListRef(ResourceOwner owner, CatCList *list)
static bool texteqfast(Datum a, Datum b)
static bool oidvectoreqfast(Datum a, Datum b)
void CatalogCacheFlushCatalog(Oid catId)
static uint32 int2hashfast(Datum datum)
#define CatalogCacheInitializeCache_DEBUG2
static void CatCacheFreeKeys(TupleDesc tupdesc, int nkeys, int *attnos, Datum *keys)
static void CatCacheRemoveCList(CatCache *cache, CatCList *cl)
#define HASH_INDEX(h, sz)
static bool IndexScanOK(CatCache *cache, ScanKey cur_skey)
static uint32 texthashfast(Datum datum)
void ReleaseCatCache(HeapTuple tuple)
HeapTuple SearchCatCache(CatCache *cache, Datum v1, Datum v2, Datum v3, Datum v4)
uint32(* CCHashFN)(Datum datum)
bool(* CCFastEqualFN)(Datum a, Datum b)
Datum datumCopy(Datum value, bool typByVal, int typLen)
static void PGresult * res
Datum DirectFunctionCall2Coll(PGFunction func, Oid collation, Datum arg1, Datum arg2)
void fmgr_info_cxt(Oid functionId, FmgrInfo *finfo, MemoryContext mcxt)
Datum DirectFunctionCall1Coll(PGFunction func, Oid collation, Datum arg1)
#define DirectFunctionCall2(func, arg1, arg2)
#define DirectFunctionCall1(func, arg1)
void systable_endscan(SysScanDesc sysscan)
bool systable_recheck_tuple(SysScanDesc sysscan, HeapTuple tup)
HeapTuple systable_getnext(SysScanDesc sysscan)
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
static uint32 murmurhash32(uint32 data)
static Datum hash_any(const unsigned char *k, int keylen)
Datum hashoidvector(PG_FUNCTION_ARGS)
Datum hashtext(PG_FUNCTION_ARGS)
HeapTuple toast_flatten_tuple(HeapTuple tup, TupleDesc tupleDesc)
void heap_freetuple(HeapTuple htup)
HeapTupleData * HeapTuple
HeapTupleHeaderData * HeapTupleHeader
#define HeapTupleIsValid(tuple)
static Datum heap_getattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
#define HeapTupleHasExternal(tuple)
static Datum fastgetattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
#define dlist_foreach(iter, lhead)
static void dlist_delete(dlist_node *node)
static void slist_init(slist_head *head)
static void dlist_push_head(dlist_head *head, dlist_node *node)
#define dlist_foreach_modify(iter, lhead)
static void slist_push_head(slist_head *head, slist_node *node)
#define slist_container(type, membername, ptr)
static void dlist_move_head(dlist_head *head, dlist_node *node)
#define slist_foreach(iter, lhead)
#define dlist_container(type, membername, ptr)
void index_close(Relation relation, LOCKMODE lockmode)
Relation index_open(Oid relationId, LOCKMODE lockmode)
void CallSyscacheCallbacks(int cacheid, uint32 hashvalue)
void on_proc_exit(pg_on_exit_callback function, Datum arg)
bool ItemPointerEquals(ItemPointer pointer1, ItemPointer pointer2)
static OffsetNumber ItemPointerGetOffsetNumber(const ItemPointerData *pointer)
static BlockNumber ItemPointerGetBlockNumber(const ItemPointerData *pointer)
Assert(fmt[strlen(fmt) - 1] !='\n')
List * lappend(List *list, void *datum)
void UnlockRelationOid(Oid relid, LOCKMODE lockmode)
void LockRelationOid(Oid relid, LOCKMODE lockmode)
char * pstrdup(const char *in)
void pfree(void *pointer)
MemoryContext TopMemoryContext
void * palloc0(Size size)
void * MemoryContextAllocZero(MemoryContext context, Size size)
void * palloc_aligned(Size size, Size alignto, int flags)
MemoryContext CacheMemoryContext
#define AllocSetContextCreate
#define ALLOCSET_DEFAULT_SIZES
#define IsBootstrapProcessingMode()
void namestrcpy(Name name, const char *str)
Datum oidvectoreq(PG_FUNCTION_ARGS)
FormData_pg_attribute * Form_pg_attribute
static uint32 pg_rotate_left32(uint32 word, int n)
#define PG_CACHE_LINE_SIZE
static int list_length(const List *l)
uint32 pg_prng_uint32(pg_prng_state *state)
pg_prng_state pg_global_prng_state
static bool DatumGetBool(Datum X)
static Datum PointerGetDatum(const void *X)
static Name DatumGetName(Datum X)
static char * DatumGetCString(Datum X)
static Datum NameGetDatum(const NameData *X)
static Pointer DatumGetPointer(Datum X)
static char DatumGetChar(Datum X)
static int16 DatumGetInt16(Datum X)
static int32 DatumGetInt32(Datum X)
char * psprintf(const char *fmt,...)
MemoryContextSwitchTo(old_ctx)
#define RelationGetForm(relation)
#define RelationGetRelid(relation)
#define RelationGetDescr(relation)
#define RelationGetRelationName(relation)
#define RelationIsValid(relation)
bool criticalRelcachesBuilt
bool criticalSharedRelcachesBuilt
ResourceOwner CurrentResourceOwner
void ResourceOwnerForget(ResourceOwner owner, Datum value, const ResourceOwnerDesc *kind)
void ResourceOwnerRemember(ResourceOwner owner, Datum value, const ResourceOwnerDesc *kind)
void ResourceOwnerEnlarge(ResourceOwner owner)
#define RELEASE_PRIO_CATCACHE_LIST_REFS
@ RESOURCE_RELEASE_AFTER_LOCKS
#define RELEASE_PRIO_CATCACHE_REFS
#define BTEqualStrategyNumber
StrategyNumber sk_strategy
CCHashFN cc_hashfunc[CATCACHE_MAXKEYS]
int cc_keyno[CATCACHE_MAXKEYS]
CCFastEqualFN cc_fastequal[CATCACHE_MAXKEYS]
ScanKeyData cc_skey[CATCACHE_MAXKEYS]
Datum keys[CATCACHE_MAXKEYS]
CatCTup * members[FLEXIBLE_ARRAY_MEMBER]
Datum keys[CATCACHE_MAXKEYS]
void table_close(Relation relation, LOCKMODE lockmode)
Relation table_open(Oid relationId, LOCKMODE lockmode)
TupleDesc CreateTupleDescCopyConstr(TupleDesc tupdesc)
struct TupleDescData * TupleDesc
#define TupleDescAttr(tupdesc, i)
Datum texteq(PG_FUNCTION_ARGS)
bool IsTransactionState(void)