/* function computing a datum's hash */ typedef uint32 (*CCHashFN) (Datum datum);
/* function computing equality of two datums */ typedefbool (*CCFastEqualFN) (Datum a, Datum b);
typedefstruct catcache
{ int id; /* cache identifier --- see syscache.h */ int cc_nbuckets; /* # of hash buckets in this cache */
TupleDesc cc_tupdesc; /* tuple descriptor (copied from reldesc) */
dlist_head *cc_bucket; /* hash buckets */
CCHashFN cc_hashfunc[CATCACHE_MAXKEYS]; /* hash function for each key */
CCFastEqualFN cc_fastequal[CATCACHE_MAXKEYS]; /* fast equal function for
* each key */ int cc_keyno[CATCACHE_MAXKEYS]; /* AttrNumber of each key */ int cc_nkeys; /* # of keys (1..CATCACHE_MAXKEYS) */ int cc_ntup; /* # of tuples currently in this cache */ int cc_nlist; /* # of CatCLists currently in this cache */ int cc_nlbuckets; /* # of CatCList hash buckets in this cache */
dlist_head *cc_lbucket; /* hash buckets for CatCLists */ constchar *cc_relname; /* name of relation the tuples come from */
Oid cc_reloid; /* OID of relation the tuples come from */
Oid cc_indexoid; /* OID of index matching cache keys */ bool cc_relisshared; /* is relation shared across databases? */
slist_node cc_next; /* list link */
ScanKeyData cc_skey[CATCACHE_MAXKEYS]; /* precomputed key info for heap
* scans */
/* *Keeptheseattheend,sothatcompilingcatcache.cwithCATCACHE_STATS *doesn'tbreakABIforothermodules
*/ #ifdef CATCACHE_STATS long cc_searches; /* total # searches against this cache */ long cc_hits; /* # of matches against existing entry */ long cc_neg_hits; /* # of matches against negative entry */ long cc_newloads; /* # of successful loads of new entry */
/* *cc_searches-(cc_hits+cc_neg_hits+cc_newloads)isnumberoffailed *searches,eachofwhichwillresultinloadinganegativeentry
*/ long cc_invals; /* # of entries invalidated from cache */ long cc_lsearches; /* total # list-searches */ long cc_lhits; /* # of matches against existing lists */ #endif
} CatCache;
typedefstruct catctup
{ int ct_magic; /* for identifying CatCTup entries */ #define CT_MAGIC 0x57261502
uint32 hash_value; /* hash value for this tuple's keys */
/* *Lookupkeysfortheentry.By-referencedatumspointintothetuplefor *positivecacheentries,andareseparatelyallocatedfornegativeones.
*/
Datum keys[CATCACHE_MAXKEYS];
/* *Eachtupleinacacheisamemberofadlistthatstorestheelements *ofitshashbucket.WekeepeachdlistinLRUordertospeedrepeated *lookups.
*/
dlist_node cache_elem; /* list member of per-bucket list */
/* *Atuplemarked"dead"mustnotbereturnedbysubsequentsearches. *However,itwon'tbephysicallydeletedfromthecacheuntilits *refcountgoestozero.(Ifit'samemberofaCatCList,thelist's *refcountmustgotozero,too;also,remembertomarkthelistdeadat *thesametimethetupleismarked.) * *Anegativecacheentryisanassertionthatthereisnotuplematching *aparticularkey.Thisisjustasusefulasanormalentrysofaras *avoidingcatalogsearchesisconcerned.Managementofpositiveand *negativeentriesisidentical.
*/ int refcount; /* number of active references */ bool dead; /* dead but not yet removed? */ bool negative; /* negative cache entry? */
HeapTupleData tuple; /* tuple management header */
/* *ThetuplemayalsobeamemberofatmostoneCatCList.(Ifasingle *catcacheislist-searchedwithvaryingnumbersofkeys,wemayhaveto *makemultipleentriesforthesametuplebecauseofthisrestriction. *Currently,that'snotexpectedtobecommon,soweacceptthepotential *inefficiency.)
*/ struct catclist *c_list; /* containing CatCList, or NULL if none */
CatCache *my_cache; /* link to owning catcache */ /* properly aligned tuple data follows, unless a negative entry */
} CatCTup;
uint32 hash_value; /* hash value for lookup keys */
dlist_node cache_elem; /* list member of per-catcache list */
/* *Lookupkeysfortheentry,withthefirstnkeyselementsbeingvalid. *Allby-referenceareseparatelyallocated.
*/
Datum keys[CATCACHE_MAXKEYS];
int refcount; /* number of active references */ bool dead; /* dead but not yet removed? */ bool ordered; /* members listed in index order? */ short nkeys; /* number of lookup keys specified */ int n_members; /* number of member tuples */
CatCache *my_cache; /* link to owning catcache */
CatCTup *members[FLEXIBLE_ARRAY_MEMBER]; /* members */
} CatCList;
typedefstruct catcacheheader
{
slist_head ch_caches; /* head of list of CatCache structs */ int ch_ntup; /* # of tuples in all caches */
} CatCacheHeader;
/* this extern duplicates utils/memutils.h... */ extern PGDLLIMPORT MemoryContext CacheMemoryContext;
externvoid CreateCacheMemoryContext(void);
extern CatCache *InitCatCache(int id, Oid reloid, Oid indexoid, int nkeys, constint *key, int nbuckets); externvoid InitCatCachePhase2(CatCache *cache, bool touch_index);
extern HeapTuple SearchCatCache(CatCache *cache,
Datum v1, Datum v2, Datum v3, Datum v4); extern HeapTuple SearchCatCache1(CatCache *cache,
Datum v1); extern HeapTuple SearchCatCache2(CatCache *cache,
Datum v1, Datum v2); extern HeapTuple SearchCatCache3(CatCache *cache,
Datum v1, Datum v2, Datum v3); extern HeapTuple SearchCatCache4(CatCache *cache,
Datum v1, Datum v2, Datum v3, Datum v4); externvoid ReleaseCatCache(HeapTuple tuple);
extern uint32 GetCatCacheHashValue(CatCache *cache,
Datum v1, Datum v2,
Datum v3, Datum v4);
extern CatCList *SearchCatCacheList(CatCache *cache, int nkeys,
Datum v1, Datum v2,
Datum v3); externvoid ReleaseCatCacheList(CatCList *list);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.