1996-08-28 03:59:28 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* catcache.h
|
1997-09-07 07:04:48 +02:00
|
|
|
* Low-level catalog cache definitions.
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
2000-11-10 01:33:12 +01:00
|
|
|
* NOTE: every catalog cache must have a corresponding unique index on
|
|
|
|
* the system table that it caches --- ie, the index must match the keys
|
|
|
|
* used to do lookups in this cache. All cache fetches are done with
|
|
|
|
* indexscans (under normal conditions). The index should be unique to
|
|
|
|
* guarantee that there can only be one matching row for a key combination.
|
|
|
|
*
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
2004-12-31 23:04:05 +01:00
|
|
|
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
2005-03-25 19:30:28 +01:00
|
|
|
* $PostgreSQL: pgsql/src/include/utils/catcache.h,v 1.53 2005/03/25 18:30:28 tgl Exp $
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
#ifndef CATCACHE_H
|
1996-08-28 03:59:28 +02:00
|
|
|
#define CATCACHE_H
|
|
|
|
|
1999-07-16 01:04:24 +02:00
|
|
|
#include "access/htup.h"
|
2003-11-09 22:30:38 +01:00
|
|
|
#include "access/skey.h"
|
1999-07-16 01:04:24 +02:00
|
|
|
#include "lib/dllist.h"
|
1996-08-28 03:59:28 +02:00
|
|
|
|
2000-06-17 06:56:39 +02:00
|
|
|
/*
|
2000-11-10 01:33:12 +01:00
|
|
|
* struct catctup: individual tuple in the cache.
|
2002-04-06 08:59:25 +02:00
|
|
|
* struct catclist: list of tuples matching a partial key.
|
1997-09-07 07:04:48 +02:00
|
|
|
* struct catcache: information for managing a cache.
|
2001-06-18 05:35:07 +02:00
|
|
|
* struct catcacheheader: information for managing all the caches.
|
1996-08-28 03:59:28 +02:00
|
|
|
*/
|
|
|
|
|
2001-06-18 05:35:07 +02:00
|
|
|
typedef struct catcache
|
|
|
|
{
|
|
|
|
int id; /* cache identifier --- see syscache.h */
|
|
|
|
struct catcache *cc_next; /* link to next catcache */
|
2002-03-26 20:17:02 +01:00
|
|
|
const char *cc_relname; /* name of relation the tuples come from */
|
|
|
|
const char *cc_indname; /* name of index matching cache keys */
|
2002-03-03 18:47:56 +01:00
|
|
|
Oid cc_reloid; /* OID of relation the tuples come from */
|
2002-04-06 08:59:25 +02:00
|
|
|
bool cc_relisshared; /* is relation shared across databases? */
|
2001-06-18 05:35:07 +02:00
|
|
|
TupleDesc cc_tupdesc; /* tuple descriptor (copied from reldesc) */
|
2002-03-03 18:47:56 +01:00
|
|
|
int cc_reloidattr; /* AttrNumber of relation OID attr, or 0 */
|
2001-06-18 05:35:07 +02:00
|
|
|
int cc_ntup; /* # of tuples currently in this cache */
|
2002-03-06 21:49:46 +01:00
|
|
|
int cc_nbuckets; /* # of hash buckets in this cache */
|
|
|
|
int cc_nkeys; /* # of keys (1..4) */
|
2001-06-18 05:35:07 +02:00
|
|
|
int cc_key[4]; /* AttrNumber of each key */
|
|
|
|
PGFunction cc_hashfunc[4]; /* hash function to use for each key */
|
|
|
|
ScanKeyData cc_skey[4]; /* precomputed key info for heap scans */
|
2002-03-03 18:47:56 +01:00
|
|
|
bool cc_isname[4]; /* flag key columns that are NAMEs */
|
2002-04-06 08:59:25 +02:00
|
|
|
Dllist cc_lists; /* list of CatCList structs */
|
2002-02-19 21:11:20 +01:00
|
|
|
#ifdef CATCACHE_STATS
|
|
|
|
long cc_searches; /* total # searches against this cache */
|
|
|
|
long cc_hits; /* # of matches against existing entry */
|
2002-03-03 18:47:56 +01:00
|
|
|
long cc_neg_hits; /* # of matches against negative entry */
|
2002-02-19 21:11:20 +01:00
|
|
|
long cc_newloads; /* # of successful loads of new entry */
|
2002-09-04 22:31:48 +02:00
|
|
|
|
2002-03-03 18:47:56 +01:00
|
|
|
/*
|
|
|
|
* cc_searches - (cc_hits + cc_neg_hits + cc_newloads) is number of
|
2002-09-04 22:31:48 +02:00
|
|
|
* failed searches, each of which will result in loading a negative
|
|
|
|
* entry
|
2002-03-03 18:47:56 +01:00
|
|
|
*/
|
|
|
|
long cc_invals; /* # of entries invalidated from cache */
|
|
|
|
long cc_discards; /* # of entries discarded due to overflow */
|
2002-04-06 08:59:25 +02:00
|
|
|
long cc_lsearches; /* total # list-searches */
|
|
|
|
long cc_lhits; /* # of matches against existing lists */
|
2002-02-19 21:11:20 +01:00
|
|
|
#endif
|
2001-06-18 05:35:07 +02:00
|
|
|
Dllist cc_bucket[1]; /* hash buckets --- VARIABLE LENGTH ARRAY */
|
|
|
|
} CatCache; /* VARIABLE LENGTH STRUCT */
|
|
|
|
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct catctup
|
|
|
|
{
|
2002-04-06 08:59:25 +02:00
|
|
|
int ct_magic; /* for identifying CatCTup entries */
|
2000-11-16 23:30:52 +01:00
|
|
|
#define CT_MAGIC 0x57261502
|
2001-06-18 05:35:07 +02:00
|
|
|
CatCache *my_cache; /* link to owning catcache */
|
2001-10-25 07:50:21 +02:00
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
/*
|
2002-04-06 08:59:25 +02:00
|
|
|
* Each tuple in a cache is a member of two Dllists: one lists all the
|
2001-06-18 05:35:07 +02:00
|
|
|
* 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.
|
2000-11-16 23:30:52 +01:00
|
|
|
*
|
2002-09-04 22:31:48 +02:00
|
|
|
* The tuple may also be a member of at most one CatCList. (If a single
|
2002-04-06 08:59:25 +02:00
|
|
|
* 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 */
|
2002-09-04 22:31:48 +02:00
|
|
|
|
2002-04-06 08:59:25 +02:00
|
|
|
/*
|
2000-11-16 23:30:52 +01:00
|
|
|
* 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.
|
2002-03-03 18:47:56 +01:00
|
|
|
*
|
2002-09-04 22:31:48 +02:00
|
|
|
* A negative cache entry is an assertion that there is no tuple matching
|
|
|
|
* a particular key. This is just as useful as a normal entry so far
|
|
|
|
* as avoiding catalog searches is concerned. Management of positive
|
|
|
|
* and negative entries is identical.
|
1999-06-04 04:19:47 +02:00
|
|
|
*/
|
2000-11-16 23:30:52 +01:00
|
|
|
int refcount; /* number of active references */
|
|
|
|
bool dead; /* dead but not yet removed? */
|
2002-03-03 18:47:56 +01:00
|
|
|
bool negative; /* negative cache entry? */
|
|
|
|
uint32 hash_value; /* hash value for this tuple's keys */
|
2000-11-16 23:30:52 +01:00
|
|
|
HeapTupleData tuple; /* tuple management header */
|
1997-09-08 23:56:23 +02:00
|
|
|
} CatCTup;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
2000-11-16 23:30:52 +01:00
|
|
|
|
2002-04-06 08:59:25 +02:00
|
|
|
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
|
2002-09-04 22:31:48 +02:00
|
|
|
* the stored key set. The CatCList object contains links to cache
|
2002-04-06 08:59:25 +02:00
|
|
|
* entries for all the table rows satisfying the partial key. (Note:
|
|
|
|
* none of these will be negative cache entries.)
|
|
|
|
*
|
2002-09-04 22:31:48 +02:00
|
|
|
* 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.
|
2002-04-06 08:59:25 +02:00
|
|
|
*
|
|
|
|
* 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.)
|
|
|
|
*
|
2002-09-04 22:31:48 +02:00
|
|
|
* 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,
|
2002-04-06 08:59:25 +02:00
|
|
|
* 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 */
|
2002-09-04 22:31:48 +02:00
|
|
|
CatCTup *members[1]; /* members --- VARIABLE LENGTH ARRAY */
|
2002-04-06 08:59:25 +02:00
|
|
|
} CatCList; /* VARIABLE LENGTH STRUCT */
|
|
|
|
|
|
|
|
|
2001-06-18 05:35:07 +02:00
|
|
|
typedef struct catcacheheader
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
2001-06-18 05:35:07 +02:00
|
|
|
CatCache *ch_caches; /* head of list of CatCache structs */
|
|
|
|
int ch_ntup; /* # of tuples in all caches */
|
|
|
|
int ch_maxtup; /* max # of tuples allowed (LRU) */
|
|
|
|
Dllist ch_lrulist; /* overall LRU list, most recent first */
|
|
|
|
} CatCacheHeader;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
|
2000-06-28 05:33:33 +02:00
|
|
|
/* this extern duplicates utils/memutils.h... */
|
2002-06-19 15:46:09 +02:00
|
|
|
extern DLLIMPORT MemoryContext CacheMemoryContext;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
2000-06-28 05:33:33 +02:00
|
|
|
extern void CreateCacheMemoryContext(void);
|
2000-11-16 23:30:52 +01:00
|
|
|
extern void AtEOXact_CatCache(bool isCommit);
|
2000-11-10 01:33:12 +01:00
|
|
|
|
2002-03-26 20:17:02 +01:00
|
|
|
extern CatCache *InitCatCache(int id, const char *relname, const char *indname,
|
2001-10-25 07:50:21 +02:00
|
|
|
int reloidattr,
|
2002-03-26 20:17:02 +01:00
|
|
|
int nkeys, const int *key);
|
2002-02-19 21:11:20 +01:00
|
|
|
extern void InitCatCachePhase2(CatCache *cache);
|
2000-11-16 23:30:52 +01:00
|
|
|
|
|
|
|
extern HeapTuple SearchCatCache(CatCache *cache,
|
2001-03-22 05:01:46 +01:00
|
|
|
Datum v1, Datum v2,
|
|
|
|
Datum v3, Datum v4);
|
2000-11-16 23:30:52 +01:00
|
|
|
extern void ReleaseCatCache(HeapTuple tuple);
|
2000-11-10 01:33:12 +01:00
|
|
|
|
2002-04-06 08:59:25 +02:00
|
|
|
extern CatCList *SearchCatCacheList(CatCache *cache, int nkeys,
|
2002-09-04 22:31:48 +02:00
|
|
|
Datum v1, Datum v2,
|
|
|
|
Datum v3, Datum v4);
|
2002-04-06 08:59:25 +02:00
|
|
|
extern void ReleaseCatCacheList(CatCList *list);
|
|
|
|
|
2001-06-18 05:35:07 +02:00
|
|
|
extern void ResetCatalogCaches(void);
|
|
|
|
extern void CatalogCacheFlushRelation(Oid relId);
|
2002-03-03 18:47:56 +01:00
|
|
|
extern void CatalogCacheIdInvalidate(int cacheId, uint32 hashValue,
|
2001-03-22 05:01:46 +01:00
|
|
|
ItemPointer pointer);
|
2001-01-05 23:54:37 +01:00
|
|
|
extern void PrepareToInvalidateCacheTuple(Relation relation,
|
2001-10-25 07:50:21 +02:00
|
|
|
HeapTuple tuple,
|
2002-09-04 22:31:48 +02:00
|
|
|
void (*function) (int, uint32, ItemPointer, Oid));
|
2001-10-28 07:26:15 +01:00
|
|
|
|
2005-03-25 19:30:28 +01:00
|
|
|
extern void PrintCatCacheLeakWarning(HeapTuple tuple);
|
|
|
|
extern void PrintCatCacheListLeakWarning(CatCList *list);
|
|
|
|
|
2001-11-05 18:46:40 +01:00
|
|
|
#endif /* CATCACHE_H */
|