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
|
|
|
*
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
|
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
2000-11-10 01:33:12 +01:00
|
|
|
* $Header: /cvsroot/pgsql/src/backend/utils/cache/syscache.c,v 1.56 2000/11/10 00:33:10 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"
|
|
|
|
#include "catalog/pg_group.h"
|
|
|
|
#include "catalog/pg_index.h"
|
|
|
|
#include "catalog/pg_inherits.h"
|
|
|
|
#include "catalog/pg_language.h"
|
1999-07-16 07:23:30 +02:00
|
|
|
#include "catalog/pg_listener.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"
|
1999-09-05 00:00:30 +02:00
|
|
|
#include "utils/temprel.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
|
2000-11-10 01:33:12 +01:00
|
|
|
name, index name, number of keys, and key attribute numbers.
|
1999-11-22 18:56:41 +01:00
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
In include/catalog/indexing.h, add a define for the number of indexes
|
2000-06-17 06:56:39 +02:00
|
|
|
on the relation, add define(s) for the index name(s), add an extern
|
2000-11-10 01:33:12 +01:00
|
|
|
array to hold the index names, and use DECLARE_UNIQUE_INDEX to define
|
|
|
|
the index. Cache lookups return only one row, so the index should be
|
|
|
|
unique in most cases.
|
1999-11-22 18:56:41 +01:00
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
In backend/catalog/indexing.c, initialize the relation array with
|
2000-11-10 01:33:12 +01:00
|
|
|
the index names for the relation.
|
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
|
1999-11-24 01:58:48 +01:00
|
|
|
heap_update calls, include code to do a CatalogIndexInsert() to update
|
1999-11-22 18:56:41 +01:00
|
|
|
the system indexes. 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
|
|
|
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2000-06-17 06:56:39 +02:00
|
|
|
/* ----------------
|
|
|
|
* struct cachedesc: information defining a single syscache
|
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
struct cachedesc
|
|
|
|
{
|
|
|
|
char *name; /* name of the relation being cached */
|
2000-11-10 01:33:12 +01:00
|
|
|
char *indname; /* name of index relation for this cache */
|
2000-06-17 06:56:39 +02:00
|
|
|
int nkeys; /* # of keys needed for cache lookup */
|
|
|
|
int key[4]; /* attribute numbers of key attrs */
|
|
|
|
};
|
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
static struct cachedesc cacheinfo[] = {
|
1999-11-22 18:56:41 +01:00
|
|
|
{AggregateRelationName, /* AGGNAME */
|
2000-11-10 01:33:12 +01:00
|
|
|
AggregateNameTypeIndex,
|
1999-11-22 18:56:41 +01:00
|
|
|
2,
|
|
|
|
{
|
|
|
|
Anum_pg_aggregate_aggname,
|
|
|
|
Anum_pg_aggregate_aggbasetype,
|
|
|
|
0,
|
|
|
|
0
|
2000-11-10 01:33:12 +01:00
|
|
|
}},
|
1999-11-22 18:56:41 +01:00
|
|
|
{AccessMethodRelationName, /* AMNAME */
|
2000-11-10 01:33:12 +01:00
|
|
|
AmNameIndex,
|
1999-11-22 18:56:41 +01:00
|
|
|
1,
|
|
|
|
{
|
|
|
|
Anum_pg_am_amname,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0
|
2000-11-10 01:33:12 +01:00
|
|
|
}},
|
1997-09-07 07:04:48 +02:00
|
|
|
{AccessMethodOperatorRelationName, /* AMOPOPID */
|
2000-11-10 01:33:12 +01:00
|
|
|
AccessMethodOpidIndex,
|
1997-09-07 07:04:48 +02:00
|
|
|
3,
|
1998-08-19 04:04:17 +02:00
|
|
|
{
|
|
|
|
Anum_pg_amop_amopclaid,
|
1997-09-07 07:04:48 +02:00
|
|
|
Anum_pg_amop_amopopr,
|
|
|
|
Anum_pg_amop_amopid,
|
1998-08-19 04:04:17 +02:00
|
|
|
0
|
2000-11-10 01:33:12 +01:00
|
|
|
}},
|
1997-09-07 07:04:48 +02:00
|
|
|
{AccessMethodOperatorRelationName, /* AMOPSTRATEGY */
|
2000-11-10 01:33:12 +01:00
|
|
|
AccessMethodStrategyIndex,
|
1997-09-07 07:04:48 +02:00
|
|
|
3,
|
1998-08-19 04:04:17 +02:00
|
|
|
{
|
|
|
|
Anum_pg_amop_amopid,
|
1997-09-07 07:04:48 +02:00
|
|
|
Anum_pg_amop_amopclaid,
|
|
|
|
Anum_pg_amop_amopstrategy,
|
1998-08-19 04:04:17 +02:00
|
|
|
0
|
2000-11-10 01:33:12 +01:00
|
|
|
}},
|
1997-09-07 07:04:48 +02:00
|
|
|
{AttributeRelationName, /* ATTNAME */
|
2000-11-10 01:33:12 +01:00
|
|
|
AttributeRelidNameIndex,
|
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
|
2000-11-10 01:33:12 +01:00
|
|
|
}},
|
1997-09-07 07:04:48 +02:00
|
|
|
{AttributeRelationName, /* ATTNUM */
|
2000-11-10 01:33:12 +01:00
|
|
|
AttributeRelidNumIndex,
|
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
|
2000-11-10 01:33:12 +01:00
|
|
|
}},
|
1999-11-22 18:56:41 +01:00
|
|
|
{OperatorClassRelationName, /* CLADEFTYPE */
|
2000-11-10 01:33:12 +01:00
|
|
|
OpclassDeftypeIndex,
|
1999-11-22 18:56:41 +01:00
|
|
|
1,
|
|
|
|
{
|
|
|
|
Anum_pg_opclass_opcdeftype,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0
|
2000-11-10 01:33:12 +01:00
|
|
|
}},
|
1999-11-22 18:56:41 +01:00
|
|
|
{OperatorClassRelationName, /* CLANAME */
|
2000-11-10 01:33:12 +01:00
|
|
|
OpclassNameIndex,
|
1999-11-22 18:56:41 +01:00
|
|
|
1,
|
|
|
|
{
|
|
|
|
Anum_pg_opclass_opcname,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0
|
2000-11-10 01:33:12 +01:00
|
|
|
}},
|
1999-11-22 18:56:41 +01:00
|
|
|
{GroupRelationName, /* GRONAME */
|
2000-11-10 01:33:12 +01:00
|
|
|
GroupNameIndex,
|
1999-11-22 18:56:41 +01:00
|
|
|
1,
|
|
|
|
{
|
|
|
|
Anum_pg_group_groname,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0
|
2000-11-10 01:33:12 +01:00
|
|
|
}},
|
1999-11-22 18:56:41 +01:00
|
|
|
{GroupRelationName, /* GROSYSID */
|
2000-11-10 01:33:12 +01:00
|
|
|
GroupSysidIndex,
|
1999-11-22 18:56:41 +01:00
|
|
|
1,
|
|
|
|
{
|
|
|
|
Anum_pg_group_grosysid,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0
|
2000-11-10 01:33:12 +01:00
|
|
|
}},
|
1997-09-07 07:04:48 +02:00
|
|
|
{IndexRelationName, /* INDEXRELID */
|
2000-11-10 01:33:12 +01:00
|
|
|
IndexRelidIndex,
|
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
|
2000-11-10 01:33:12 +01:00
|
|
|
}},
|
1999-11-22 18:56:41 +01:00
|
|
|
{InheritsRelationName, /* INHRELID */
|
2000-11-10 01:33:12 +01:00
|
|
|
InheritsRelidSeqnoIndex,
|
1999-11-22 18:56:41 +01:00
|
|
|
2,
|
|
|
|
{
|
|
|
|
Anum_pg_inherits_inhrelid,
|
|
|
|
Anum_pg_inherits_inhseqno,
|
|
|
|
0,
|
|
|
|
0
|
2000-11-10 01:33:12 +01:00
|
|
|
}},
|
1999-11-22 18:56:41 +01:00
|
|
|
{LanguageRelationName, /* LANGNAME */
|
2000-11-10 01:33:12 +01:00
|
|
|
LanguageNameIndex,
|
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
|
2000-11-10 01:33:12 +01:00
|
|
|
}},
|
1999-11-22 18:56:41 +01:00
|
|
|
{LanguageRelationName, /* LANGOID */
|
2000-11-10 01:33:12 +01:00
|
|
|
LanguageOidIndex,
|
1999-11-22 18:56:41 +01:00
|
|
|
1,
|
|
|
|
{
|
|
|
|
ObjectIdAttributeNumber,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0
|
2000-11-10 01:33:12 +01:00
|
|
|
}},
|
1999-11-22 18:56:41 +01:00
|
|
|
{ListenerRelationName, /* LISTENREL */
|
2000-11-10 01:33:12 +01:00
|
|
|
ListenerPidRelnameIndex,
|
1999-11-22 18:56:41 +01:00
|
|
|
2,
|
|
|
|
{
|
|
|
|
Anum_pg_listener_pid,
|
2000-06-07 06:09:44 +02:00
|
|
|
Anum_pg_listener_relname,
|
1999-11-22 18:56:41 +01:00
|
|
|
0,
|
|
|
|
0
|
2000-11-10 01:33:12 +01:00
|
|
|
}},
|
1999-11-22 18:56:41 +01:00
|
|
|
{OperatorRelationName, /* OPERNAME */
|
2000-11-10 01:33:12 +01:00
|
|
|
OperatorNameIndex,
|
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,
|
1998-08-19 04:04:17 +02:00
|
|
|
Anum_pg_operator_oprkind
|
2000-11-10 01:33:12 +01:00
|
|
|
}},
|
1999-11-22 18:56:41 +01:00
|
|
|
{OperatorRelationName, /* OPEROID */
|
2000-11-10 01:33:12 +01:00
|
|
|
OperatorOidIndex,
|
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
|
2000-11-10 01:33:12 +01:00
|
|
|
}},
|
1999-11-22 18:56:41 +01:00
|
|
|
{ProcedureRelationName, /* PROCNAME */
|
2000-11-10 01:33:12 +01:00
|
|
|
ProcedureNameIndex,
|
1997-09-07 07:04:48 +02:00
|
|
|
3,
|
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,
|
1998-08-19 04:04:17 +02:00
|
|
|
0
|
2000-11-10 01:33:12 +01:00
|
|
|
}},
|
1999-11-22 18:56:41 +01:00
|
|
|
{ProcedureRelationName, /* PROCOID */
|
2000-11-10 01:33:12 +01:00
|
|
|
ProcedureOidIndex,
|
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
|
2000-11-10 01:33:12 +01:00
|
|
|
}},
|
1997-09-07 07:04:48 +02:00
|
|
|
{RelationRelationName, /* RELNAME */
|
2000-11-10 01:33:12 +01:00
|
|
|
ClassNameIndex,
|
1997-09-07 07:04:48 +02:00
|
|
|
1,
|
1998-08-19 04:04:17 +02:00
|
|
|
{
|
|
|
|
Anum_pg_class_relname,
|
1997-09-07 07:04:48 +02:00
|
|
|
0,
|
|
|
|
0,
|
1998-08-19 04:04:17 +02:00
|
|
|
0
|
2000-11-10 01:33:12 +01:00
|
|
|
}},
|
1997-09-07 07:04:48 +02:00
|
|
|
{RelationRelationName, /* RELOID */
|
2000-11-10 01:33:12 +01:00
|
|
|
ClassOidIndex,
|
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
|
2000-11-10 01:33:12 +01:00
|
|
|
}},
|
1999-11-22 18:56:41 +01:00
|
|
|
{RewriteRelationName, /* REWRITENAME */
|
2000-11-10 01:33:12 +01:00
|
|
|
RewriteRulenameIndex,
|
1997-09-07 07:04:48 +02:00
|
|
|
1,
|
1998-08-19 04:04:17 +02:00
|
|
|
{
|
1999-11-22 18:56:41 +01:00
|
|
|
Anum_pg_rewrite_rulename,
|
1997-09-07 07:04:48 +02:00
|
|
|
0,
|
|
|
|
0,
|
1998-08-19 04:04:17 +02:00
|
|
|
0
|
2000-11-10 01:33:12 +01:00
|
|
|
}},
|
1999-11-22 18:56:41 +01:00
|
|
|
{RewriteRelationName, /* RULEOID */
|
2000-11-10 01:33:12 +01:00
|
|
|
RewriteOidIndex,
|
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
|
2000-11-10 01:33:12 +01:00
|
|
|
}},
|
1999-11-24 17:52:50 +01:00
|
|
|
{ShadowRelationName, /* SHADOWNAME */
|
2000-11-10 01:33:12 +01:00
|
|
|
ShadowNameIndex,
|
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
|
2000-11-10 01:33:12 +01:00
|
|
|
}},
|
1999-11-24 17:52:50 +01:00
|
|
|
{ShadowRelationName, /* SHADOWSYSID */
|
2000-11-10 01:33:12 +01:00
|
|
|
ShadowSysidIndex,
|
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
|
2000-11-10 01:33:12 +01:00
|
|
|
}},
|
1999-11-24 17:52:50 +01:00
|
|
|
{StatisticRelationName, /* STATRELID */
|
2000-11-10 01:33:12 +01:00
|
|
|
StatisticRelidAttnumIndex,
|
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
|
2000-11-10 01:33:12 +01:00
|
|
|
}},
|
1999-11-24 17:52:50 +01:00
|
|
|
{TypeRelationName, /* TYPENAME */
|
2000-11-10 01:33:12 +01:00
|
|
|
TypeNameIndex,
|
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_type_typname,
|
1997-09-07 07:04:48 +02:00
|
|
|
0,
|
|
|
|
0,
|
1998-08-19 04:04:17 +02:00
|
|
|
0
|
2000-11-10 01:33:12 +01:00
|
|
|
}},
|
1999-11-24 17:52:50 +01:00
|
|
|
{TypeRelationName, /* TYPEOID */
|
2000-11-10 01:33:12 +01:00
|
|
|
TypeOidIndex,
|
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
|
2000-11-10 01:33:12 +01:00
|
|
|
}}
|
1996-07-09 08:22:35 +02:00
|
|
|
};
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2000-06-17 06:56:39 +02:00
|
|
|
static CatCache *SysCache[lengthof(cacheinfo)];
|
1997-09-08 04:41:22 +02:00
|
|
|
static int32 SysCacheSize = lengthof(cacheinfo);
|
2000-04-12 19:17:23 +02:00
|
|
|
static bool CacheInitialized = false;
|
2000-06-17 06:56:39 +02:00
|
|
|
|
|
|
|
|
|
|
|
bool
|
2000-04-12 19:17:23 +02:00
|
|
|
IsCacheInitialized(void)
|
2000-02-18 10:30:20 +01:00
|
|
|
{
|
|
|
|
return CacheInitialized;
|
|
|
|
}
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
/*
|
1999-02-14 00:22:53 +01:00
|
|
|
* zerocaches
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
1997-09-07 07:04:48 +02:00
|
|
|
* Make sure the SysCache structure is zero'd.
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
zerocaches()
|
|
|
|
{
|
2000-06-17 06:56:39 +02:00
|
|
|
MemSet((char *) SysCache, 0, SysCacheSize * sizeof(CatCache *));
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
2000-06-17 06:56:39 +02:00
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
/*
|
2000-06-17 06:56:39 +02:00
|
|
|
* InitCatalogCache - initialize the caches
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
InitCatalogCache()
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
int cacheId; /* XXX type */
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
if (!AMI_OVERRIDE)
|
|
|
|
{
|
|
|
|
for (cacheId = 0; cacheId < SysCacheSize; cacheId += 1)
|
|
|
|
{
|
2000-06-17 06:56:39 +02:00
|
|
|
Assert(!PointerIsValid(SysCache[cacheId]));
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2000-11-10 01:33:12 +01:00
|
|
|
SysCache[cacheId] = InitSysCache(cacheId,
|
|
|
|
cacheinfo[cacheId].name,
|
1999-05-25 18:15:34 +02:00
|
|
|
cacheinfo[cacheId].indname,
|
|
|
|
cacheinfo[cacheId].nkeys,
|
2000-11-10 01:33:12 +01:00
|
|
|
cacheinfo[cacheId].key);
|
2000-06-17 06:56:39 +02:00
|
|
|
if (!PointerIsValid(SysCache[cacheId]))
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
1998-01-07 22:07:04 +01:00
|
|
|
elog(ERROR,
|
2000-06-17 06:56:39 +02:00
|
|
|
"InitCatalogCache: Can't init cache %s (%d)",
|
1997-09-07 07:04:48 +02: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
|
|
|
|
|
|
|
/*
|
1999-02-14 00:22:53 +01:00
|
|
|
* SearchSysCacheTuple
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
1998-08-19 04:04:17 +02:00
|
|
|
* A layer on top of SearchSysCache that does the initialization and
|
|
|
|
* 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.
|
|
|
|
* The tuple is the 'cache' copy.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
2000-06-06 19:02:38 +02:00
|
|
|
* CAUTION: The tuple that is returned must NOT be freed by the caller!
|
|
|
|
*
|
|
|
|
* CAUTION: The returned tuple may be flushed from the cache during
|
|
|
|
* subsequent cache lookup operations, or by shared cache invalidation.
|
|
|
|
* Callers should not expect the pointer to remain valid for long.
|
2000-06-17 06:56:39 +02:00
|
|
|
*
|
|
|
|
* XXX we ought to have some kind of referencecount mechanism for
|
|
|
|
* cache entries, to ensure entries aren't deleted while in use.
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
|
|
|
HeapTuple
|
1998-02-26 05:46:47 +01:00
|
|
|
SearchSysCacheTuple(int cacheId,/* cache selection code */
|
1997-09-07 07:04:48 +02:00
|
|
|
Datum key1,
|
|
|
|
Datum key2,
|
|
|
|
Datum key3,
|
|
|
|
Datum key4)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1998-02-26 05:46:47 +01:00
|
|
|
HeapTuple tp;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
if (cacheId < 0 || cacheId >= SysCacheSize)
|
|
|
|
{
|
1998-01-07 22:07:04 +01:00
|
|
|
elog(ERROR, "SearchSysCacheTuple: Bad cache id %d", cacheId);
|
1998-09-01 05:29:17 +02:00
|
|
|
return (HeapTuple) NULL;
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
|
|
|
|
1998-06-15 21:30:31 +02:00
|
|
|
Assert(AMI_OVERRIDE || PointerIsValid(SysCache[cacheId]));
|
|
|
|
|
|
|
|
if (!PointerIsValid(SysCache[cacheId]))
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
2000-11-10 01:33:12 +01:00
|
|
|
SysCache[cacheId] = InitSysCache(cacheId,
|
|
|
|
cacheinfo[cacheId].name,
|
1999-05-25 18:15:34 +02:00
|
|
|
cacheinfo[cacheId].indname,
|
|
|
|
cacheinfo[cacheId].nkeys,
|
2000-11-10 01:33:12 +01:00
|
|
|
cacheinfo[cacheId].key);
|
1997-09-07 07:04:48 +02:00
|
|
|
if (!PointerIsValid(SysCache[cacheId]))
|
1998-06-15 21:30:31 +02:00
|
|
|
elog(ERROR,
|
1998-07-20 18:57:18 +02:00
|
|
|
"InitCatalogCache: Can't init cache %s(%d)",
|
1998-06-15 21:30:31 +02:00
|
|
|
cacheinfo[cacheId].name,
|
|
|
|
cacheId);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2000-06-20 03:41:22 +02:00
|
|
|
/*
|
|
|
|
* If someone tries to look up a relname, translate temp relation
|
|
|
|
* names to real names. Less obviously, apply the same translation
|
|
|
|
* to type names, so that the type tuple of a temp table will be found
|
|
|
|
* when sought. This is a kluge ... temp table substitution should be
|
|
|
|
* happening at a higher level ...
|
|
|
|
*/
|
|
|
|
if (cacheId == RELNAME || cacheId == TYPENAME)
|
1999-09-05 00:00:30 +02:00
|
|
|
{
|
2000-04-12 19:17:23 +02:00
|
|
|
char *nontemp_relname;
|
1999-09-05 00:00:30 +02:00
|
|
|
|
2000-06-20 03:41:22 +02:00
|
|
|
nontemp_relname = get_temp_rel_by_username(DatumGetCString(key1));
|
|
|
|
if (nontemp_relname != NULL)
|
|
|
|
key1 = CStringGetDatum(nontemp_relname);
|
1999-09-05 00:00:30 +02:00
|
|
|
}
|
2000-01-24 03:12:58 +01:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
tp = SearchSysCache(SysCache[cacheId], key1, key2, key3, key4);
|
|
|
|
if (!HeapTupleIsValid(tp))
|
|
|
|
{
|
1996-07-09 08:22:35 +02:00
|
|
|
#ifdef CACHEDEBUG
|
1997-09-07 07:04:48 +02:00
|
|
|
elog(DEBUG,
|
|
|
|
"SearchSysCacheTuple: Search %s(%d) %d %d %d %d failed",
|
1998-05-10 01:45:29 +02:00
|
|
|
cacheinfo[cacheId].name,
|
1997-09-07 07:04:48 +02:00
|
|
|
cacheId, key1, key2, key3, key4);
|
1996-07-09 08:22:35 +02:00
|
|
|
#endif
|
1998-09-01 05:29:17 +02:00
|
|
|
return (HeapTuple) NULL;
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
1998-09-01 05:29:17 +02:00
|
|
|
return tp;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-17 06:56:39 +02:00
|
|
|
/*
|
|
|
|
* SearchSysCacheTupleCopy
|
|
|
|
*
|
|
|
|
* This is like SearchSysCacheTuple, except it returns a palloc'd copy of
|
|
|
|
* the tuple. The caller should heap_freetuple() the returned copy when
|
|
|
|
* done with it. This routine should be used when the caller intends to
|
|
|
|
* continue to access the tuple for more than a very short period of time.
|
|
|
|
*/
|
|
|
|
HeapTuple
|
|
|
|
SearchSysCacheTupleCopy(int cacheId, /* cache selection code */
|
|
|
|
Datum key1,
|
|
|
|
Datum key2,
|
|
|
|
Datum key3,
|
|
|
|
Datum key4)
|
|
|
|
{
|
|
|
|
HeapTuple cachetup;
|
|
|
|
|
|
|
|
cachetup = SearchSysCacheTuple(cacheId, key1, key2, key3, key4);
|
|
|
|
if (PointerIsValid(cachetup))
|
|
|
|
return heap_copytuple(cachetup);
|
|
|
|
else
|
|
|
|
return cachetup; /* NULL */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
/*
|
2000-01-23 04:43:24 +01:00
|
|
|
* SysCacheGetAttr
|
|
|
|
*
|
|
|
|
* Given a tuple previously fetched by SearchSysCacheTuple() or
|
|
|
|
* SearchSysCacheTupleCopy(), 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
|
|
|
{
|
2000-04-12 19:17:23 +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
|
2000-06-17 06:56:39 +02:00
|
|
|
* is currently valid --- if the caller recently fetched the tuple, then
|
2000-04-12 19:17:23 +02:00
|
|
|
* it should be.
|
1999-09-18 21:08:25 +02:00
|
|
|
*/
|
2000-01-23 04:43:24 +01:00
|
|
|
if (cacheId < 0 || cacheId >= SysCacheSize)
|
|
|
|
elog(ERROR, "SysCacheGetAttr: Bad cache id %d", cacheId);
|
2000-04-12 19:17:23 +02:00
|
|
|
if (!PointerIsValid(SysCache[cacheId]) ||
|
|
|
|
!PointerIsValid(SysCache[cacheId]->cc_tupdesc))
|
2000-01-23 04:43:24 +01:00
|
|
|
elog(ERROR, "SysCacheGetAttr: missing cache data for id %d", cacheId);
|
|
|
|
|
|
|
|
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
|
|
|
}
|