36#include "utils/fmgroids.h"
70#define HASH_INDEX(h, sz) ((Index) ((h) & ((sz) - 1)))
78#define CACHE_elog(...) elog(__VA_ARGS__)
80#define CACHE_elog(...)
140 .
name =
"catcache reference",
150 .
name =
"catcache list reference",
374 elog(
FATAL,
"wrong number of hash keys: %d", nkeys);
429 elog(
FATAL,
"wrong number of hash keys: %d", nkeys);
449 for (
i = 0;
i < nkeys;
i++)
482 " lsrch, %" PRIu64 " lhits",
509 " lsrch, %" PRIu64 " lhits",
585 for (
i =
cl->n_members; --
i >= 0;)
656 if (
cl->refcount > 0)
671 if (hashValue ==
ct->hash_value)
673 if (
ct->refcount > 0 ||
674 (
ct->c_list &&
ct->c_list->refcount > 0))
695 if (
e->list ||
e->hash_value == hashValue)
723 "CacheMemoryContext",
757 if (
cl->refcount > 0)
773 if (
ct->refcount > 0 ||
774 (
ct->c_list &&
ct->c_list->refcount > 0))
874#define InitCatCache_DEBUG2 \
876 elog(DEBUG2, "InitCatCache: rel=%u ind=%u id=%d nkeys=%d size=%d", \
877 cp->cc_reloid, cp->cc_indexoid, cp->id, \
878 cp->cc_nkeys, cp->cc_nbuckets); \
881#define InitCatCache_DEBUG2
907 Assert(nbuckets > 0 && (nbuckets & -nbuckets) == nbuckets);
953 cp->cc_relname =
"(not known yet)";
954 cp->cc_reloid = reloid;
955 cp->cc_indexoid = indexoid;
956 cp->cc_relisshared =
false;
960 cp->cc_nbuckets = nbuckets;
961 cp->cc_nlbuckets = 0;
962 cp->cc_nkeys = nkeys;
963 for (
i = 0;
i < nkeys; ++
i)
966 cp->cc_keyno[
i] = key[
i];
998 elog(
DEBUG1,
"rehashing catalog cache id %d for %s; %d tups, %d buckets",
999 cp->id,
cp->cc_relname,
cp->cc_ntup,
cp->cc_nbuckets);
1006 for (
i = 0;
i <
cp->cc_nbuckets;
i++)
1043 elog(
DEBUG1,
"rehashing catalog cache id %d for %s; %d lists, %d buckets",
1044 cp->id,
cp->cc_relname,
cp->cc_nlist,
cp->cc_nlbuckets);
1051 for (
i = 0;
i <
cp->cc_nlbuckets;
i++)
1087#ifdef USE_ASSERT_CHECKING
1115#define CatalogCacheInitializeCache_DEBUG1 \
1116 elog(DEBUG2, "CatalogCacheInitializeCache: cache @%p rel=%u", cache, \
1119#define CatalogCacheInitializeCache_DEBUG2 \
1121 if (cache->cc_keyno[i] > 0) { \
1122 elog(DEBUG2, "CatalogCacheInitializeCache: load %d/%d w/%d, %u", \
1123 i+1, cache->cc_nkeys, cache->cc_keyno[i], \
1124 TupleDescAttr(tupdesc, cache->cc_keyno[i] - 1)->atttypid); \
1126 elog(DEBUG2, "CatalogCacheInitializeCache: load %d/%d w/%d", \
1127 i+1, cache->cc_nkeys, cache->cc_keyno[i]); \
1131#define CatalogCacheInitializeCache_DEBUG1
1132#define CatalogCacheInitializeCache_DEBUG2
1194 Assert(attr->attnotnull);
1199 elog(
FATAL,
"sys attributes are not supported in caches");
1271 idesc->rd_index->indimmediate);
1433#ifdef CATCACHE_STATS
1434 cache->cc_searches++;
1463 if (
ct->hash_value != hashValue)
1490#ifdef CATCACHE_STATS
1501#ifdef CATCACHE_STATS
1502 cache->cc_neg_hits++;
1649#ifdef CATCACHE_STATS
1650 cache->cc_newloads++;
1691 ct->refcount == 0 &&
1692 (
ct->c_list ==
NULL ||
ct->c_list->refcount == 0))
1771#ifdef CATCACHE_STATS
1772 cache->cc_lsearches++;
1833 if (
cl->nkeys != nkeys)
1856#ifdef CATCACHE_STATS
1945 ordered = (scandesc->
irel !=
NULL);
1974 if (
ct->dead ||
ct->negative)
1977 if (
ct->hash_value != hashValue)
2056 ct->refcount == 0 &&
2057 (
ct->c_list ==
NULL ||
ct->c_list->refcount == 0))
2071 cl->ordered = ordered;
2074 cl->n_members = nmembers;
2133 list->refcount == 0)
2173#ifdef USE_ASSERT_CHECKING
2228 ct->tuple.t_len =
dtp->t_len;
2229 ct->tuple.t_self =
dtp->t_self;
2230 ct->tuple.t_tableOid =
dtp->t_tableOid;
2235 (
const char *)
dtp->t_data,
2281 ct->hash_value = hashValue;
2306 for (
i = 0;
i < nkeys;
i++)
2334 for (
i = 0;
i < nkeys;
i++)
2429 if (
ccp->cc_reloid != reloid)
2438 (*function) (
ccp->id, hashvalue, dbid, context);
2470 return psprintf(
"cache %s (%d), tuple %u/%u has count %d",
2471 ct->my_cache->cc_relname,
ct->my_cache->id,
2488 return psprintf(
"cache %s (%d), list %p has count %d",
2489 list->my_cache->cc_relname,
list->my_cache->id,
#define AttributeNumberIsValid(attributeNumber)
#define Assert(condition)
#define pg_attribute_always_inline
static bool chareqfast(Datum a, Datum b)
CatCache * InitCatCache(int id, Oid reloid, Oid indexoid, int nkeys, const int *key, int nbuckets)
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)
CatCList * SearchCatCacheList(CatCache *cache, int nkeys, Datum v1, Datum v2, Datum v3)
static void ResOwnerReleaseCatCache(Datum res)
uint32 GetCatCacheHashValue(CatCache *cache, Datum v1, Datum v2, Datum v3, Datum v4)
static CatCInProgress * catcache_in_progress_stack
static void CatCacheRemoveCTup(CatCache *cache, CatCTup *ct)
static char * ResOwnerPrintCatCache(Datum res)
static void RehashCatCache(CatCache *cp)
static void ResetCatalogCache(CatCache *cache, bool debug_discard)
static CatCTup * CatalogCacheCreateEntry(CatCache *cache, HeapTuple ntp, Datum *arguments, uint32 hashValue, Index hashIndex)
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 void CatCacheFreeKeys(TupleDesc tupdesc, int nkeys, const int *attnos, const Datum *keys)
static const ResourceOwnerDesc catcache_resowner_desc
static void ResOwnerReleaseCatCacheList(Datum res)
static void ResourceOwnerRememberCatCacheRef(ResourceOwner owner, HeapTuple tuple)
void PrepareToInvalidateCacheTuple(Relation relation, HeapTuple tuple, HeapTuple newtuple, void(*function)(int, uint32, Oid, void *), void *context)
#define CatalogCacheInitializeCache_DEBUG1
static HeapTuple SearchCatCacheInternal(CatCache *cache, int nkeys, Datum v1, Datum v2, Datum v3, Datum v4)
static pg_attribute_always_inline void ConditionalCatalogCacheInitializeCache(CatCache *cache)
static char * ResOwnerPrintCatCacheList(Datum res)
static void ReleaseCatCacheListWithOwner(CatCList *list, ResourceOwner resowner)
static CatCacheHeader * CacheHdr
static uint32 namehashfast(Datum datum)
void CreateCacheMemoryContext(void)
static const ResourceOwnerDesc catlistref_resowner_desc
static bool IndexScanOK(CatCache *cache)
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)
static void CatCacheCopyKeys(TupleDesc tupdesc, int nkeys, const int *attnos, const Datum *srckeys, Datum *dstkeys)
#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 CatCacheRemoveCList(CatCache *cache, CatCList *cl)
#define HASH_INDEX(h, sz)
static uint32 texthashfast(Datum datum)
void ReleaseCatCache(HeapTuple tuple)
HeapTuple SearchCatCache(CatCache *cache, Datum v1, Datum v2, Datum v3, Datum v4)
void ResetCatalogCachesExt(bool debug_discard)
uint32(* CCHashFN)(Datum datum)
bool(* CCFastEqualFN)(Datum a, Datum b)
Datum datumCopy(Datum value, bool typByVal, int typLen)
#define palloc_object(type)
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)
HeapTuple systable_getnext(SysScanDesc sysscan)
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
uint32 hash_bytes(const unsigned char *k, int keylen)
static uint32 murmurhash32(uint32 data)
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)
static bool HeapTupleHasExternal(const HeapTupleData *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)
static void dlist_push_tail(dlist_head *head, dlist_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)
#define INJECTION_POINT(name, arg)
void CallSyscacheCallbacks(int cacheid, uint32 hashvalue)
void on_proc_exit(pg_on_exit_callback function, Datum arg)
bool ItemPointerEquals(const ItemPointerData *pointer1, const ItemPointerData *pointer2)
static OffsetNumber ItemPointerGetOffsetNumber(const ItemPointerData *pointer)
static BlockNumber ItemPointerGetBlockNumber(const ItemPointerData *pointer)
List * lappend(List *list, void *datum)
void UnlockRelationOid(Oid relid, LOCKMODE lockmode)
void LockRelationOid(Oid relid, LOCKMODE lockmode)
void * MemoryContextAllocZero(MemoryContext context, Size size)
char * pstrdup(const char *in)
void pfree(void *pointer)
void * palloc0(Size size)
MemoryContext TopMemoryContext
MemoryContext CacheMemoryContext
void * palloc_aligned(Size size, Size alignto, int flags)
#define AllocSetContextCreate
#define ALLOCSET_DEFAULT_SIZES
#define IsBootstrapProcessingMode()
void namestrcpy(Name name, const char *str)
Datum oidvectoreq(PG_FUNCTION_ARGS)
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
FormData_pg_attribute * Form_pg_attribute
on_exit_nicely_callback function
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,...)
#define RelationGetForm(relation)
#define RelationGetRelid(relation)
#define RelationGetDescr(relation)
#define RelationGetRelationName(relation)
#define RelationIsValid(relation)
bool criticalRelcachesBuilt
bool criticalSharedRelcachesBuilt
static void AssertCouldGetRelation(void)
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
struct CatCInProgress * next
StrategyNumber sk_strategy
CCHashFN cc_hashfunc[CATCACHE_MAXKEYS]
int cc_keyno[CATCACHE_MAXKEYS]
CCFastEqualFN cc_fastequal[CATCACHE_MAXKEYS]
ScanKeyData cc_skey[CATCACHE_MAXKEYS]
void table_close(Relation relation, LOCKMODE lockmode)
Relation table_open(Oid relationId, LOCKMODE lockmode)
TupleDesc CreateTupleDescCopyConstr(TupleDesc tupdesc)
static FormData_pg_attribute * TupleDescAttr(TupleDesc tupdesc, int i)
static CompactAttribute * TupleDescCompactAttr(TupleDesc tupdesc, int i)
struct TupleDescData * TupleDesc
Datum texteq(PG_FUNCTION_ARGS)
bool IsTransactionState(void)