postgresql/src/include/utils/catcache.h
Marc G. Fournier 6c7c6d0c05 From: Jan Wieck <jwieck@debis.com>
The diff looks so simple and easy. But to find it wasn't fun.

    It must have been there for a long time. What happened:

    When a tuple in one of some central catalogs was updated, the
    referenced  relation  got flushed, so it would be reopened on
    the next access (to reflect new  triggers,  rules  and  table
    structure changes into the relation cache).

    Some  data  (the  tupleDescriptor e.g.) is used in the system
    cache too. So when a relation is subject to the system cache,
    this  must know too that a cached system relation got flushed
    because the tupleDesc data gets freed during the flush!

    For the GRANT/REVOKE on pg_class it was  slightly  different.
    There  is some local data in inval.c that gets initialized on
    the first invalidation of a tuple in some  central  catalogs.
    This  needs a SysCache lookup in pg_class. But when the first
    of all commands is a GRANT on pg_class,  exactly  the  needed
    tuple is the one actually invalidated. So I added little code
    snippets that the initialization of the  local  variables  in
    inval.c will already happen during InitPostgres().
1998-02-23 17:44:24 +00:00

78 lines
2.3 KiB
C

/*-------------------------------------------------------------------------
*
* catcache.h--
* Low-level catalog cache definitions.
*
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: catcache.h,v 1.10 1998/02/23 17:44:22 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
#ifndef CATCACHE_H
#define CATCACHE_H
/* #define CACHEDEBUG turns DEBUG elogs on */
#include <access/htup.h>
#include <lib/dllist.h>
#include <nodes/memnodes.h>
#include <utils/rel.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 CatalogCacheIdInvalidate(int cacheId, Index hashIndex,
ItemPointer pointer);
extern void ResetSystemCache(void);
extern void SystemCacheRelationFlushed(Oid relId);
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 */