aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/catcache.h
blob: daecf2ff30a18a47cdbf01380c5494083109ff3a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*-------------------------------------------------------------------------
 *
 * catcache.h--
 *    Low-level catalog cache definitions.
 *
 *
 * Copyright (c) 1994, Regents of the University of California
 *
 * $Id: catcache.h,v 1.1.1.1 1996/07/09 06:22:01 scrappy Exp $
 *
 *-------------------------------------------------------------------------
 */
#ifndef	CATCACHE_H
#define CATCACHE_H

/* #define	CACHEDEBUG 	 turns DEBUG elogs on */

#include "postgres.h"
    
#include "access/skey.h"
#include "access/htup.h"
#include "utils/rel.h"
#include "nodes/memnodes.h"
#include "lib/dllist.h"

/*
 *	struct catctup:		tuples in the cache.
 *	struct catcache:	information for managing a cache.
 */

typedef struct catctup {
    HeapTuple	ct_tup;		/* A pointer to a tuple		*/
    Dlelem     *ct_node; /* points to LRU list is the CatCTup is in the cache,
			    else, points to the cache if the CatCTup is in 
			    LRU list */
} CatCTup;

/* voodoo constants */
#define	NCCBUCK	500	/* CatCache buckets*/
#define MAXTUP 300	/* Maximum # of tuples cached per cache */

typedef struct catcache {
    Oid		relationId;
    Oid		indexId;
    char	*cc_relname; 	/* relation name for defered open */
    char	*cc_indname; 	/* index name for defered open */
    HeapTuple	(*cc_iscanfunc)(); /* index scanfunction */
    TupleDesc 	cc_tupdesc;	/* tuple descriptor from reldesc */
    int		id;		/* XXX could be improved -hirohama */
    short	cc_ntup; 	/* # of tuples in this cache	*/
    short	cc_maxtup; 	/* max # of tuples allowed (LRU)*/
    short	cc_nkeys;
    short	cc_size;
    short	cc_key[4];
    short	cc_klen[4];
    ScanKeyData	cc_skey[4];
    struct catcache *cc_next;
    Dllist  *cc_lrulist;          /* LRU list, most recent first */
    Dllist  *cc_cache[NCCBUCK+1];
} CatCache;

#define	InvalidCatalogCacheId	(-1)

extern struct catcache	*Caches;
extern GlobalMemory	CacheCxt;

extern void CatalogCacheInitializeCache(struct catcache *cache, 
					Relation relation);
extern void CatalogCacheSetId(CatCache *cacheInOutP, int id);
extern long comphash(long l, char *v);
extern Index CatalogCacheComputeHashIndex(struct catcache *cacheInP);
extern Index CatalogCacheComputeTupleHashIndex(struct catcache *cacheInOutP,
				       Relation relation, HeapTuple tuple);
extern void CatCacheRemoveCTup(CatCache *cache, Dlelem *e);  
extern void CatalogCacheIdInvalidate(int cacheId, Index hashIndex, 
				     ItemPointer pointer);
extern void ResetSystemCache(void);
extern CatCache *InitSysCache(char *relname, char *indname, int id, int nkeys, 
			      int key[], HeapTuple (*iScanfuncP)());
extern HeapTuple SearchSysCache(struct catcache *cache, Datum v1, Datum v2,
				Datum v3, Datum v4);
extern void RelationInvalidateCatalogCacheTuple(Relation relation, 
				HeapTuple tuple, void (*function)());

#endif	/* CATCACHE_H */