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
|
|
|
*
|
2001-01-24 20:43:33 +01:00
|
|
|
* Portions Copyright (c) 1996-2001, 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
|
|
|
*
|
2001-01-24 20:43:33 +01:00
|
|
|
* $Id: catcache.h,v 1.31 2001/01/24 19:43:28 momjian 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
|
|
|
|
|
2000-06-17 06:56:39 +02:00
|
|
|
/* #define CACHEDEBUG */ /* turns DEBUG elogs on */
|
1996-08-28 03:59:28 +02:00
|
|
|
|
1999-07-16 01:04:24 +02:00
|
|
|
#include "access/htup.h"
|
|
|
|
#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.
|
1997-09-07 07:04:48 +02:00
|
|
|
* struct catcache: information for managing a cache.
|
1996-08-28 03:59:28 +02:00
|
|
|
*/
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct catctup
|
|
|
|
{
|
2000-11-16 23:30:52 +01:00
|
|
|
int ct_magic; /* for Assert checks */
|
|
|
|
#define CT_MAGIC 0x57261502
|
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
/*
|
2000-11-16 23:30:52 +01:00
|
|
|
* Each tuple in a cache is a member of two lists: one lists all the
|
|
|
|
* elements in that cache in LRU order, and the other lists just the
|
|
|
|
* elements in one hashbucket, also in LRU order.
|
|
|
|
*
|
|
|
|
* 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.
|
1999-06-04 04:19:47 +02:00
|
|
|
*/
|
2000-11-16 23:30:52 +01:00
|
|
|
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? */
|
|
|
|
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
|
|
|
|
1996-08-28 03:59:28 +02:00
|
|
|
/* voodoo constants */
|
1997-09-07 07:04:48 +02:00
|
|
|
#define NCCBUCK 500 /* CatCache buckets */
|
2000-11-16 23:30:52 +01:00
|
|
|
#define MAXTUP 500 /* Maximum # of tuples stored per cache */
|
1996-08-28 03:59:28 +02:00
|
|
|
|
2000-02-21 04:36:59 +01:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct catcache
|
|
|
|
{
|
2000-11-10 01:33:12 +01:00
|
|
|
int id; /* cache identifier --- see syscache.h */
|
|
|
|
struct catcache *cc_next; /* link to next catcache */
|
|
|
|
char *cc_relname; /* name of relation the tuples come from */
|
|
|
|
char *cc_indname; /* name of index matching cache keys */
|
|
|
|
TupleDesc cc_tupdesc; /* tuple descriptor (copied from reldesc) */
|
|
|
|
short cc_ntup; /* # of tuples in this cache */
|
1997-09-08 04:41:22 +02:00
|
|
|
short cc_maxtup; /* max # of tuples allowed (LRU) */
|
2000-11-10 01:33:12 +01:00
|
|
|
short cc_size; /* # of hash buckets in this cache */
|
|
|
|
short cc_nkeys; /* number of keys (1..4) */
|
2000-02-21 04:36:59 +01:00
|
|
|
short cc_key[4]; /* AttrNumber of each key */
|
2000-06-05 09:29:25 +02:00
|
|
|
PGFunction cc_hashfunc[4]; /* hash function to use for each key */
|
2000-11-24 05:16:12 +01:00
|
|
|
ScanKeyData cc_skey[4]; /* precomputed key info for heap scans */
|
2000-11-16 23:30:52 +01:00
|
|
|
Dllist cc_lrulist; /* overall LRU list, most recent first */
|
|
|
|
Dllist cc_cache[NCCBUCK]; /* hash buckets */
|
1997-09-08 23:56:23 +02:00
|
|
|
} CatCache;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
#define InvalidCatalogCacheId (-1)
|
1996-08-28 03:59:28 +02:00
|
|
|
|
2000-06-28 05:33:33 +02:00
|
|
|
/* this extern duplicates utils/memutils.h... */
|
|
|
|
extern 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
|
|
|
|
2000-11-16 23:30:52 +01:00
|
|
|
extern CatCache *InitCatCache(int id, char *relname, char *indname,
|
2000-11-10 01:33:12 +01:00
|
|
|
int nkeys, int *key);
|
2000-11-16 23:30:52 +01:00
|
|
|
|
|
|
|
extern HeapTuple SearchCatCache(CatCache *cache,
|
2000-06-17 06:56:39 +02: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
|
|
|
|
|
|
|
extern void ResetSystemCache(void);
|
|
|
|
extern void SystemCacheRelationFlushed(Oid relId);
|
|
|
|
extern void CatalogCacheIdInvalidate(int cacheId, Index hashIndex,
|
|
|
|
ItemPointer pointer);
|
2001-01-05 23:54:37 +01:00
|
|
|
extern void PrepareToInvalidateCacheTuple(Relation relation,
|
2000-06-17 06:56:39 +02:00
|
|
|
HeapTuple tuple,
|
|
|
|
void (*function) (int, Index, ItemPointer));
|
1996-08-28 03:59:28 +02:00
|
|
|
|
1998-09-01 06:40:42 +02:00
|
|
|
#endif /* CATCACHE_H */
|