#ifndef CATCACHE_H
#define CATCACHE_H
#include "access/htup.h"
#include "access/skey.h"
#include "lib/ilist.h"
#include "utils/relcache.h"
#define CATCACHE_MAXKEYS 4
typedef uint32 (*CCHashFN) (Datum datum);
typedef bool (*CCFastEqualFN) (Datum a, Datum b);
typedef struct catcache
{
int id;
int cc_nbuckets;
TupleDesc cc_tupdesc;
dlist_head *cc_bucket;
CCHashFN cc_hashfunc[CATCACHE_MAXKEYS];
CCFastEqualFN cc_fastequal[CATCACHE_MAXKEYS];
int cc_keyno[CATCACHE_MAXKEYS];
int cc_nkeys;
int cc_ntup;
int cc_nlist;
int cc_nlbuckets;
dlist_head *cc_lbucket;
const char *cc_relname;
Oid cc_reloid;
Oid cc_indexoid;
bool cc_relisshared;
slist_node cc_next;
ScanKeyData cc_skey[CATCACHE_MAXKEYS];
#ifdef CATCACHE_STATS
long cc_searches;
long cc_hits;
long cc_neg_hits;
long cc_newloads;
long cc_invals;
long cc_lsearches;
long cc_lhits;
#endif
} CatCache;
typedef struct catctup
{
int ct_magic;
#define CT_MAGIC 0x57261502
uint32 hash_value;
Datum keys[CATCACHE_MAXKEYS];
dlist_node cache_elem;
int refcount;
bool dead;
bool negative;
HeapTupleData tuple;
struct catclist *c_list;
CatCache *my_cache;
} CatCTup;
typedef struct catclist
{
int cl_magic;
#define CL_MAGIC 0x52765103
uint32 hash_value;
dlist_node cache_elem;
Datum keys[CATCACHE_MAXKEYS];
int refcount;
bool dead;
bool ordered;
short nkeys;
int n_members;
CatCache *my_cache;
CatCTup *members[FLEXIBLE_ARRAY_MEMBER];
} CatCList;
typedef struct catcacheheader
{
slist_head ch_caches;
int ch_ntup;
} CatCacheHeader;
extern PGDLLIMPORT MemoryContext CacheMemoryContext;
extern void CreateCacheMemoryContext(void);
extern CatCache *InitCatCache(int id, Oid reloid, Oid indexoid,
int nkeys, const int *key,
int nbuckets);
extern void InitCatCachePhase2(CatCache *cache, bool touch_index);
extern HeapTuple SearchCatCache(CatCache *cache,
Datum v1, Datum v2, Datum v3, Datum v4);
extern HeapTuple SearchCatCache1(CatCache *cache,
Datum v1);
extern HeapTuple SearchCatCache2(CatCache *cache,
Datum v1, Datum v2);
extern HeapTuple SearchCatCache3(CatCache *cache,
Datum v1, Datum v2, Datum v3);
extern HeapTuple SearchCatCache4(CatCache *cache,
Datum v1, Datum v2, Datum v3, Datum v4);
extern void ReleaseCatCache(HeapTuple tuple);
extern uint32 GetCatCacheHashValue(CatCache *cache,
Datum v1, Datum v2,
Datum v3, Datum v4);
extern CatCList *SearchCatCacheList(CatCache *cache, int nkeys,
Datum v1, Datum v2,
Datum v3);
extern void ReleaseCatCacheList(CatCList *list);
extern void ResetCatalogCaches(void);
extern void ResetCatalogCachesExt(bool debug_discard);
extern void CatalogCacheFlushCatalog(Oid catId);
extern void CatCacheInvalidate(CatCache *cache, uint32 hashValue);
extern void PrepareToInvalidateCacheTuple(Relation relation,
HeapTuple tuple,
HeapTuple newtuple,
void (*function) (int, uint32, Oid));
#endif