diff options
Diffstat (limited to 'src/include/utils/catcache.h')
-rw-r--r-- | src/include/utils/catcache.h | 70 |
1 files changed, 64 insertions, 6 deletions
diff --git a/src/include/utils/catcache.h b/src/include/utils/catcache.h index 8e98f41c019..2a1a83f13b9 100644 --- a/src/include/utils/catcache.h +++ b/src/include/utils/catcache.h @@ -13,7 +13,7 @@ * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $Id: catcache.h,v 1.41 2002/03/26 19:16:56 tgl Exp $ + * $Id: catcache.h,v 1.42 2002/04/06 06:59:24 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -25,6 +25,7 @@ /* * struct catctup: individual tuple in the cache. + * struct catclist: list of tuples matching a partial key. * struct catcache: information for managing a cache. * struct catcacheheader: information for managing all the caches. */ @@ -36,7 +37,7 @@ typedef struct catcache const char *cc_relname; /* name of relation the tuples come from */ const char *cc_indname; /* name of index matching cache keys */ Oid cc_reloid; /* OID of relation the tuples come from */ - bool cc_relisshared; /* is relation shared? */ + bool cc_relisshared; /* is relation shared across databases? */ TupleDesc cc_tupdesc; /* tuple descriptor (copied from reldesc) */ int cc_reloidattr; /* AttrNumber of relation OID attr, or 0 */ int cc_ntup; /* # of tuples currently in this cache */ @@ -46,6 +47,7 @@ typedef struct catcache PGFunction cc_hashfunc[4]; /* hash function to use for each key */ ScanKeyData cc_skey[4]; /* precomputed key info for heap scans */ bool cc_isname[4]; /* flag key columns that are NAMEs */ + Dllist cc_lists; /* list of CatCList structs */ #ifdef CATCACHE_STATS long cc_searches; /* total # searches against this cache */ long cc_hits; /* # of matches against existing entry */ @@ -57,6 +59,8 @@ typedef struct catcache */ long cc_invals; /* # of entries invalidated from cache */ long cc_discards; /* # of entries discarded due to overflow */ + long cc_lsearches; /* total # list-searches */ + long cc_lhits; /* # of matches against existing lists */ #endif Dllist cc_bucket[1]; /* hash buckets --- VARIABLE LENGTH ARRAY */ } CatCache; /* VARIABLE LENGTH STRUCT */ @@ -64,15 +68,25 @@ typedef struct catcache typedef struct catctup { - int ct_magic; /* for Assert checks */ + int ct_magic; /* for identifying CatCTup entries */ #define CT_MAGIC 0x57261502 CatCache *my_cache; /* link to owning catcache */ /* - * Each tuple in a cache is a member of two lists: one lists all the + * Each tuple in a cache is a member of two Dllists: one lists all the * elements in all the caches in LRU order, and the other lists just * the elements in one hashbucket of one cache, also in LRU order. * + * The tuple may also be a member of at most one CatCList. (If a single + * catcache is list-searched with varying numbers of keys, we may have + * to make multiple entries for the same tuple because of this + * restriction. Currently, that's not expected to be common, so we + * accept the potential inefficiency.) + */ + Dlelem lrulist_elem; /* list member of global LRU list */ + Dlelem cache_elem; /* list member of per-bucket list */ + struct catclist *c_list; /* containing catclist, or NULL if none */ + /* * A tuple marked "dead" must not be returned by subsequent searches. * However, it won't be physically deleted from the cache until its * refcount goes to zero. @@ -82,8 +96,6 @@ typedef struct catctup * so far as avoiding catalog searches is concerned. Management of * positive and negative entries is identical. */ - Dlelem lrulist_elem; /* list member of global LRU list */ - Dlelem cache_elem; /* list member of per-bucket list */ int refcount; /* number of active references */ bool dead; /* dead but not yet removed? */ bool negative; /* negative cache entry? */ @@ -92,6 +104,47 @@ typedef struct catctup } CatCTup; +typedef struct catclist +{ + int cl_magic; /* for identifying CatCList entries */ +#define CL_MAGIC 0x52765103 + CatCache *my_cache; /* link to owning catcache */ + + /* + * A CatCList describes the result of a partial search, ie, a search + * using only the first K key columns of an N-key cache. We form the + * keys used into a tuple (with other attributes NULL) to represent + * the stored key set. The CatCList object contains links to cache + * entries for all the table rows satisfying the partial key. (Note: + * none of these will be negative cache entries.) + * + * A CatCList is only a member of a per-cache list; we do not do + * separate LRU management for CatCLists. Instead, a CatCList is + * dropped from the cache as soon as any one of its member tuples + * ages out due to tuple-level LRU management. + * + * A list marked "dead" must not be returned by subsequent searches. + * However, it won't be physically deleted from the cache until its + * refcount goes to zero. (Its member tuples must have refcounts at + * least as large, so they won't go away either.) + * + * If "ordered" is true then the member tuples appear in the order of + * the cache's underlying index. This will be true in normal operation, + * but might not be true during bootstrap or recovery operations. + * (namespace.c is able to save some cycles when it is true.) + */ + Dlelem cache_elem; /* list member of per-catcache list */ + 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 */ + uint32 hash_value; /* hash value for lookup keys */ + HeapTupleData tuple; /* header for tuple holding keys */ + int n_members; /* number of member tuples */ + CatCTup *members[1]; /* members --- VARIABLE LENGTH ARRAY */ +} CatCList; /* VARIABLE LENGTH STRUCT */ + + typedef struct catcacheheader { CatCache *ch_caches; /* head of list of CatCache structs */ @@ -117,6 +170,11 @@ extern HeapTuple SearchCatCache(CatCache *cache, Datum v3, Datum v4); extern void ReleaseCatCache(HeapTuple tuple); +extern CatCList *SearchCatCacheList(CatCache *cache, int nkeys, + Datum v1, Datum v2, + Datum v3, Datum v4); +extern void ReleaseCatCacheList(CatCList *list); + extern void ResetCatalogCaches(void); extern void CatalogCacheFlushRelation(Oid relId); extern void CatalogCacheIdInvalidate(int cacheId, uint32 hashValue, |