1996-07-09 08:22:35 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* syscache.c
|
1997-09-07 07:04:48 +02:00
|
|
|
* System cache management routines
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
2003-08-04 04:40:20 +02:00
|
|
|
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
2003-11-12 22:15:59 +01:00
|
|
|
* $Header: /cvsroot/pgsql/src/backend/utils/cache/syscache.c,v 1.92 2003/11/12 21:15:56 tgl Exp $
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
* NOTES
|
1997-09-07 07:04:48 +02:00
|
|
|
* These routines allow the parser/planner/executor to perform
|
|
|
|
* rapid lookups on the contents of the system catalogs.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
1997-09-07 07:04:48 +02:00
|
|
|
* see catalog/syscache.h for a list of the cache id's
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
1996-11-03 07:54:38 +01:00
|
|
|
#include "postgres.h"
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
#include "access/heapam.h"
|
2000-06-17 06:56:39 +02:00
|
|
|
#include "access/transam.h"
|
|
|
|
#include "utils/builtins.h"
|
1996-07-09 08:22:35 +02:00
|
|
|
#include "catalog/catname.h"
|
2000-06-17 06:56:39 +02:00
|
|
|
#include "catalog/indexing.h"
|
1999-07-16 07:23:30 +02:00
|
|
|
#include "catalog/pg_aggregate.h"
|
1996-07-09 08:22:35 +02:00
|
|
|
#include "catalog/pg_amop.h"
|
2001-08-21 18:36:06 +02:00
|
|
|
#include "catalog/pg_amproc.h"
|
2002-07-19 01:11:32 +02:00
|
|
|
#include "catalog/pg_cast.h"
|
2002-07-11 09:39:28 +02:00
|
|
|
#include "catalog/pg_conversion.h"
|
1996-07-09 08:22:35 +02:00
|
|
|
#include "catalog/pg_group.h"
|
|
|
|
#include "catalog/pg_index.h"
|
|
|
|
#include "catalog/pg_inherits.h"
|
|
|
|
#include "catalog/pg_language.h"
|
2002-03-22 22:34:44 +01:00
|
|
|
#include "catalog/pg_namespace.h"
|
1996-07-09 08:22:35 +02:00
|
|
|
#include "catalog/pg_opclass.h"
|
|
|
|
#include "catalog/pg_operator.h"
|
|
|
|
#include "catalog/pg_proc.h"
|
|
|
|
#include "catalog/pg_rewrite.h"
|
1998-02-25 14:09:49 +01:00
|
|
|
#include "catalog/pg_shadow.h"
|
1999-11-24 18:09:28 +01:00
|
|
|
#include "catalog/pg_statistic.h"
|
1999-07-16 07:23:30 +02:00
|
|
|
#include "catalog/pg_type.h"
|
|
|
|
#include "utils/catcache.h"
|
2000-06-17 06:56:39 +02:00
|
|
|
#include "utils/syscache.h"
|
2000-02-18 10:30:20 +01:00
|
|
|
#include "miscadmin.h"
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1999-11-22 18:56:41 +01:00
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
Adding system caches:
|
|
|
|
|
|
|
|
Add your new cache to the list in include/utils/syscache.h. Keep
|
|
|
|
the list sorted alphabetically and adjust the cache numbers
|
|
|
|
accordingly.
|
2000-01-24 03:12:58 +01:00
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
Add your entry to the cacheinfo[] array below. All cache lists are
|
1999-11-22 18:56:41 +01:00
|
|
|
alphabetical, so add it in the proper place. Specify the relation
|
2001-06-18 05:35:07 +02:00
|
|
|
name, index name, number of keys, and key attribute numbers. If the
|
|
|
|
relation contains tuples that are associated with a particular relation
|
|
|
|
(for example, its attributes, rules, triggers, etc) then specify the
|
|
|
|
attribute number that contains the OID of the associated relation.
|
|
|
|
This is used by CatalogCacheFlushRelation() to remove the correct
|
|
|
|
tuples during a table drop or relcache invalidation event.
|
1999-11-22 18:56:41 +01:00
|
|
|
|
2002-08-05 05:29:17 +02:00
|
|
|
There must be a unique index underlying each syscache (ie, an index
|
|
|
|
whose key is the same as that of the cache). If there is not one
|
|
|
|
already, add definitions for it to include/catalog/indexing.h: you
|
|
|
|
need a #define for the index name and a DECLARE_UNIQUE_INDEX macro
|
|
|
|
with the actual declaration. (This will require a catversion.h update,
|
|
|
|
while simply adding/deleting caches only requires a recompile.)
|
1999-11-22 18:56:41 +01:00
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
Finally, any place your relation gets heap_insert() or
|
2002-08-05 05:29:17 +02:00
|
|
|
heap_update calls, make sure there is a CatalogUpdateIndexes() or
|
|
|
|
similar call. The heap_* calls do not update indexes.
|
2000-01-24 03:12:58 +01:00
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
bjm 1999/11/22
|
1999-11-22 18:56:41 +01:00
|
|
|
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2001-02-22 19:39:20 +01:00
|
|
|
/*
|
2000-06-17 06:56:39 +02:00
|
|
|
* struct cachedesc: information defining a single syscache
|
|
|
|
*/
|
|
|
|
struct cachedesc
|
|
|
|
{
|
2002-03-26 20:17:02 +01:00
|
|
|
const char *name; /* name of the relation being cached */
|
|
|
|
const char *indname; /* name of index relation for this cache */
|
2001-06-18 05:35:07 +02:00
|
|
|
int reloidattr; /* attr number of rel OID reference, or 0 */
|
2000-06-17 06:56:39 +02:00
|
|
|
int nkeys; /* # of keys needed for cache lookup */
|
|
|
|
int key[4]; /* attribute numbers of key attrs */
|
|
|
|
};
|
|
|
|
|
2002-03-26 20:17:02 +01:00
|
|
|
static const struct cachedesc cacheinfo[] = {
|
2002-04-11 22:00:18 +02:00
|
|
|
{AggregateRelationName, /* AGGFNOID */
|
|
|
|
AggregateFnoidIndex,
|
2002-03-22 00:27:25 +01:00
|
|
|
0,
|
|
|
|
1,
|
|
|
|
{
|
2002-04-11 22:00:18 +02:00
|
|
|
Anum_pg_aggregate_aggfnoid,
|
2002-03-22 00:27:25 +01:00
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0
|
|
|
|
}},
|
1999-11-22 18:56:41 +01:00
|
|
|
{AccessMethodRelationName, /* AMNAME */
|
2001-03-22 05:01:46 +01:00
|
|
|
AmNameIndex,
|
2001-06-18 05:35:07 +02:00
|
|
|
0,
|
1999-11-22 18:56:41 +01:00
|
|
|
1,
|
|
|
|
{
|
|
|
|
Anum_pg_am_amname,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0
|
2001-03-22 05:01:46 +01:00
|
|
|
}},
|
2002-02-19 21:11:20 +01:00
|
|
|
{AccessMethodRelationName, /* AMOID */
|
|
|
|
AmOidIndex,
|
|
|
|
0,
|
|
|
|
1,
|
|
|
|
{
|
|
|
|
ObjectIdAttributeNumber,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0
|
|
|
|
}},
|
1997-09-07 07:04:48 +02:00
|
|
|
{AccessMethodOperatorRelationName, /* AMOPOPID */
|
2001-08-21 18:36:06 +02:00
|
|
|
AccessMethodOperatorIndex,
|
2001-06-18 05:35:07 +02:00
|
|
|
0,
|
2001-08-21 18:36:06 +02:00
|
|
|
2,
|
1998-08-19 04:04:17 +02:00
|
|
|
{
|
1997-09-07 07:04:48 +02:00
|
|
|
Anum_pg_amop_amopopr,
|
2003-05-13 06:38:58 +02:00
|
|
|
Anum_pg_amop_amopclaid,
|
2001-08-21 18:36:06 +02:00
|
|
|
0,
|
1998-08-19 04:04:17 +02:00
|
|
|
0
|
2001-03-22 05:01:46 +01:00
|
|
|
}},
|
1997-09-07 07:04:48 +02:00
|
|
|
{AccessMethodOperatorRelationName, /* AMOPSTRATEGY */
|
2001-03-22 05:01:46 +01:00
|
|
|
AccessMethodStrategyIndex,
|
2001-06-18 05:35:07 +02:00
|
|
|
0,
|
2003-11-12 22:15:59 +01:00
|
|
|
3,
|
1998-08-19 04:04:17 +02:00
|
|
|
{
|
1997-09-07 07:04:48 +02:00
|
|
|
Anum_pg_amop_amopclaid,
|
2003-11-12 22:15:59 +01:00
|
|
|
Anum_pg_amop_amopsubtype,
|
1997-09-07 07:04:48 +02:00
|
|
|
Anum_pg_amop_amopstrategy,
|
2001-08-21 18:36:06 +02:00
|
|
|
0
|
|
|
|
}},
|
2001-10-25 07:50:21 +02:00
|
|
|
{AccessMethodProcedureRelationName, /* AMPROCNUM */
|
2001-08-21 18:36:06 +02:00
|
|
|
AccessMethodProcedureIndex,
|
|
|
|
0,
|
2003-11-12 22:15:59 +01:00
|
|
|
3,
|
2001-08-21 18:36:06 +02:00
|
|
|
{
|
|
|
|
Anum_pg_amproc_amopclaid,
|
2003-11-12 22:15:59 +01:00
|
|
|
Anum_pg_amproc_amprocsubtype,
|
2001-08-21 18:36:06 +02:00
|
|
|
Anum_pg_amproc_amprocnum,
|
1998-08-19 04:04:17 +02:00
|
|
|
0
|
2001-03-22 05:01:46 +01:00
|
|
|
}},
|
1997-09-07 07:04:48 +02:00
|
|
|
{AttributeRelationName, /* ATTNAME */
|
2001-03-22 05:01:46 +01:00
|
|
|
AttributeRelidNameIndex,
|
2001-06-18 05:35:07 +02:00
|
|
|
Anum_pg_attribute_attrelid,
|
1997-09-07 07:04:48 +02:00
|
|
|
2,
|
1998-08-19 04:04:17 +02:00
|
|
|
{
|
|
|
|
Anum_pg_attribute_attrelid,
|
1997-09-07 07:04:48 +02:00
|
|
|
Anum_pg_attribute_attname,
|
|
|
|
0,
|
1998-08-19 04:04:17 +02:00
|
|
|
0
|
2001-03-22 05:01:46 +01:00
|
|
|
}},
|
1997-09-07 07:04:48 +02:00
|
|
|
{AttributeRelationName, /* ATTNUM */
|
2001-03-22 05:01:46 +01:00
|
|
|
AttributeRelidNumIndex,
|
2001-06-18 05:35:07 +02:00
|
|
|
Anum_pg_attribute_attrelid,
|
1997-09-07 07:04:48 +02:00
|
|
|
2,
|
1998-08-19 04:04:17 +02:00
|
|
|
{
|
|
|
|
Anum_pg_attribute_attrelid,
|
1997-09-07 07:04:48 +02:00
|
|
|
Anum_pg_attribute_attnum,
|
|
|
|
0,
|
1998-08-19 04:04:17 +02:00
|
|
|
0
|
2001-03-22 05:01:46 +01:00
|
|
|
}},
|
2002-07-19 01:11:32 +02:00
|
|
|
{
|
2002-09-04 22:31:48 +02:00
|
|
|
CastRelationName, /* CASTSOURCETARGET */
|
2002-07-19 01:11:32 +02:00
|
|
|
CastSourceTargetIndex,
|
|
|
|
0,
|
|
|
|
2,
|
|
|
|
{
|
|
|
|
Anum_pg_cast_castsource,
|
|
|
|
Anum_pg_cast_casttarget,
|
|
|
|
0,
|
|
|
|
0
|
|
|
|
}},
|
2002-04-17 22:57:57 +02:00
|
|
|
{OperatorClassRelationName, /* CLAAMNAMENSP */
|
|
|
|
OpclassAmNameNspIndex,
|
2001-06-18 05:35:07 +02:00
|
|
|
0,
|
2002-04-17 22:57:57 +02:00
|
|
|
3,
|
1999-11-22 18:56:41 +01:00
|
|
|
{
|
2001-08-21 18:36:06 +02:00
|
|
|
Anum_pg_opclass_opcamid,
|
|
|
|
Anum_pg_opclass_opcname,
|
2002-04-17 22:57:57 +02:00
|
|
|
Anum_pg_opclass_opcnamespace,
|
1999-11-22 18:56:41 +01:00
|
|
|
0
|
2001-03-22 05:01:46 +01:00
|
|
|
}},
|
2001-08-21 18:36:06 +02:00
|
|
|
{OperatorClassRelationName, /* CLAOID */
|
|
|
|
OpclassOidIndex,
|
2001-06-18 05:35:07 +02:00
|
|
|
0,
|
1999-11-22 18:56:41 +01:00
|
|
|
1,
|
|
|
|
{
|
2001-08-21 18:36:06 +02:00
|
|
|
ObjectIdAttributeNumber,
|
1999-11-22 18:56:41 +01:00
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0
|
2001-03-22 05:01:46 +01:00
|
|
|
}},
|
2002-09-04 22:31:48 +02:00
|
|
|
{ConversionRelationName, /* CONDEFAULT */
|
2002-07-25 12:07:13 +02:00
|
|
|
ConversionDefaultIndex,
|
|
|
|
0,
|
|
|
|
4,
|
|
|
|
{
|
|
|
|
Anum_pg_conversion_connamespace,
|
|
|
|
Anum_pg_conversion_conforencoding,
|
|
|
|
Anum_pg_conversion_contoencoding,
|
|
|
|
ObjectIdAttributeNumber,
|
|
|
|
}},
|
2002-09-04 22:31:48 +02:00
|
|
|
{ConversionRelationName, /* CONNAMENSP */
|
2002-07-11 09:39:28 +02:00
|
|
|
ConversionNameNspIndex,
|
|
|
|
0,
|
|
|
|
2,
|
|
|
|
{
|
|
|
|
Anum_pg_conversion_conname,
|
|
|
|
Anum_pg_conversion_connamespace,
|
|
|
|
0,
|
|
|
|
0
|
|
|
|
}},
|
2002-09-04 22:31:48 +02:00
|
|
|
{ConversionRelationName, /* CONOID */
|
2002-07-25 12:07:13 +02:00
|
|
|
ConversionOidIndex,
|
|
|
|
0,
|
|
|
|
1,
|
|
|
|
{
|
|
|
|
ObjectIdAttributeNumber,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0
|
|
|
|
}},
|
1999-11-22 18:56:41 +01:00
|
|
|
{GroupRelationName, /* GRONAME */
|
2001-03-22 05:01:46 +01:00
|
|
|
GroupNameIndex,
|
2001-06-18 05:35:07 +02:00
|
|
|
0,
|
1999-11-22 18:56:41 +01:00
|
|
|
1,
|
|
|
|
{
|
|
|
|
Anum_pg_group_groname,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0
|
2001-03-22 05:01:46 +01:00
|
|
|
}},
|
1999-11-22 18:56:41 +01:00
|
|
|
{GroupRelationName, /* GROSYSID */
|
2001-03-22 05:01:46 +01:00
|
|
|
GroupSysidIndex,
|
2001-06-18 05:35:07 +02:00
|
|
|
0,
|
1999-11-22 18:56:41 +01:00
|
|
|
1,
|
|
|
|
{
|
|
|
|
Anum_pg_group_grosysid,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0
|
2001-03-22 05:01:46 +01:00
|
|
|
}},
|
1997-09-07 07:04:48 +02:00
|
|
|
{IndexRelationName, /* INDEXRELID */
|
2001-03-22 05:01:46 +01:00
|
|
|
IndexRelidIndex,
|
2001-06-18 05:35:07 +02:00
|
|
|
Anum_pg_index_indrelid,
|
1997-09-07 07:04:48 +02:00
|
|
|
1,
|
1998-08-19 04:04:17 +02:00
|
|
|
{
|
|
|
|
Anum_pg_index_indexrelid,
|
1997-09-07 07:04:48 +02:00
|
|
|
0,
|
|
|
|
0,
|
1998-08-19 04:04:17 +02:00
|
|
|
0
|
2001-03-22 05:01:46 +01:00
|
|
|
}},
|
1999-11-22 18:56:41 +01:00
|
|
|
{InheritsRelationName, /* INHRELID */
|
2001-03-22 05:01:46 +01:00
|
|
|
InheritsRelidSeqnoIndex,
|
2001-06-18 05:35:07 +02:00
|
|
|
Anum_pg_inherits_inhrelid,
|
1999-11-22 18:56:41 +01:00
|
|
|
2,
|
|
|
|
{
|
|
|
|
Anum_pg_inherits_inhrelid,
|
|
|
|
Anum_pg_inherits_inhseqno,
|
|
|
|
0,
|
|
|
|
0
|
2001-03-22 05:01:46 +01:00
|
|
|
}},
|
1999-11-22 18:56:41 +01:00
|
|
|
{LanguageRelationName, /* LANGNAME */
|
2001-03-22 05:01:46 +01:00
|
|
|
LanguageNameIndex,
|
2001-06-18 05:35:07 +02:00
|
|
|
0,
|
1997-09-07 07:04:48 +02:00
|
|
|
1,
|
1998-08-19 04:04:17 +02:00
|
|
|
{
|
|
|
|
Anum_pg_language_lanname,
|
1997-09-07 07:04:48 +02:00
|
|
|
0,
|
|
|
|
0,
|
1998-08-19 04:04:17 +02:00
|
|
|
0
|
2001-03-22 05:01:46 +01:00
|
|
|
}},
|
1999-11-22 18:56:41 +01:00
|
|
|
{LanguageRelationName, /* LANGOID */
|
2001-03-22 05:01:46 +01:00
|
|
|
LanguageOidIndex,
|
2001-06-18 05:35:07 +02:00
|
|
|
0,
|
1999-11-22 18:56:41 +01:00
|
|
|
1,
|
|
|
|
{
|
|
|
|
ObjectIdAttributeNumber,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0
|
2001-03-22 05:01:46 +01:00
|
|
|
}},
|
2002-03-22 22:34:44 +01:00
|
|
|
{NamespaceRelationName, /* NAMESPACENAME */
|
|
|
|
NamespaceNameIndex,
|
|
|
|
0,
|
|
|
|
1,
|
|
|
|
{
|
|
|
|
Anum_pg_namespace_nspname,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0
|
|
|
|
}},
|
|
|
|
{NamespaceRelationName, /* NAMESPACEOID */
|
|
|
|
NamespaceOidIndex,
|
|
|
|
0,
|
|
|
|
1,
|
|
|
|
{
|
|
|
|
ObjectIdAttributeNumber,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0
|
|
|
|
}},
|
2002-04-17 01:08:12 +02:00
|
|
|
{OperatorRelationName, /* OPERNAMENSP */
|
|
|
|
OperatorNameNspIndex,
|
2001-06-18 05:35:07 +02:00
|
|
|
0,
|
1997-09-07 07:04:48 +02:00
|
|
|
4,
|
1998-08-19 04:04:17 +02:00
|
|
|
{
|
|
|
|
Anum_pg_operator_oprname,
|
1997-09-07 07:04:48 +02:00
|
|
|
Anum_pg_operator_oprleft,
|
|
|
|
Anum_pg_operator_oprright,
|
2002-04-17 01:08:12 +02:00
|
|
|
Anum_pg_operator_oprnamespace
|
2001-03-22 05:01:46 +01:00
|
|
|
}},
|
1999-11-22 18:56:41 +01:00
|
|
|
{OperatorRelationName, /* OPEROID */
|
2001-03-22 05:01:46 +01:00
|
|
|
OperatorOidIndex,
|
2001-06-18 05:35:07 +02:00
|
|
|
0,
|
1997-09-07 07:04:48 +02:00
|
|
|
1,
|
1998-08-19 04:04:17 +02:00
|
|
|
{
|
|
|
|
ObjectIdAttributeNumber,
|
1997-09-07 07:04:48 +02:00
|
|
|
0,
|
|
|
|
0,
|
1998-08-19 04:04:17 +02:00
|
|
|
0
|
2001-03-22 05:01:46 +01:00
|
|
|
}},
|
2002-04-09 22:35:55 +02:00
|
|
|
{ProcedureRelationName, /* PROCNAMENSP */
|
|
|
|
ProcedureNameNspIndex,
|
2001-06-18 05:35:07 +02:00
|
|
|
0,
|
2002-04-09 22:35:55 +02:00
|
|
|
4,
|
1998-08-19 04:04:17 +02:00
|
|
|
{
|
|
|
|
Anum_pg_proc_proname,
|
1997-09-07 07:04:48 +02:00
|
|
|
Anum_pg_proc_pronargs,
|
|
|
|
Anum_pg_proc_proargtypes,
|
2002-04-09 22:35:55 +02:00
|
|
|
Anum_pg_proc_pronamespace
|
2001-03-22 05:01:46 +01:00
|
|
|
}},
|
1999-11-22 18:56:41 +01:00
|
|
|
{ProcedureRelationName, /* PROCOID */
|
2001-03-22 05:01:46 +01:00
|
|
|
ProcedureOidIndex,
|
2001-06-18 05:35:07 +02:00
|
|
|
0,
|
1997-09-07 07:04:48 +02:00
|
|
|
1,
|
1998-08-19 04:04:17 +02:00
|
|
|
{
|
|
|
|
ObjectIdAttributeNumber,
|
1997-09-07 07:04:48 +02:00
|
|
|
0,
|
|
|
|
0,
|
1998-08-19 04:04:17 +02:00
|
|
|
0
|
2001-03-22 05:01:46 +01:00
|
|
|
}},
|
2002-03-26 20:17:02 +01:00
|
|
|
{RelationRelationName, /* RELNAMENSP */
|
|
|
|
ClassNameNspIndex,
|
2001-06-18 05:35:07 +02:00
|
|
|
ObjectIdAttributeNumber,
|
2002-03-26 20:17:02 +01:00
|
|
|
2,
|
1998-08-19 04:04:17 +02:00
|
|
|
{
|
|
|
|
Anum_pg_class_relname,
|
2002-03-26 20:17:02 +01:00
|
|
|
Anum_pg_class_relnamespace,
|
1997-09-07 07:04:48 +02:00
|
|
|
0,
|
1998-08-19 04:04:17 +02:00
|
|
|
0
|
2001-03-22 05:01:46 +01:00
|
|
|
}},
|
1997-09-07 07:04:48 +02:00
|
|
|
{RelationRelationName, /* RELOID */
|
2001-03-22 05:01:46 +01:00
|
|
|
ClassOidIndex,
|
2001-06-18 05:35:07 +02:00
|
|
|
ObjectIdAttributeNumber,
|
1997-09-07 07:04:48 +02:00
|
|
|
1,
|
1998-08-19 04:04:17 +02:00
|
|
|
{
|
|
|
|
ObjectIdAttributeNumber,
|
1997-09-07 07:04:48 +02:00
|
|
|
0,
|
|
|
|
0,
|
1998-08-19 04:04:17 +02:00
|
|
|
0
|
2001-03-22 05:01:46 +01:00
|
|
|
}},
|
2002-04-18 22:01:11 +02:00
|
|
|
{RewriteRelationName, /* RULERELNAME */
|
|
|
|
RewriteRelRulenameIndex,
|
2001-06-18 05:35:07 +02:00
|
|
|
Anum_pg_rewrite_ev_class,
|
2002-04-18 22:01:11 +02:00
|
|
|
2,
|
1998-08-19 04:04:17 +02:00
|
|
|
{
|
2002-04-18 22:01:11 +02:00
|
|
|
Anum_pg_rewrite_ev_class,
|
1999-11-22 18:56:41 +01:00
|
|
|
Anum_pg_rewrite_rulename,
|
1997-09-07 07:04:48 +02:00
|
|
|
0,
|
1998-08-19 04:04:17 +02:00
|
|
|
0
|
2001-03-22 05:01:46 +01:00
|
|
|
}},
|
1999-11-24 17:52:50 +01:00
|
|
|
{ShadowRelationName, /* SHADOWNAME */
|
2001-03-22 05:01:46 +01:00
|
|
|
ShadowNameIndex,
|
2001-06-18 05:35:07 +02:00
|
|
|
0,
|
1997-09-07 07:04:48 +02:00
|
|
|
1,
|
1998-08-19 04:04:17 +02:00
|
|
|
{
|
1999-11-24 17:52:50 +01:00
|
|
|
Anum_pg_shadow_usename,
|
1997-09-07 07:04:48 +02:00
|
|
|
0,
|
|
|
|
0,
|
1998-08-19 04:04:17 +02:00
|
|
|
0
|
2001-03-22 05:01:46 +01:00
|
|
|
}},
|
1999-11-24 17:52:50 +01:00
|
|
|
{ShadowRelationName, /* SHADOWSYSID */
|
2001-03-22 05:01:46 +01:00
|
|
|
ShadowSysidIndex,
|
2001-06-18 05:35:07 +02:00
|
|
|
0,
|
1997-09-07 07:04:48 +02:00
|
|
|
1,
|
1998-08-19 04:04:17 +02:00
|
|
|
{
|
1999-11-24 17:52:50 +01:00
|
|
|
Anum_pg_shadow_usesysid,
|
1997-09-07 07:04:48 +02:00
|
|
|
0,
|
|
|
|
0,
|
1998-08-19 04:04:17 +02:00
|
|
|
0
|
2001-03-22 05:01:46 +01:00
|
|
|
}},
|
2001-05-07 02:43:27 +02:00
|
|
|
{StatisticRelationName, /* STATRELATT */
|
2001-03-22 05:01:46 +01:00
|
|
|
StatisticRelidAttnumIndex,
|
2001-06-18 05:35:07 +02:00
|
|
|
Anum_pg_statistic_starelid,
|
2000-01-24 03:12:58 +01:00
|
|
|
2,
|
1999-11-24 17:52:50 +01:00
|
|
|
{
|
|
|
|
Anum_pg_statistic_starelid,
|
|
|
|
Anum_pg_statistic_staattnum,
|
2000-01-24 03:12:58 +01:00
|
|
|
0,
|
1999-11-24 17:52:50 +01:00
|
|
|
0
|
2001-03-22 05:01:46 +01:00
|
|
|
}},
|
2002-03-29 20:06:29 +01:00
|
|
|
{TypeRelationName, /* TYPENAMENSP */
|
|
|
|
TypeNameNspIndex,
|
2001-06-18 05:35:07 +02:00
|
|
|
Anum_pg_type_typrelid,
|
2002-03-29 20:06:29 +01:00
|
|
|
2,
|
1998-08-19 04:04:17 +02:00
|
|
|
{
|
1999-11-24 17:52:50 +01:00
|
|
|
Anum_pg_type_typname,
|
2002-03-29 20:06:29 +01:00
|
|
|
Anum_pg_type_typnamespace,
|
1997-09-07 07:04:48 +02:00
|
|
|
0,
|
1998-08-19 04:04:17 +02:00
|
|
|
0
|
2001-03-22 05:01:46 +01:00
|
|
|
}},
|
1999-11-24 17:52:50 +01:00
|
|
|
{TypeRelationName, /* TYPEOID */
|
2001-03-22 05:01:46 +01:00
|
|
|
TypeOidIndex,
|
2001-06-18 05:35:07 +02:00
|
|
|
Anum_pg_type_typrelid,
|
1997-09-07 07:04:48 +02:00
|
|
|
1,
|
1998-08-19 04:04:17 +02:00
|
|
|
{
|
1999-11-24 17:52:50 +01:00
|
|
|
ObjectIdAttributeNumber,
|
1997-09-07 07:04:48 +02:00
|
|
|
0,
|
|
|
|
0,
|
1998-08-19 04:04:17 +02:00
|
|
|
0
|
2001-03-22 05:01:46 +01:00
|
|
|
}}
|
1996-07-09 08:22:35 +02:00
|
|
|
};
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2003-09-24 20:54:02 +02:00
|
|
|
static CatCache *SysCache[lengthof(cacheinfo)];
|
2001-03-22 05:01:46 +01:00
|
|
|
static int SysCacheSize = lengthof(cacheinfo);
|
2000-04-12 19:17:23 +02:00
|
|
|
static bool CacheInitialized = false;
|
2000-06-17 06:56:39 +02:00
|
|
|
|
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
/*
|
2000-11-16 23:30:52 +01:00
|
|
|
* InitCatalogCache - initialize the caches
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
2000-11-16 23:30:52 +01:00
|
|
|
* Note that no database access is done here; we only allocate memory
|
2001-03-22 05:01:46 +01:00
|
|
|
* and initialize the cache structure. Interrogation of the database
|
2002-02-19 21:11:20 +01:00
|
|
|
* to complete initialization of a cache happens upon first use
|
2000-11-16 23:30:52 +01:00
|
|
|
* of that cache.
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
|
|
|
void
|
2000-11-16 23:30:52 +01:00
|
|
|
InitCatalogCache(void)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
2000-11-16 23:30:52 +01:00
|
|
|
int cacheId;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
2000-11-16 23:30:52 +01:00
|
|
|
Assert(!CacheInitialized);
|
2000-06-17 06:56:39 +02:00
|
|
|
|
2000-11-16 23:30:52 +01:00
|
|
|
MemSet((char *) SysCache, 0, sizeof(SysCache));
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2000-11-16 23:30:52 +01:00
|
|
|
for (cacheId = 0; cacheId < SysCacheSize; cacheId++)
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
2000-11-16 23:30:52 +01:00
|
|
|
SysCache[cacheId] = InitCatCache(cacheId,
|
|
|
|
cacheinfo[cacheId].name,
|
|
|
|
cacheinfo[cacheId].indname,
|
2001-06-18 05:35:07 +02:00
|
|
|
cacheinfo[cacheId].reloidattr,
|
2000-11-16 23:30:52 +01:00
|
|
|
cacheinfo[cacheId].nkeys,
|
|
|
|
cacheinfo[cacheId].key);
|
|
|
|
if (!PointerIsValid(SysCache[cacheId]))
|
2003-07-25 22:18:01 +02:00
|
|
|
elog(ERROR, "could not initialize cache %s (%d)",
|
2000-11-16 23:30:52 +01:00
|
|
|
cacheinfo[cacheId].name, cacheId);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
2000-02-18 10:30:20 +01:00
|
|
|
CacheInitialized = true;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
1998-09-01 06:40:42 +02:00
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
|
2002-02-19 21:11:20 +01:00
|
|
|
/*
|
|
|
|
* InitCatalogCachePhase2 - finish initializing the caches
|
|
|
|
*
|
|
|
|
* Finish initializing all the caches, including necessary database
|
|
|
|
* access.
|
|
|
|
*
|
|
|
|
* This is *not* essential; normally we allow syscaches to be initialized
|
|
|
|
* on first use. However, it is useful as a mechanism to preload the
|
|
|
|
* relcache with entries for the most-commonly-used system catalogs.
|
|
|
|
* Therefore, we invoke this routine when we need to write a new relcache
|
|
|
|
* init file.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
InitCatalogCachePhase2(void)
|
|
|
|
{
|
|
|
|
int cacheId;
|
|
|
|
|
|
|
|
Assert(CacheInitialized);
|
|
|
|
|
|
|
|
for (cacheId = 0; cacheId < SysCacheSize; cacheId++)
|
|
|
|
InitCatCachePhase2(SysCache[cacheId]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
/*
|
2000-11-16 23:30:52 +01:00
|
|
|
* SearchSysCache
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
2000-11-16 23:30:52 +01:00
|
|
|
* A layer on top of SearchCatCache that does the initialization and
|
1998-08-19 04:04:17 +02:00
|
|
|
* key-setting for you.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
1998-08-19 04:04:17 +02:00
|
|
|
* Returns the cache copy of the tuple if one is found, NULL if not.
|
2000-11-16 23:30:52 +01:00
|
|
|
* The tuple is the 'cache' copy and must NOT be modified!
|
2000-06-06 19:02:38 +02:00
|
|
|
*
|
2000-11-16 23:30:52 +01:00
|
|
|
* When the caller is done using the tuple, call ReleaseSysCache()
|
|
|
|
* to release the reference count grabbed by SearchSysCache(). If this
|
|
|
|
* is not done, the tuple will remain locked in cache until end of
|
|
|
|
* transaction, which is tolerable but not desirable.
|
2000-06-17 06:56:39 +02:00
|
|
|
*
|
2000-11-16 23:30:52 +01:00
|
|
|
* CAUTION: The tuple that is returned must NOT be freed by the caller!
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
|
|
|
HeapTuple
|
2000-11-16 23:30:52 +01:00
|
|
|
SearchSysCache(int cacheId,
|
|
|
|
Datum key1,
|
|
|
|
Datum key2,
|
|
|
|
Datum key3,
|
|
|
|
Datum key4)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
2002-03-31 08:26:32 +02:00
|
|
|
if (cacheId < 0 || cacheId >= SysCacheSize ||
|
2002-09-04 22:31:48 +02:00
|
|
|
!PointerIsValid(SysCache[cacheId]))
|
2003-07-25 22:18:01 +02:00
|
|
|
elog(ERROR, "invalid cache id: %d", cacheId);
|
2000-01-24 03:12:58 +01:00
|
|
|
|
2000-11-16 23:30:52 +01:00
|
|
|
return SearchCatCache(SysCache[cacheId], key1, key2, key3, key4);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
2000-11-16 23:30:52 +01:00
|
|
|
/*
|
|
|
|
* ReleaseSysCache
|
|
|
|
* Release previously grabbed reference count on a tuple
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ReleaseSysCache(HeapTuple tuple)
|
|
|
|
{
|
|
|
|
ReleaseCatCache(tuple);
|
|
|
|
}
|
1996-07-09 08:22:35 +02:00
|
|
|
|
2000-06-17 06:56:39 +02:00
|
|
|
/*
|
2000-11-16 23:30:52 +01:00
|
|
|
* SearchSysCacheCopy
|
2000-06-17 06:56:39 +02:00
|
|
|
*
|
2000-11-16 23:30:52 +01:00
|
|
|
* A convenience routine that does SearchSysCache and (if successful)
|
|
|
|
* returns a modifiable copy of the syscache entry. The original
|
|
|
|
* syscache entry is released before returning. The caller should
|
|
|
|
* heap_freetuple() the result when done with it.
|
2000-06-17 06:56:39 +02:00
|
|
|
*/
|
|
|
|
HeapTuple
|
2000-11-16 23:30:52 +01:00
|
|
|
SearchSysCacheCopy(int cacheId,
|
|
|
|
Datum key1,
|
|
|
|
Datum key2,
|
|
|
|
Datum key3,
|
|
|
|
Datum key4)
|
2000-06-17 06:56:39 +02:00
|
|
|
{
|
2000-11-16 23:30:52 +01:00
|
|
|
HeapTuple tuple,
|
|
|
|
newtuple;
|
|
|
|
|
|
|
|
tuple = SearchSysCache(cacheId, key1, key2, key3, key4);
|
|
|
|
if (!HeapTupleIsValid(tuple))
|
|
|
|
return tuple;
|
|
|
|
newtuple = heap_copytuple(tuple);
|
|
|
|
ReleaseSysCache(tuple);
|
|
|
|
return newtuple;
|
2000-06-17 06:56:39 +02:00
|
|
|
}
|
|
|
|
|
2001-08-10 20:57:42 +02:00
|
|
|
/*
|
|
|
|
* SearchSysCacheExists
|
|
|
|
*
|
|
|
|
* A convenience routine that just probes to see if a tuple can be found.
|
|
|
|
* No lock is retained on the syscache entry.
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
SearchSysCacheExists(int cacheId,
|
|
|
|
Datum key1,
|
|
|
|
Datum key2,
|
|
|
|
Datum key3,
|
|
|
|
Datum key4)
|
|
|
|
{
|
|
|
|
HeapTuple tuple;
|
|
|
|
|
|
|
|
tuple = SearchSysCache(cacheId, key1, key2, key3, key4);
|
|
|
|
if (!HeapTupleIsValid(tuple))
|
|
|
|
return false;
|
|
|
|
ReleaseSysCache(tuple);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2000-11-16 23:30:52 +01:00
|
|
|
/*
|
|
|
|
* GetSysCacheOid
|
|
|
|
*
|
|
|
|
* A convenience routine that does SearchSysCache and returns the OID
|
|
|
|
* of the found tuple, or InvalidOid if no tuple could be found.
|
|
|
|
* No lock is retained on the syscache entry.
|
|
|
|
*/
|
|
|
|
Oid
|
|
|
|
GetSysCacheOid(int cacheId,
|
|
|
|
Datum key1,
|
|
|
|
Datum key2,
|
|
|
|
Datum key3,
|
|
|
|
Datum key4)
|
|
|
|
{
|
|
|
|
HeapTuple tuple;
|
|
|
|
Oid result;
|
|
|
|
|
|
|
|
tuple = SearchSysCache(cacheId, key1, key2, key3, key4);
|
|
|
|
if (!HeapTupleIsValid(tuple))
|
|
|
|
return InvalidOid;
|
2002-07-20 07:16:59 +02:00
|
|
|
result = HeapTupleGetOid(tuple);
|
2000-11-16 23:30:52 +01:00
|
|
|
ReleaseSysCache(tuple);
|
|
|
|
return result;
|
|
|
|
}
|
2000-06-17 06:56:39 +02:00
|
|
|
|
2002-08-02 20:15:10 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* SearchSysCacheAttName
|
|
|
|
*
|
|
|
|
* This routine is equivalent to SearchSysCache on the ATTNAME cache,
|
|
|
|
* except that it will return NULL if the found attribute is marked
|
|
|
|
* attisdropped. This is convenient for callers that want to act as
|
|
|
|
* though dropped attributes don't exist.
|
|
|
|
*/
|
|
|
|
HeapTuple
|
|
|
|
SearchSysCacheAttName(Oid relid, const char *attname)
|
|
|
|
{
|
|
|
|
HeapTuple tuple;
|
|
|
|
|
|
|
|
tuple = SearchSysCache(ATTNAME,
|
|
|
|
ObjectIdGetDatum(relid),
|
|
|
|
CStringGetDatum(attname),
|
|
|
|
0, 0);
|
|
|
|
if (!HeapTupleIsValid(tuple))
|
|
|
|
return NULL;
|
|
|
|
if (((Form_pg_attribute) GETSTRUCT(tuple))->attisdropped)
|
|
|
|
{
|
|
|
|
ReleaseSysCache(tuple);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return tuple;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* SearchSysCacheCopyAttName
|
|
|
|
*
|
|
|
|
* As above, an attisdropped-aware version of SearchSysCacheCopy.
|
|
|
|
*/
|
|
|
|
HeapTuple
|
|
|
|
SearchSysCacheCopyAttName(Oid relid, const char *attname)
|
|
|
|
{
|
|
|
|
HeapTuple tuple,
|
|
|
|
newtuple;
|
|
|
|
|
|
|
|
tuple = SearchSysCacheAttName(relid, attname);
|
|
|
|
if (!HeapTupleIsValid(tuple))
|
|
|
|
return tuple;
|
|
|
|
newtuple = heap_copytuple(tuple);
|
|
|
|
ReleaseSysCache(tuple);
|
|
|
|
return newtuple;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* SearchSysCacheExistsAttName
|
|
|
|
*
|
|
|
|
* As above, an attisdropped-aware version of SearchSysCacheExists.
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
SearchSysCacheExistsAttName(Oid relid, const char *attname)
|
|
|
|
{
|
|
|
|
HeapTuple tuple;
|
|
|
|
|
|
|
|
tuple = SearchSysCacheAttName(relid, attname);
|
|
|
|
if (!HeapTupleIsValid(tuple))
|
|
|
|
return false;
|
|
|
|
ReleaseSysCache(tuple);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
/*
|
2000-01-23 04:43:24 +01:00
|
|
|
* SysCacheGetAttr
|
|
|
|
*
|
2000-11-16 23:30:52 +01:00
|
|
|
* Given a tuple previously fetched by SearchSysCache(),
|
|
|
|
* extract a specific attribute.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
2000-01-23 04:43:24 +01:00
|
|
|
* This is equivalent to using heap_getattr() on a tuple fetched
|
2000-04-12 19:17:23 +02:00
|
|
|
* from a non-cached relation. Usually, this is only used for attributes
|
2000-01-23 04:43:24 +01:00
|
|
|
* that could be NULL or variable length; the fixed-size attributes in
|
|
|
|
* a system table are accessed just by mapping the tuple onto the C struct
|
|
|
|
* declarations from include/catalog/.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
2000-01-23 04:43:24 +01:00
|
|
|
* As with heap_getattr(), if the attribute is of a pass-by-reference type
|
|
|
|
* then a pointer into the tuple data area is returned --- the caller must
|
|
|
|
* not modify or pfree the datum!
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
2000-01-23 04:43:24 +01:00
|
|
|
Datum
|
|
|
|
SysCacheGetAttr(int cacheId, HeapTuple tup,
|
|
|
|
AttrNumber attributeNumber,
|
2000-06-17 06:56:39 +02:00
|
|
|
bool *isNull)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1999-09-18 21:08:25 +02:00
|
|
|
/*
|
2000-04-12 19:17:23 +02:00
|
|
|
* We just need to get the TupleDesc out of the cache entry, and then
|
|
|
|
* we can apply heap_getattr(). We expect that the cache control data
|
2001-03-22 05:01:46 +01:00
|
|
|
* is currently valid --- if the caller recently fetched the tuple,
|
|
|
|
* then it should be.
|
1999-09-18 21:08:25 +02:00
|
|
|
*/
|
2000-01-23 04:43:24 +01:00
|
|
|
if (cacheId < 0 || cacheId >= SysCacheSize)
|
2003-07-25 22:18:01 +02:00
|
|
|
elog(ERROR, "invalid cache id: %d", cacheId);
|
2000-04-12 19:17:23 +02:00
|
|
|
if (!PointerIsValid(SysCache[cacheId]) ||
|
|
|
|
!PointerIsValid(SysCache[cacheId]->cc_tupdesc))
|
2003-07-25 22:18:01 +02:00
|
|
|
elog(ERROR, "missing cache data for cache id %d", cacheId);
|
2000-01-23 04:43:24 +01:00
|
|
|
|
|
|
|
return heap_getattr(tup, attributeNumber,
|
|
|
|
SysCache[cacheId]->cc_tupdesc,
|
2000-06-17 06:56:39 +02:00
|
|
|
isNull);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
2002-04-06 08:59:25 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* List-search interface
|
|
|
|
*/
|
|
|
|
struct catclist *
|
|
|
|
SearchSysCacheList(int cacheId, int nkeys,
|
|
|
|
Datum key1, Datum key2, Datum key3, Datum key4)
|
|
|
|
{
|
|
|
|
if (cacheId < 0 || cacheId >= SysCacheSize ||
|
2002-09-04 22:31:48 +02:00
|
|
|
!PointerIsValid(SysCache[cacheId]))
|
2003-07-25 22:18:01 +02:00
|
|
|
elog(ERROR, "invalid cache id: %d", cacheId);
|
2002-04-06 08:59:25 +02:00
|
|
|
|
|
|
|
return SearchCatCacheList(SysCache[cacheId], nkeys,
|
|
|
|
key1, key2, key3, key4);
|
|
|
|
}
|