]> granicus.if.org Git - postgresql/blob - src/include/utils/catcache.h
Commit to match discussed elog() changes. Only update is that LOG is
[postgresql] / src / include / utils / catcache.h
1 /*-------------------------------------------------------------------------
2  *
3  * catcache.h
4  *        Low-level catalog cache definitions.
5  *
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.
11  *
12  *
13  * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
14  * Portions Copyright (c) 1994, Regents of the University of California
15  *
16  * $Id: catcache.h,v 1.38 2002/02/19 20:11:19 tgl Exp $
17  *
18  *-------------------------------------------------------------------------
19  */
20 #ifndef CATCACHE_H
21 #define CATCACHE_H
22
23 #include "access/htup.h"
24 #include "lib/dllist.h"
25
26 /*
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.
30  */
31
32 typedef struct catcache
33 {
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 */
47 #ifdef CATCACHE_STATS
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 */
52 #endif
53         Dllist          cc_bucket[1];   /* hash buckets --- VARIABLE LENGTH ARRAY */
54 } CatCache;                                             /* VARIABLE LENGTH STRUCT */
55
56
57 typedef struct catctup
58 {
59         int                     ct_magic;               /* for Assert checks */
60 #define CT_MAGIC   0x57261502
61         CatCache   *my_cache;           /* link to owning catcache */
62
63         /*
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.
67          *
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.
71          */
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 */
77 } CatCTup;
78
79
80 typedef struct catcacheheader
81 {
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 */
86 } CatCacheHeader;
87
88
89 /* this extern duplicates utils/memutils.h... */
90 extern MemoryContext CacheMemoryContext;
91
92 extern void CreateCacheMemoryContext(void);
93 extern void AtEOXact_CatCache(bool isCommit);
94
95 extern CatCache *InitCatCache(int id, char *relname, char *indname,
96                          int reloidattr,
97                          int nkeys, int *key);
98 extern void InitCatCachePhase2(CatCache *cache);
99
100 extern HeapTuple SearchCatCache(CatCache *cache,
101                            Datum v1, Datum v2,
102                            Datum v3, Datum v4);
103 extern void ReleaseCatCache(HeapTuple tuple);
104
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,
110                                                           HeapTuple tuple,
111                                                 void (*function) (int, Index, ItemPointer, Oid));
112
113 #endif   /* CATCACHE_H */