1 /*-------------------------------------------------------------------------
4 * Low-level catalog cache definitions.
6 * NOTE: every catalog cache must have a corresponding unique index on
7 * the system table that it caches --- ie, the index must match the keys
8 * used to do lookups in this cache. All cache fetches are done with
9 * indexscans (under normal conditions). The index should be unique to
10 * guarantee that there can only be one matching row for a key combination.
13 * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
14 * Portions Copyright (c) 1994, Regents of the University of California
16 * $Id: catcache.h,v 1.38 2002/02/19 20:11:19 tgl Exp $
18 *-------------------------------------------------------------------------
23 #include "access/htup.h"
24 #include "lib/dllist.h"
27 * struct catctup: individual tuple in the cache.
28 * struct catcache: information for managing a cache.
29 * struct catcacheheader: information for managing all the caches.
32 typedef struct catcache
34 int id; /* cache identifier --- see syscache.h */
35 struct catcache *cc_next; /* link to next catcache */
36 char *cc_relname; /* name of relation the tuples come from */
37 char *cc_indname; /* name of index matching cache keys */
38 int cc_reloidattr; /* AttrNumber of relation OID, or 0 */
39 bool cc_relisshared; /* is relation shared? */
40 TupleDesc cc_tupdesc; /* tuple descriptor (copied from reldesc) */
41 int cc_ntup; /* # of tuples currently in this cache */
42 int cc_size; /* # of hash buckets in this cache */
43 int cc_nkeys; /* number of keys (1..4) */
44 int cc_key[4]; /* AttrNumber of each key */
45 PGFunction cc_hashfunc[4]; /* hash function to use for each key */
46 ScanKeyData cc_skey[4]; /* precomputed key info for heap scans */
48 long cc_searches; /* total # searches against this cache */
49 long cc_hits; /* # of matches against existing entry */
50 long cc_newloads; /* # of successful loads of new entry */
51 /* cc_searches - (cc_hits + cc_newloads) is # of failed searches */
53 Dllist cc_bucket[1]; /* hash buckets --- VARIABLE LENGTH ARRAY */
54 } CatCache; /* VARIABLE LENGTH STRUCT */
57 typedef struct catctup
59 int ct_magic; /* for Assert checks */
60 #define CT_MAGIC 0x57261502
61 CatCache *my_cache; /* link to owning catcache */
64 * Each tuple in a cache is a member of two lists: one lists all the
65 * elements in all the caches in LRU order, and the other lists just
66 * the elements in one hashbucket of one cache, also in LRU order.
68 * A tuple marked "dead" must not be returned by subsequent searches.
69 * However, it won't be physically deleted from the cache until its
70 * refcount goes to zero.
72 Dlelem lrulist_elem; /* list member of global LRU list */
73 Dlelem cache_elem; /* list member of per-bucket list */
74 int refcount; /* number of active references */
75 bool dead; /* dead but not yet removed? */
76 HeapTupleData tuple; /* tuple management header */
80 typedef struct catcacheheader
82 CatCache *ch_caches; /* head of list of CatCache structs */
83 int ch_ntup; /* # of tuples in all caches */
84 int ch_maxtup; /* max # of tuples allowed (LRU) */
85 Dllist ch_lrulist; /* overall LRU list, most recent first */
89 /* this extern duplicates utils/memutils.h... */
90 extern MemoryContext CacheMemoryContext;
92 extern void CreateCacheMemoryContext(void);
93 extern void AtEOXact_CatCache(bool isCommit);
95 extern CatCache *InitCatCache(int id, char *relname, char *indname,
98 extern void InitCatCachePhase2(CatCache *cache);
100 extern HeapTuple SearchCatCache(CatCache *cache,
103 extern void ReleaseCatCache(HeapTuple tuple);
105 extern void ResetCatalogCaches(void);
106 extern void CatalogCacheFlushRelation(Oid relId);
107 extern void CatalogCacheIdInvalidate(int cacheId, Index hashIndex,
108 ItemPointer pointer);
109 extern void PrepareToInvalidateCacheTuple(Relation relation,
111 void (*function) (int, Index, ItemPointer, Oid));
113 #endif /* CATCACHE_H */