Eneboo - Documentación para desarrolladores
src/libpq/include/utils/catcache.h
Ir a la documentación de este archivo.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * catcache.h
00004  *        Low-level catalog cache definitions.
00005  *
00006  * NOTE: every catalog cache must have a corresponding unique index on
00007  * the system table that it caches --- ie, the index must match the keys
00008  * used to do lookups in this cache.  All cache fetches are done with
00009  * indexscans (under normal conditions).  The index should be unique to
00010  * guarantee that there can only be one matching row for a key combination.
00011  *
00012  *
00013  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
00014  * Portions Copyright (c) 1994, Regents of the University of California
00015  *
00016  * $PostgreSQL: pgsql/src/include/utils/catcache.h,v 1.56.2.1 2005/11/22 18:23:29 momjian Exp $
00017  *
00018  *-------------------------------------------------------------------------
00019  */
00020 #ifndef CATCACHE_H
00021 #define CATCACHE_H
00022 
00023 #include "access/htup.h"
00024 #include "access/skey.h"
00025 #include "lib/dllist.h"
00026 
00027 /*
00028  *              struct catctup:                 individual tuple in the cache.
00029  *              struct catclist:                list of tuples matching a partial key.
00030  *              struct catcache:                information for managing a cache.
00031  *              struct catcacheheader:  information for managing all the caches.
00032  */
00033 
00034 typedef struct catcache
00035 {
00036         int                     id;                             /* cache identifier --- see syscache.h */
00037         struct catcache *cc_next;       /* link to next catcache */
00038         const char *cc_relname;         /* name of relation the tuples come from */
00039         Oid                     cc_reloid;              /* OID of relation the tuples come from */
00040         Oid                     cc_indexoid;    /* OID of index matching cache keys */
00041         bool            cc_relisshared; /* is relation shared across databases? */
00042         TupleDesc       cc_tupdesc;             /* tuple descriptor (copied from reldesc) */
00043         int                     cc_reloidattr;  /* AttrNumber of relation OID attr, or 0 */
00044         int                     cc_ntup;                /* # of tuples currently in this cache */
00045         int                     cc_nbuckets;    /* # of hash buckets in this cache */
00046         int                     cc_nkeys;               /* # of keys (1..4) */
00047         int                     cc_key[4];              /* AttrNumber of each key */
00048         PGFunction      cc_hashfunc[4]; /* hash function to use for each key */
00049         ScanKeyData cc_skey[4];         /* precomputed key info for heap scans */
00050         bool            cc_isname[4];   /* flag key columns that are NAMEs */
00051         Dllist          cc_lists;               /* list of CatCList structs */
00052 #ifdef CATCACHE_STATS
00053         long            cc_searches;    /* total # searches against this cache */
00054         long            cc_hits;                /* # of matches against existing entry */
00055         long            cc_neg_hits;    /* # of matches against negative entry */
00056         long            cc_newloads;    /* # of successful loads of new entry */
00057 
00058         /*
00059          * cc_searches - (cc_hits + cc_neg_hits + cc_newloads) is number of failed
00060          * searches, each of which will result in loading a negative entry
00061          */
00062         long            cc_invals;              /* # of entries invalidated from cache */
00063         long            cc_discards;    /* # of entries discarded due to overflow */
00064         long            cc_lsearches;   /* total # list-searches */
00065         long            cc_lhits;               /* # of matches against existing lists */
00066 #endif
00067         Dllist          cc_bucket[1];   /* hash buckets --- VARIABLE LENGTH ARRAY */
00068 } CatCache;                                             /* VARIABLE LENGTH STRUCT */
00069 
00070 
00071 typedef struct catctup
00072 {
00073         int                     ct_magic;               /* for identifying CatCTup entries */
00074 #define CT_MAGIC   0x57261502
00075         CatCache   *my_cache;           /* link to owning catcache */
00076 
00077         /*
00078          * Each tuple in a cache is a member of two Dllists: one lists all the
00079          * elements in all the caches in LRU order, and the other lists just the
00080          * elements in one hashbucket of one cache, also in LRU order.
00081          */
00082         Dlelem          lrulist_elem;   /* list member of global LRU list */
00083         Dlelem          cache_elem;             /* list member of per-bucket list */
00084 
00085         /*
00086          * The tuple may also be a member of at most one CatCList.      (If a single
00087          * catcache is list-searched with varying numbers of keys, we may have to
00088          * make multiple entries for the same tuple because of this restriction.
00089          * Currently, that's not expected to be common, so we accept the potential
00090          * inefficiency.)
00091          */
00092         struct catclist *c_list;        /* containing CatCList, or NULL if none */
00093 
00094         /*
00095          * A tuple marked "dead" must not be returned by subsequent searches.
00096          * However, it won't be physically deleted from the cache until its
00097          * refcount goes to zero.  (If it's a member of a CatCList, the list's
00098          * refcount must go to zero, too; also, remember to mark the list dead at
00099          * the same time the tuple is marked.)
00100          *
00101          * A negative cache entry is an assertion that there is no tuple matching
00102          * a particular key.  This is just as useful as a normal entry so far as
00103          * avoiding catalog searches is concerned.      Management of positive and
00104          * negative entries is identical.
00105          */
00106         int                     refcount;               /* number of active references */
00107         bool            dead;                   /* dead but not yet removed? */
00108         bool            negative;               /* negative cache entry? */
00109         uint32          hash_value;             /* hash value for this tuple's keys */
00110         HeapTupleData tuple;            /* tuple management header */
00111 } CatCTup;
00112 
00113 
00114 typedef struct catclist
00115 {
00116         int                     cl_magic;               /* for identifying CatCList entries */
00117 #define CL_MAGIC   0x52765103
00118         CatCache   *my_cache;           /* link to owning catcache */
00119 
00120         /*
00121          * A CatCList describes the result of a partial search, ie, a search using
00122          * only the first K key columns of an N-key cache.      We form the keys used
00123          * into a tuple (with other attributes NULL) to represent the stored key
00124          * set.  The CatCList object contains links to cache entries for all the
00125          * table rows satisfying the partial key.  (Note: none of these will be
00126          * negative cache entries.)
00127          *
00128          * A CatCList is only a member of a per-cache list; we do not do separate
00129          * LRU management for CatCLists.  See CatalogCacheCleanup() for the
00130          * details of the management algorithm.
00131          *
00132          * A list marked "dead" must not be returned by subsequent searches.
00133          * However, it won't be physically deleted from the cache until its
00134          * refcount goes to zero.  (A list should be marked dead if any of its
00135          * member entries are dead.)
00136          *
00137          * If "ordered" is true then the member tuples appear in the order of the
00138          * cache's underlying index.  This will be true in normal operation, but
00139          * might not be true during bootstrap or recovery operations. (namespace.c
00140          * is able to save some cycles when it is true.)
00141          */
00142         Dlelem          cache_elem;             /* list member of per-catcache list */
00143         int                     refcount;               /* number of active references */
00144         bool            dead;                   /* dead but not yet removed? */
00145         bool            ordered;                /* members listed in index order? */
00146         bool            touched;                /* used since last CatalogCacheCleanup? */
00147         short           nkeys;                  /* number of lookup keys specified */
00148         uint32          hash_value;             /* hash value for lookup keys */
00149         HeapTupleData tuple;            /* header for tuple holding keys */
00150         int                     n_members;              /* number of member tuples */
00151         CatCTup    *members[1];         /* members --- VARIABLE LENGTH ARRAY */
00152 } CatCList;                                             /* VARIABLE LENGTH STRUCT */
00153 
00154 
00155 typedef struct catcacheheader
00156 {
00157         CatCache   *ch_caches;          /* head of list of CatCache structs */
00158         int                     ch_ntup;                /* # of tuples in all caches */
00159         int                     ch_maxtup;              /* max # of tuples allowed (LRU) */
00160         Dllist          ch_lrulist;             /* overall LRU list, most recent first */
00161 } CatCacheHeader;
00162 
00163 
00164 /* this extern duplicates utils/memutils.h... */
00165 extern DLLIMPORT MemoryContext CacheMemoryContext;
00166 
00167 extern void CreateCacheMemoryContext(void);
00168 extern void AtEOXact_CatCache(bool isCommit);
00169 
00170 extern CatCache *InitCatCache(int id, Oid reloid, Oid indexoid,
00171                          int reloidattr,
00172                          int nkeys, const int *key);
00173 extern void InitCatCachePhase2(CatCache *cache);
00174 
00175 extern HeapTuple SearchCatCache(CatCache *cache,
00176                            Datum v1, Datum v2,
00177                            Datum v3, Datum v4);
00178 extern void ReleaseCatCache(HeapTuple tuple);
00179 
00180 extern CatCList *SearchCatCacheList(CatCache *cache, int nkeys,
00181                                    Datum v1, Datum v2,
00182                                    Datum v3, Datum v4);
00183 extern void ReleaseCatCacheList(CatCList *list);
00184 
00185 extern void ResetCatalogCaches(void);
00186 extern void CatalogCacheFlushRelation(Oid relId);
00187 extern void CatalogCacheIdInvalidate(int cacheId, uint32 hashValue,
00188                                                  ItemPointer pointer);
00189 extern void PrepareToInvalidateCacheTuple(Relation relation,
00190                                                           HeapTuple tuple,
00191                                                    void (*function) (int, uint32, ItemPointer, Oid));
00192 
00193 extern void PrintCatCacheLeakWarning(HeapTuple tuple);
00194 extern void PrintCatCacheListLeakWarning(CatCList *list);
00195 
00196 #endif   /* CATCACHE_H */
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'