1996-08-27 21:59:28 -04:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
*
|
1999-02-13 18:22:53 -05:00
|
|
|
* syscache.h
|
1997-09-07 01:04:48 -04:00
|
|
|
* System catalog cache definitions.
|
1996-08-27 21:59:28 -04:00
|
|
|
*
|
1999-08-08 23:13:31 -04:00
|
|
|
* See also lsyscache.h, which provides convenience routines for
|
|
|
|
|
* common cache-lookup operations.
|
1996-08-27 21:59:28 -04:00
|
|
|
*
|
2010-01-02 11:58:17 -05:00
|
|
|
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
|
2000-01-26 00:58:53 -05:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-08-27 21:59:28 -04:00
|
|
|
*
|
2010-02-14 13:42:19 -05:00
|
|
|
* $PostgreSQL: pgsql/src/include/utils/syscache.h,v 1.79 2010/02/14 18:42:18 rhaas Exp $
|
1996-08-27 21:59:28 -04:00
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
1997-09-07 01:04:48 -04:00
|
|
|
#ifndef SYSCACHE_H
|
1996-08-27 21:59:28 -04:00
|
|
|
#define SYSCACHE_H
|
|
|
|
|
|
2006-07-11 09:54:25 -04:00
|
|
|
#include "utils/catcache.h"
|
1996-10-19 00:16:04 -04:00
|
|
|
|
1996-08-27 21:59:28 -04:00
|
|
|
/*
|
1997-09-07 01:04:48 -04:00
|
|
|
* SysCache identifiers.
|
1996-08-27 21:59:28 -04:00
|
|
|
*
|
2008-05-06 21:04:49 -04:00
|
|
|
* The order of these identifiers must match the order
|
|
|
|
|
* of the entries in the array cacheinfo[] in syscache.c.
|
|
|
|
|
* Keep them in alphabetical order (renumbering only costs a
|
|
|
|
|
* backend rebuild).
|
1996-08-27 21:59:28 -04:00
|
|
|
*/
|
|
|
|
|
|
2008-05-06 21:04:49 -04:00
|
|
|
enum SysCacheIdentifier
|
|
|
|
|
{
|
|
|
|
|
AGGFNOID = 0,
|
|
|
|
|
AMNAME,
|
|
|
|
|
AMOID,
|
|
|
|
|
AMOPOPID,
|
|
|
|
|
AMOPSTRATEGY,
|
|
|
|
|
AMPROCNUM,
|
|
|
|
|
ATTNAME,
|
|
|
|
|
ATTNUM,
|
|
|
|
|
AUTHMEMMEMROLE,
|
|
|
|
|
AUTHMEMROLEMEM,
|
|
|
|
|
AUTHNAME,
|
|
|
|
|
AUTHOID,
|
|
|
|
|
CASTSOURCETARGET,
|
|
|
|
|
CLAAMNAMENSP,
|
|
|
|
|
CLAOID,
|
|
|
|
|
CONDEFAULT,
|
|
|
|
|
CONNAMENSP,
|
|
|
|
|
CONSTROID,
|
|
|
|
|
CONVOID,
|
|
|
|
|
DATABASEOID,
|
2009-10-05 15:24:49 -04:00
|
|
|
DEFACLROLENSPOBJ,
|
2008-05-06 21:04:49 -04:00
|
|
|
ENUMOID,
|
|
|
|
|
ENUMTYPOIDNAME,
|
2008-12-19 11:25:19 -05:00
|
|
|
FOREIGNDATAWRAPPERNAME,
|
|
|
|
|
FOREIGNDATAWRAPPEROID,
|
|
|
|
|
FOREIGNSERVERNAME,
|
|
|
|
|
FOREIGNSERVEROID,
|
2008-05-06 21:04:49 -04:00
|
|
|
INDEXRELID,
|
|
|
|
|
LANGNAME,
|
|
|
|
|
LANGOID,
|
|
|
|
|
NAMESPACENAME,
|
|
|
|
|
NAMESPACEOID,
|
|
|
|
|
OPERNAMENSP,
|
|
|
|
|
OPEROID,
|
|
|
|
|
OPFAMILYAMNAMENSP,
|
|
|
|
|
OPFAMILYOID,
|
|
|
|
|
PROCNAMEARGSNSP,
|
|
|
|
|
PROCOID,
|
|
|
|
|
RELNAMENSP,
|
|
|
|
|
RELOID,
|
|
|
|
|
RULERELNAME,
|
2009-12-29 15:11:45 -05:00
|
|
|
STATRELATTINH,
|
2010-01-05 16:54:00 -05:00
|
|
|
TABLESPACEOID,
|
2008-05-06 21:04:49 -04:00
|
|
|
TSCONFIGMAP,
|
|
|
|
|
TSCONFIGNAMENSP,
|
|
|
|
|
TSCONFIGOID,
|
|
|
|
|
TSDICTNAMENSP,
|
|
|
|
|
TSDICTOID,
|
|
|
|
|
TSPARSERNAMENSP,
|
|
|
|
|
TSPARSEROID,
|
|
|
|
|
TSTEMPLATENAMENSP,
|
|
|
|
|
TSTEMPLATEOID,
|
|
|
|
|
TYPENAMENSP,
|
2008-12-19 11:25:19 -05:00
|
|
|
TYPEOID,
|
|
|
|
|
USERMAPPINGOID,
|
|
|
|
|
USERMAPPINGUSERSERVER
|
2008-05-06 21:04:49 -04:00
|
|
|
};
|
1996-08-27 21:59:28 -04:00
|
|
|
|
1997-09-07 22:41:22 -04:00
|
|
|
extern void InitCatalogCache(void);
|
2002-02-19 15:11:20 -05:00
|
|
|
extern void InitCatalogCachePhase2(void);
|
2000-11-16 17:30:52 -05:00
|
|
|
|
|
|
|
|
extern HeapTuple SearchSysCache(int cacheId,
|
2001-03-21 23:01:46 -05:00
|
|
|
Datum key1, Datum key2, Datum key3, Datum key4);
|
2000-11-16 17:30:52 -05:00
|
|
|
extern void ReleaseSysCache(HeapTuple tuple);
|
|
|
|
|
|
|
|
|
|
/* convenience routines */
|
|
|
|
|
extern HeapTuple SearchSysCacheCopy(int cacheId,
|
2001-03-21 23:01:46 -05:00
|
|
|
Datum key1, Datum key2, Datum key3, Datum key4);
|
2001-08-10 14:57:42 -04:00
|
|
|
extern bool SearchSysCacheExists(int cacheId,
|
2001-10-25 01:50:21 -04:00
|
|
|
Datum key1, Datum key2, Datum key3, Datum key4);
|
2000-11-16 17:30:52 -05:00
|
|
|
extern Oid GetSysCacheOid(int cacheId,
|
2001-03-21 23:01:46 -05:00
|
|
|
Datum key1, Datum key2, Datum key3, Datum key4);
|
2000-11-16 17:30:52 -05:00
|
|
|
|
2002-08-02 14:15:10 -04:00
|
|
|
extern HeapTuple SearchSysCacheAttName(Oid relid, const char *attname);
|
|
|
|
|
extern HeapTuple SearchSysCacheCopyAttName(Oid relid, const char *attname);
|
|
|
|
|
extern bool SearchSysCacheExistsAttName(Oid relid, const char *attname);
|
|
|
|
|
|
2000-01-22 22:43:24 -05:00
|
|
|
extern Datum SysCacheGetAttr(int cacheId, HeapTuple tup,
|
2000-06-17 00:56:39 -04:00
|
|
|
AttrNumber attributeNumber, bool *isNull);
|
2001-10-28 01:26:15 -05:00
|
|
|
|
2002-04-06 01:59:25 -05:00
|
|
|
/* list-search interface. Users of this must import catcache.h too */
|
|
|
|
|
extern struct catclist *SearchSysCacheList(int cacheId, int nkeys,
|
2002-09-04 16:31:48 -04:00
|
|
|
Datum key1, Datum key2, Datum key3, Datum key4);
|
|
|
|
|
|
Use a safer method for determining whether relcache init file is stale.
When we invalidate the relcache entry for a system catalog or index, we
must also delete the relcache "init file" if the init file contains a copy
of that rel's entry. The old way of doing this relied on a specially
maintained list of the OIDs of relations present in the init file: we made
the list either when reading the file in, or when writing the file out.
The problem is that when writing the file out, we included only rels
present in our local relcache, which might have already suffered some
deletions due to relcache inval events. In such cases we correctly decided
not to overwrite the real init file with incomplete data --- but we still
used the incomplete initFileRelationIds list for the rest of the current
session. This could result in wrong decisions about whether the session's
own actions require deletion of the init file, potentially allowing an init
file created by some other concurrent session to be left around even though
it's been made stale.
Since we don't support changing the schema of a system catalog at runtime,
the only likely scenario in which this would cause a problem in the field
involves a "vacuum full" on a catalog concurrently with other activity, and
even then it's far from easy to provoke. Remarkably, this has been broken
since 2002 (in commit 786340441706ac1957a031f11ad1c2e5b6e18314), but we had
never seen a reproducible test case until recently. If it did happen in
the field, the symptoms would probably involve unexpected "cache lookup
failed" errors to begin with, then "could not open file" failures after the
next checkpoint, as all accesses to the affected catalog stopped working.
Recovery would require manually removing the stale "pg_internal.init" file.
To fix, get rid of the initFileRelationIds list, and instead consult
syscache.c's list of relations used in catalog caches to decide whether a
relation is included in the init file. This should be a tad more efficient
anyway, since we're replacing linear search of a list with ~100 entries
with a binary search. It's a bit ugly that the init file contents are now
so directly tied to the catalog caches, but in practice that won't make
much difference.
Back-patch to all supported branches.
2015-06-07 15:32:09 -04:00
|
|
|
extern bool RelationSupportsSysCache(Oid relid);
|
|
|
|
|
|
2010-02-14 13:42:19 -05:00
|
|
|
/*
|
|
|
|
|
* The use of the macros below rather than direct calls to the corresponding
|
|
|
|
|
* functions is encouraged, as it insulates the caller from changes in the
|
|
|
|
|
* maximum number of keys.
|
|
|
|
|
*/
|
|
|
|
|
#define SearchSysCache1(cacheId, key1) \
|
|
|
|
|
SearchSysCache(cacheId, key1, 0, 0, 0)
|
|
|
|
|
#define SearchSysCache2(cacheId, key1, key2) \
|
|
|
|
|
SearchSysCache(cacheId, key1, key2, 0, 0)
|
|
|
|
|
#define SearchSysCache3(cacheId, key1, key2, key3) \
|
|
|
|
|
SearchSysCache(cacheId, key1, key2, key3, 0)
|
|
|
|
|
#define SearchSysCache4(cacheId, key1, key2, key3, key4) \
|
|
|
|
|
SearchSysCache(cacheId, key1, key2, key3, key4)
|
|
|
|
|
|
|
|
|
|
#define SearchSysCacheCopy1(cacheId, key1) \
|
|
|
|
|
SearchSysCacheCopy(cacheId, key1, 0, 0, 0)
|
|
|
|
|
#define SearchSysCacheCopy2(cacheId, key1, key2) \
|
|
|
|
|
SearchSysCacheCopy(cacheId, key1, key2, 0, 0)
|
|
|
|
|
#define SearchSysCacheCopy3(cacheId, key1, key2, key3) \
|
|
|
|
|
SearchSysCacheCopy(cacheId, key1, key2, key3, 0)
|
|
|
|
|
#define SearchSysCacheCopy4(cacheId, key1, key2, key3, key4) \
|
|
|
|
|
SearchSysCacheCopy(cacheId, key1, key2, key3, key4)
|
|
|
|
|
|
|
|
|
|
#define SearchSysCacheExists1(cacheId, key1) \
|
|
|
|
|
SearchSysCacheExists(cacheId, key1, 0, 0, 0)
|
|
|
|
|
#define SearchSysCacheExists2(cacheId, key1, key2) \
|
|
|
|
|
SearchSysCacheExists(cacheId, key1, key2, 0, 0)
|
|
|
|
|
#define SearchSysCacheExists3(cacheId, key1, key2, key3) \
|
|
|
|
|
SearchSysCacheExists(cacheId, key1, key2, key3, 0)
|
|
|
|
|
#define SearchSysCacheExists4(cacheId, key1, key2, key3, key4) \
|
|
|
|
|
SearchSysCacheExists(cacheId, key1, key2, key3, key4)
|
|
|
|
|
|
|
|
|
|
#define GetSysCacheOid1(cacheId, key1) \
|
|
|
|
|
GetSysCacheOid(cacheId, key1, 0, 0, 0)
|
|
|
|
|
#define GetSysCacheOid2(cacheId, key1, key2) \
|
|
|
|
|
GetSysCacheOid(cacheId, key1, key2, 0, 0)
|
|
|
|
|
#define GetSysCacheOid3(cacheId, key1, key2, key3) \
|
|
|
|
|
GetSysCacheOid(cacheId, key1, key2, key3, 0)
|
|
|
|
|
#define GetSysCacheOid4(cacheId, key1, key2, key3, key4) \
|
|
|
|
|
GetSysCacheOid(cacheId, key1, key2, key3, key4)
|
|
|
|
|
|
|
|
|
|
#define SearchSysCacheList1(cacheId, key1) \
|
|
|
|
|
SearchSysCacheList(cacheId, 1, key1, 0, 0, 0)
|
|
|
|
|
#define SearchSysCacheList2(cacheId, key1, key2) \
|
|
|
|
|
SearchSysCacheList(cacheId, 2, key1, key2, 0, 0)
|
|
|
|
|
#define SearchSysCacheList3(cacheId, key1, key2, key3) \
|
|
|
|
|
SearchSysCacheList(cacheId, 3, key1, key2, key3, 0)
|
|
|
|
|
#define SearchSysCacheList4(cacheId, key1, key2, key3, key4) \
|
|
|
|
|
SearchSysCacheList(cacheId, 4, key1, key2, key3, key4)
|
|
|
|
|
|
2002-09-04 16:31:48 -04:00
|
|
|
#define ReleaseSysCacheList(x) ReleaseCatCacheList(x)
|
2002-04-06 01:59:25 -05:00
|
|
|
|
2001-11-05 12:46:40 -05:00
|
|
|
#endif /* SYSCACHE_H */
|