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
|
|
|
*
|
|
|
|
* Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
1999-07-16 07:23:30 +02:00
|
|
|
* $Header: /cvsroot/pgsql/src/backend/utils/cache/syscache.c,v 1.30 1999/07/16 05:23:21 momjian 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
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
1999-07-16 07:23:30 +02:00
|
|
|
#include <string.h>
|
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"
|
|
|
|
#include "catalog/catname.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-07-16 07:23:30 +02:00
|
|
|
#include "catalog/pg_type.h"
|
|
|
|
#include "utils/catcache.h"
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
extern bool AMI_OVERRIDE; /* XXX style */
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
#include "utils/syscache.h"
|
|
|
|
#include "catalog/indexing.h"
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1998-02-26 05:46:47 +01:00
|
|
|
typedef HeapTuple (*ScanFunc) ();
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
/* ----------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* Warning: cacheinfo[] below is changed, then be sure and
|
|
|
|
* update the magic constants in syscache.h!
|
1996-07-09 08:22:35 +02:00
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
static struct cachedesc cacheinfo[] = {
|
1997-09-07 07:04:48 +02:00
|
|
|
{AccessMethodOperatorRelationName, /* AMOPOPID */
|
|
|
|
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
|
|
|
|
},
|
1997-09-07 07:04:48 +02:00
|
|
|
sizeof(FormData_pg_amop),
|
|
|
|
NULL,
|
|
|
|
(ScanFunc) NULL},
|
|
|
|
{AccessMethodOperatorRelationName, /* AMOPSTRATEGY */
|
|
|
|
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
|
|
|
|
},
|
1997-09-07 07:04:48 +02:00
|
|
|
sizeof(FormData_pg_amop),
|
|
|
|
NULL,
|
|
|
|
(ScanFunc) NULL},
|
|
|
|
{AttributeRelationName, /* ATTNAME */
|
|
|
|
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
|
|
|
|
},
|
1997-09-07 07:04:48 +02:00
|
|
|
ATTRIBUTE_TUPLE_SIZE,
|
|
|
|
AttributeNameIndex,
|
|
|
|
(ScanFunc) AttributeNameIndexScan},
|
|
|
|
{AttributeRelationName, /* ATTNUM */
|
|
|
|
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
|
|
|
|
},
|
1997-09-07 07:04:48 +02:00
|
|
|
ATTRIBUTE_TUPLE_SIZE,
|
|
|
|
AttributeNumIndex,
|
|
|
|
(ScanFunc) AttributeNumIndexScan},
|
|
|
|
{IndexRelationName, /* INDEXRELID */
|
|
|
|
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
|
|
|
|
},
|
1997-09-07 07:04:48 +02:00
|
|
|
offsetof(FormData_pg_index, indpred),
|
|
|
|
NULL,
|
|
|
|
NULL},
|
|
|
|
{LanguageRelationName, /* LANNAME */
|
|
|
|
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
|
|
|
|
},
|
1997-09-07 07:04:48 +02:00
|
|
|
offsetof(FormData_pg_language, lancompiler),
|
|
|
|
NULL,
|
|
|
|
NULL},
|
|
|
|
{OperatorRelationName, /* OPRNAME */
|
|
|
|
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
|
|
|
|
},
|
1997-09-07 07:04:48 +02:00
|
|
|
sizeof(FormData_pg_operator),
|
|
|
|
NULL,
|
|
|
|
NULL},
|
|
|
|
{OperatorRelationName, /* OPROID */
|
|
|
|
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
|
|
|
|
},
|
1997-09-07 07:04:48 +02:00
|
|
|
sizeof(FormData_pg_operator),
|
|
|
|
NULL,
|
|
|
|
(ScanFunc) NULL},
|
|
|
|
{ProcedureRelationName, /* PRONAME */
|
|
|
|
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
|
|
|
|
},
|
1997-09-07 07:04:48 +02:00
|
|
|
offsetof(FormData_pg_proc, prosrc),
|
|
|
|
ProcedureNameIndex,
|
|
|
|
(ScanFunc) ProcedureNameIndexScan},
|
|
|
|
{ProcedureRelationName, /* PROOID */
|
|
|
|
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
|
|
|
|
},
|
1997-09-07 07:04:48 +02:00
|
|
|
offsetof(FormData_pg_proc, prosrc),
|
|
|
|
ProcedureOidIndex,
|
|
|
|
(ScanFunc) ProcedureOidIndexScan},
|
|
|
|
{RelationRelationName, /* RELNAME */
|
|
|
|
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
|
|
|
|
},
|
1997-09-07 07:04:48 +02:00
|
|
|
CLASS_TUPLE_SIZE,
|
|
|
|
ClassNameIndex,
|
|
|
|
(ScanFunc) ClassNameIndexScan},
|
|
|
|
{RelationRelationName, /* RELOID */
|
|
|
|
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
|
|
|
|
},
|
1997-09-07 07:04:48 +02:00
|
|
|
CLASS_TUPLE_SIZE,
|
|
|
|
ClassOidIndex,
|
|
|
|
(ScanFunc) ClassOidIndexScan},
|
|
|
|
{TypeRelationName, /* TYPNAME */
|
|
|
|
1,
|
1998-08-19 04:04:17 +02:00
|
|
|
{
|
|
|
|
Anum_pg_type_typname,
|
1997-09-07 07:04:48 +02:00
|
|
|
0,
|
|
|
|
0,
|
1998-08-19 04:04:17 +02:00
|
|
|
0
|
|
|
|
},
|
1999-05-26 00:43:53 +02:00
|
|
|
offsetof(FormData_pg_type, typalign) +sizeof(char),
|
1997-09-07 07:04:48 +02:00
|
|
|
TypeNameIndex,
|
|
|
|
TypeNameIndexScan},
|
|
|
|
{TypeRelationName, /* TYPOID */
|
|
|
|
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
|
|
|
|
},
|
1998-09-01 05:29:17 +02:00
|
|
|
offsetof(FormData_pg_type, typalign) +sizeof(char),
|
1997-09-07 07:04:48 +02:00
|
|
|
TypeOidIndex,
|
|
|
|
TypeOidIndexScan},
|
|
|
|
{AccessMethodRelationName, /* AMNAME */
|
|
|
|
1,
|
1998-08-19 04:04:17 +02:00
|
|
|
{
|
|
|
|
Anum_pg_am_amname,
|
1997-09-07 07:04:48 +02:00
|
|
|
0,
|
|
|
|
0,
|
1998-08-19 04:04:17 +02:00
|
|
|
0
|
|
|
|
},
|
1997-09-07 07:04:48 +02:00
|
|
|
sizeof(FormData_pg_am),
|
|
|
|
NULL,
|
|
|
|
NULL},
|
|
|
|
{OperatorClassRelationName, /* CLANAME */
|
|
|
|
1,
|
1998-08-19 04:04:17 +02:00
|
|
|
{
|
|
|
|
Anum_pg_opclass_opcname,
|
1997-09-07 07:04:48 +02:00
|
|
|
0,
|
|
|
|
0,
|
1998-08-19 04:04:17 +02:00
|
|
|
0
|
|
|
|
},
|
1997-09-07 07:04:48 +02:00
|
|
|
sizeof(FormData_pg_opclass),
|
|
|
|
NULL,
|
|
|
|
NULL},
|
1998-09-01 06:40:42 +02:00
|
|
|
{IndexRelationName, /* INDRELIDKEY *//* never used */
|
1997-09-07 07:04:48 +02:00
|
|
|
2,
|
1998-08-19 04:04:17 +02:00
|
|
|
{
|
|
|
|
Anum_pg_index_indrelid,
|
1997-09-07 07:04:48 +02:00
|
|
|
Anum_pg_index_indkey,
|
|
|
|
0,
|
1998-08-19 04:04:17 +02:00
|
|
|
0
|
|
|
|
},
|
1997-09-07 07:04:48 +02:00
|
|
|
offsetof(FormData_pg_index, indpred),
|
|
|
|
NULL,
|
|
|
|
(ScanFunc) NULL},
|
|
|
|
{InheritsRelationName, /* INHRELID */
|
|
|
|
2,
|
1998-08-19 04:04:17 +02:00
|
|
|
{
|
|
|
|
Anum_pg_inherits_inhrel,
|
1997-09-07 07:04:48 +02:00
|
|
|
Anum_pg_inherits_inhseqno,
|
|
|
|
0,
|
1998-08-19 04:04:17 +02:00
|
|
|
0
|
|
|
|
},
|
1997-09-07 07:04:48 +02:00
|
|
|
sizeof(FormData_pg_inherits),
|
|
|
|
NULL,
|
|
|
|
(ScanFunc) NULL},
|
|
|
|
{RewriteRelationName, /* RULOID */
|
|
|
|
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
|
|
|
|
},
|
1997-09-07 07:04:48 +02:00
|
|
|
offsetof(FormData_pg_rewrite, ev_qual),
|
|
|
|
NULL,
|
|
|
|
(ScanFunc) NULL},
|
|
|
|
{AggregateRelationName, /* AGGNAME */
|
|
|
|
2,
|
1998-08-19 04:04:17 +02:00
|
|
|
{
|
|
|
|
Anum_pg_aggregate_aggname,
|
1997-09-07 07:04:48 +02:00
|
|
|
Anum_pg_aggregate_aggbasetype,
|
|
|
|
0,
|
1998-08-19 04:04:17 +02:00
|
|
|
0
|
|
|
|
},
|
1997-09-07 07:04:48 +02:00
|
|
|
offsetof(FormData_pg_aggregate, agginitval1),
|
|
|
|
NULL,
|
|
|
|
(ScanFunc) NULL},
|
|
|
|
{ListenerRelationName, /* LISTENREL */
|
|
|
|
2,
|
1998-08-19 04:04:17 +02:00
|
|
|
{
|
|
|
|
Anum_pg_listener_relname,
|
1997-09-07 07:04:48 +02:00
|
|
|
Anum_pg_listener_pid,
|
|
|
|
0,
|
1998-08-19 04:04:17 +02:00
|
|
|
0
|
|
|
|
},
|
1997-09-07 07:04:48 +02:00
|
|
|
sizeof(FormData_pg_listener),
|
|
|
|
NULL,
|
|
|
|
(ScanFunc) NULL},
|
1998-02-26 05:46:47 +01:00
|
|
|
{ShadowRelationName, /* USENAME */
|
1997-09-07 07:04:48 +02:00
|
|
|
1,
|
1998-08-19 04:04:17 +02:00
|
|
|
{
|
|
|
|
Anum_pg_shadow_usename,
|
1997-09-07 07:04:48 +02:00
|
|
|
0,
|
|
|
|
0,
|
1998-08-19 04:04:17 +02:00
|
|
|
0
|
|
|
|
},
|
1998-02-25 14:09:49 +01:00
|
|
|
sizeof(FormData_pg_shadow),
|
1997-09-07 07:04:48 +02:00
|
|
|
NULL,
|
|
|
|
(ScanFunc) NULL},
|
1998-02-26 05:46:47 +01:00
|
|
|
{ShadowRelationName, /* USESYSID */
|
1997-09-07 07:04:48 +02:00
|
|
|
1,
|
1998-08-19 04:04:17 +02:00
|
|
|
{
|
|
|
|
Anum_pg_shadow_usesysid,
|
1997-09-07 07:04:48 +02:00
|
|
|
0,
|
|
|
|
0,
|
1998-08-19 04:04:17 +02:00
|
|
|
0
|
|
|
|
},
|
1998-02-25 14:09:49 +01:00
|
|
|
sizeof(FormData_pg_shadow),
|
1997-09-07 07:04:48 +02:00
|
|
|
NULL,
|
|
|
|
(ScanFunc) NULL},
|
|
|
|
{GroupRelationName, /* GRONAME */
|
|
|
|
1,
|
1998-08-19 04:04:17 +02:00
|
|
|
{
|
|
|
|
Anum_pg_group_groname,
|
1997-09-07 07:04:48 +02:00
|
|
|
0,
|
|
|
|
0,
|
1998-08-19 04:04:17 +02:00
|
|
|
0
|
|
|
|
},
|
1997-09-07 07:04:48 +02:00
|
|
|
offsetof(FormData_pg_group, grolist[0]),
|
|
|
|
NULL,
|
|
|
|
(ScanFunc) NULL},
|
|
|
|
{GroupRelationName, /* GROSYSID */
|
|
|
|
1,
|
1998-08-19 04:04:17 +02:00
|
|
|
{
|
|
|
|
Anum_pg_group_grosysid,
|
1997-09-07 07:04:48 +02:00
|
|
|
0,
|
|
|
|
0,
|
1998-08-19 04:04:17 +02:00
|
|
|
0
|
|
|
|
},
|
1997-09-07 07:04:48 +02:00
|
|
|
offsetof(FormData_pg_group, grolist[0]),
|
|
|
|
NULL,
|
|
|
|
(ScanFunc) NULL},
|
|
|
|
{RewriteRelationName, /* REWRITENAME */
|
|
|
|
1,
|
1998-08-19 04:04:17 +02:00
|
|
|
{
|
|
|
|
Anum_pg_rewrite_rulename,
|
1997-09-07 07:04:48 +02:00
|
|
|
0,
|
|
|
|
0,
|
1998-08-19 04:04:17 +02:00
|
|
|
0
|
|
|
|
},
|
1997-09-07 07:04:48 +02:00
|
|
|
offsetof(FormData_pg_rewrite, ev_qual),
|
|
|
|
NULL,
|
|
|
|
(ScanFunc) NULL},
|
|
|
|
{ProcedureRelationName, /* PROSRC */
|
|
|
|
1,
|
1998-08-19 04:04:17 +02:00
|
|
|
{
|
|
|
|
Anum_pg_proc_prosrc,
|
1997-09-07 07:04:48 +02:00
|
|
|
0,
|
|
|
|
0,
|
1998-08-19 04:04:17 +02:00
|
|
|
0
|
|
|
|
},
|
1997-09-07 07:04:48 +02:00
|
|
|
offsetof(FormData_pg_proc, prosrc),
|
|
|
|
ProcedureSrcIndex,
|
|
|
|
(ScanFunc) ProcedureSrcIndexScan},
|
|
|
|
{OperatorClassRelationName, /* CLADEFTYPE */
|
|
|
|
1,
|
1998-08-19 04:04:17 +02:00
|
|
|
{
|
|
|
|
Anum_pg_opclass_opcdeftype,
|
1997-09-07 07:04:48 +02:00
|
|
|
0,
|
|
|
|
0,
|
1998-08-19 04:04:17 +02:00
|
|
|
0
|
|
|
|
},
|
1997-09-07 07:04:48 +02:00
|
|
|
sizeof(FormData_pg_opclass),
|
|
|
|
NULL,
|
1997-10-28 16:11:45 +01:00
|
|
|
(ScanFunc) NULL},
|
|
|
|
{LanguageRelationName, /* LANOID */
|
|
|
|
1,
|
1998-08-19 04:04:17 +02:00
|
|
|
{
|
|
|
|
ObjectIdAttributeNumber,
|
1997-10-28 16:11:45 +01:00
|
|
|
0,
|
|
|
|
0,
|
1998-08-19 04:04:17 +02:00
|
|
|
0
|
|
|
|
},
|
1997-10-28 16:11:45 +01:00
|
|
|
offsetof(FormData_pg_language, lancompiler),
|
|
|
|
NULL,
|
|
|
|
NULL}
|
1996-07-09 08:22:35 +02:00
|
|
|
};
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1999-05-29 03:45:21 +02:00
|
|
|
static struct catcache *SysCache[lengthof(cacheinfo)];
|
1997-09-08 04:41:22 +02:00
|
|
|
static int32 SysCacheSize = lengthof(cacheinfo);
|
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()
|
|
|
|
{
|
1997-09-18 22:22:58 +02:00
|
|
|
MemSet((char *) SysCache, 0, SysCacheSize * sizeof(struct catcache *));
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Note:
|
1997-09-07 07:04:48 +02:00
|
|
|
* This function was written because the initialized catalog caches
|
|
|
|
* are used to determine which caches may contain tuples which need
|
|
|
|
* to be invalidated in other backends.
|
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)
|
|
|
|
{
|
|
|
|
|
|
|
|
Assert(!PointerIsValid((Pointer) SysCache[cacheId]));
|
|
|
|
|
1999-02-03 22:18:02 +01:00
|
|
|
SysCache[cacheId] = InitSysCache(cacheinfo[cacheId].name,
|
1999-05-25 18:15:34 +02:00
|
|
|
cacheinfo[cacheId].indname,
|
|
|
|
cacheId,
|
|
|
|
cacheinfo[cacheId].nkeys,
|
|
|
|
cacheinfo[cacheId].key,
|
|
|
|
cacheinfo[cacheId].iScanFunc);
|
1997-09-07 07:04:48 +02:00
|
|
|
if (!PointerIsValid((char *) SysCache[cacheId]))
|
|
|
|
{
|
1998-01-07 22:07:04 +01:00
|
|
|
elog(ERROR,
|
1998-07-20 18:57:18 +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
|
|
|
}
|
|
|
|
}
|
1998-09-01 06:40:42 +02:00
|
|
|
|
1998-08-19 04:04:17 +02:00
|
|
|
/*
|
1999-02-14 00:22:53 +01:00
|
|
|
* SearchSysCacheTupleCopy
|
1998-08-19 04:04:17 +02:00
|
|
|
*
|
1999-07-07 18:09:33 +02:00
|
|
|
* This is like SearchSysCacheTuple, except it returns a copy of the tuple
|
1998-08-19 04:04:17 +02:00
|
|
|
* that the user is required to pfree().
|
|
|
|
*/
|
|
|
|
HeapTuple
|
1998-09-01 06:40:42 +02:00
|
|
|
SearchSysCacheTupleCopy(int cacheId, /* cache selection code */
|
|
|
|
Datum key1,
|
|
|
|
Datum key2,
|
|
|
|
Datum key3,
|
|
|
|
Datum key4)
|
1998-08-19 04:04:17 +02:00
|
|
|
{
|
|
|
|
HeapTuple cachetup;
|
|
|
|
|
|
|
|
cachetup = SearchSysCacheTuple(cacheId, key1, key2, key3, key4);
|
|
|
|
if (PointerIsValid(cachetup))
|
|
|
|
return heap_copytuple(cachetup);
|
|
|
|
else
|
1998-09-01 06:40:42 +02:00
|
|
|
return cachetup; /* NULL */
|
1998-08-19 04:04:17 +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
|
|
|
*
|
1998-08-19 04:04:17 +02:00
|
|
|
* XXX The tuple that is returned is NOT supposed to be pfree'd!
|
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
|
|
|
{
|
1999-02-03 22:18:02 +01:00
|
|
|
SysCache[cacheId] = InitSysCache(cacheinfo[cacheId].name,
|
1999-05-25 18:15:34 +02:00
|
|
|
cacheinfo[cacheId].indname,
|
|
|
|
cacheId,
|
|
|
|
cacheinfo[cacheId].nkeys,
|
|
|
|
cacheinfo[cacheId].key,
|
|
|
|
cacheinfo[cacheId].iScanFunc);
|
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
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1999-02-14 00:22:53 +01:00
|
|
|
* SearchSysCacheStruct
|
1997-09-07 07:04:48 +02:00
|
|
|
* Fills 's' with the information retrieved by calling SearchSysCache()
|
|
|
|
* with arguments key1...key4. Retrieves only the portion of the tuple
|
|
|
|
* which is not variable-length.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
* NOTE: we are assuming that non-variable-length fields in the system
|
1997-09-07 07:04:48 +02:00
|
|
|
* catalogs will always be defined!
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
* Returns 1L if a tuple was found, 0L if not.
|
|
|
|
*/
|
|
|
|
int32
|
|
|
|
SearchSysCacheStruct(int cacheId, /* cache selection code */
|
1997-09-07 07:04:48 +02:00
|
|
|
char *returnStruct, /* (preallocated!) */
|
|
|
|
Datum key1,
|
|
|
|
Datum key2,
|
|
|
|
Datum key3,
|
|
|
|
Datum key4)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
HeapTuple tp;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
if (!PointerIsValid(returnStruct))
|
|
|
|
{
|
1998-01-07 22:07:04 +01:00
|
|
|
elog(ERROR, "SearchSysCacheStruct: No receiving struct");
|
1998-09-01 05:29:17 +02:00
|
|
|
return 0;
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
|
|
|
tp = SearchSysCacheTuple(cacheId, key1, key2, key3, key4);
|
|
|
|
if (!HeapTupleIsValid(tp))
|
1998-09-01 05:29:17 +02:00
|
|
|
return 0;
|
1999-05-29 03:45:21 +02:00
|
|
|
memcpy(returnStruct, (char *) GETSTRUCT(tp), cacheinfo[cacheId].size);
|
1998-09-01 05:29:17 +02:00
|
|
|
return 1;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
1999-02-14 00:22:53 +01:00
|
|
|
* SearchSysCacheGetAttribute
|
1997-09-07 07:04:48 +02:00
|
|
|
* Returns the attribute corresponding to 'attributeNumber' for
|
1999-05-29 03:45:21 +02:00
|
|
|
* a given cached tuple. This routine usually needs to be used for
|
|
|
|
* attributes that might be NULL or might be at a variable offset
|
|
|
|
* in the tuple.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
1999-05-29 03:45:21 +02:00
|
|
|
* XXX This re-opens the relation, so this is slower than just pulling
|
|
|
|
* fixed-location fields out of the struct returned by SearchSysCacheTuple.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
* [callers all assume this returns a (struct varlena *). -ay 10/94]
|
|
|
|
*/
|
1998-02-26 05:46:47 +01:00
|
|
|
void *
|
1996-07-09 08:22:35 +02:00
|
|
|
SearchSysCacheGetAttribute(int cacheId,
|
1997-09-07 07:04:48 +02:00
|
|
|
AttrNumber attributeNumber,
|
|
|
|
Datum key1,
|
|
|
|
Datum key2,
|
|
|
|
Datum key3,
|
|
|
|
Datum key4)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
HeapTuple tp;
|
|
|
|
char *cacheName;
|
|
|
|
Relation relation;
|
|
|
|
int32 attributeLength,
|
|
|
|
attributeByValue;
|
|
|
|
bool isNull;
|
1997-09-12 06:09:08 +02:00
|
|
|
Datum attributeValue;
|
1997-09-08 04:41:22 +02:00
|
|
|
void *returnValue;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
tp = SearchSysCacheTuple(cacheId, key1, key2, key3, key4);
|
|
|
|
cacheName = cacheinfo[cacheId].name;
|
|
|
|
|
|
|
|
if (!HeapTupleIsValid(tp))
|
|
|
|
{
|
1996-07-09 08:22:35 +02:00
|
|
|
#ifdef CACHEDEBUG
|
1997-09-07 07:04:48 +02:00
|
|
|
elog(DEBUG,
|
|
|
|
"SearchSysCacheGetAttribute: Lookup in %s(%d) failed",
|
|
|
|
cacheName, cacheId);
|
1998-09-01 06:40:42 +02:00
|
|
|
#endif /* defined(CACHEDEBUG) */
|
1998-09-01 05:29:17 +02:00
|
|
|
return NULL;
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
relation = heap_openr(cacheName);
|
|
|
|
|
|
|
|
if (attributeNumber < 0 &&
|
|
|
|
attributeNumber > FirstLowInvalidHeapAttributeNumber)
|
|
|
|
{
|
|
|
|
attributeLength = heap_sysattrlen(attributeNumber);
|
|
|
|
attributeByValue = heap_sysattrbyval(attributeNumber);
|
|
|
|
}
|
|
|
|
else if (attributeNumber > 0 &&
|
|
|
|
attributeNumber <= relation->rd_rel->relnatts)
|
|
|
|
{
|
1999-02-03 22:18:02 +01:00
|
|
|
attributeLength = relation->rd_att->attrs[attributeNumber - 1]->attlen;
|
|
|
|
attributeByValue = relation->rd_att->attrs[attributeNumber - 1]->attbyval;
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
1998-01-07 22:07:04 +01:00
|
|
|
elog(ERROR,
|
1997-09-07 07:04:48 +02:00
|
|
|
"SearchSysCacheGetAttribute: Bad attr # %d in %s(%d)",
|
|
|
|
attributeNumber, cacheName, cacheId);
|
1998-09-01 05:29:17 +02:00
|
|
|
return NULL;
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
attributeValue = heap_getattr(tp,
|
|
|
|
attributeNumber,
|
1998-09-01 05:29:17 +02:00
|
|
|
RelationGetDescr(relation),
|
1997-09-07 07:04:48 +02:00
|
|
|
&isNull);
|
|
|
|
|
|
|
|
if (isNull)
|
|
|
|
{
|
1998-09-01 06:40:42 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
/*
|
|
|
|
* Used to be an elog(DEBUG, ...) here and a claim that it should
|
|
|
|
* be a FATAL error, I don't think either is warranted -mer 6/9/92
|
|
|
|
*/
|
1998-09-01 05:29:17 +02:00
|
|
|
return NULL;
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (attributeByValue)
|
|
|
|
returnValue = (void *) attributeValue;
|
|
|
|
else
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
char *tmp;
|
|
|
|
int size = (attributeLength < 0)
|
1997-09-07 07:04:48 +02:00
|
|
|
? VARSIZE((struct varlena *) attributeValue) /* variable length */
|
|
|
|
: attributeLength; /* fixed length */
|
|
|
|
|
|
|
|
tmp = (char *) palloc(size);
|
1999-05-29 03:45:21 +02:00
|
|
|
memcpy(tmp, (void *) attributeValue, size);
|
1997-09-07 07:04:48 +02:00
|
|
|
returnValue = (void *) tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
heap_close(relation);
|
1998-09-01 05:29:17 +02:00
|
|
|
return returnValue;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1999-02-14 00:22:53 +01:00
|
|
|
* TypeDefaultRetrieve
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
1997-09-07 07:04:48 +02:00
|
|
|
* Given a type OID, return the typdefault field associated with that
|
1999-05-29 03:45:21 +02:00
|
|
|
* type. The result is a Datum, and points to palloc'd storage for
|
|
|
|
* non-pass-by-value types.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
* [identical to get_typdefault, expecting a (struct varlena *) as ret val.
|
1997-09-07 07:04:48 +02:00
|
|
|
* some day, either of the functions should be removed -ay 10/94]
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
1998-02-26 05:46:47 +01:00
|
|
|
void *
|
1996-07-09 08:22:35 +02:00
|
|
|
TypeDefaultRetrieve(Oid typId)
|
|
|
|
{
|
1999-05-29 03:45:21 +02:00
|
|
|
struct varlena *typDefault;
|
|
|
|
int32 dataSize;
|
1997-09-08 04:41:22 +02:00
|
|
|
HeapTuple typeTuple;
|
1998-09-01 05:29:17 +02:00
|
|
|
Form_pg_type type;
|
1997-09-08 04:41:22 +02:00
|
|
|
int32 typByVal,
|
|
|
|
typLen;
|
|
|
|
void *returnValue;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1999-05-29 03:45:21 +02:00
|
|
|
/*
|
|
|
|
* First, see if there is a non-null typdefault field (usually there isn't)
|
|
|
|
*/
|
|
|
|
typDefault = (struct varlena *)
|
|
|
|
SearchSysCacheGetAttribute(TYPOID,
|
|
|
|
Anum_pg_type_typdefault,
|
|
|
|
ObjectIdGetDatum(typId),
|
|
|
|
0, 0, 0);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1999-05-29 03:45:21 +02:00
|
|
|
if (typDefault == NULL)
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
1996-07-09 08:22:35 +02:00
|
|
|
#ifdef CACHEDEBUG
|
1999-05-29 03:45:21 +02:00
|
|
|
elog(DEBUG, "TypeDefaultRetrieve: No extractable typdefault in %s(%d)",
|
1998-05-10 01:45:29 +02:00
|
|
|
cacheinfo[TYPOID].name, TYPOID);
|
1998-09-01 06:40:42 +02:00
|
|
|
#endif /* defined(CACHEDEBUG) */
|
1998-09-01 05:29:17 +02:00
|
|
|
return NULL;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1999-05-29 03:45:21 +02:00
|
|
|
dataSize = VARSIZE(typDefault) - VARHDRSZ;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1999-05-29 03:45:21 +02:00
|
|
|
/*
|
|
|
|
* Need the type's length and byVal fields.
|
|
|
|
*
|
|
|
|
* XXX silly to repeat the syscache search that SearchSysCacheGetAttribute
|
|
|
|
* just did --- but at present this path isn't taken often enough to
|
|
|
|
* make it worth fixing.
|
|
|
|
*/
|
|
|
|
typeTuple = SearchSysCacheTuple(TYPOID,
|
|
|
|
ObjectIdGetDatum(typId),
|
|
|
|
0, 0, 0);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1999-05-29 03:45:21 +02:00
|
|
|
if (!HeapTupleIsValid(typeTuple))
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
1999-05-29 03:45:21 +02:00
|
|
|
/* should never get here, really... */
|
1997-09-07 07:04:48 +02:00
|
|
|
#ifdef CACHEDEBUG
|
1999-05-29 03:45:21 +02:00
|
|
|
elog(DEBUG, "TypeDefaultRetrieve: Lookup in %s(%d) failed",
|
1998-05-10 01:45:29 +02:00
|
|
|
cacheinfo[TYPOID].name, TYPOID);
|
1998-09-01 06:40:42 +02:00
|
|
|
#endif /* defined(CACHEDEBUG) */
|
1998-09-01 05:29:17 +02:00
|
|
|
return NULL;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
1999-05-29 03:45:21 +02:00
|
|
|
type = (Form_pg_type) GETSTRUCT(typeTuple);
|
|
|
|
typLen = type->typlen;
|
|
|
|
typByVal = type->typbyval;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
if (typByVal)
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
int8 i8;
|
|
|
|
int16 i16;
|
1999-05-29 03:45:21 +02:00
|
|
|
int32 i32 = 0;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
if (dataSize == typLen)
|
|
|
|
{
|
|
|
|
switch (typLen)
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
case sizeof(int8):
|
1999-05-29 03:45:21 +02:00
|
|
|
memcpy((char *) &i8, VARDATA(typDefault), sizeof(int8));
|
1997-09-08 04:41:22 +02:00
|
|
|
i32 = i8;
|
|
|
|
break;
|
|
|
|
case sizeof(int16):
|
1999-05-29 03:45:21 +02:00
|
|
|
memcpy((char *) &i16, VARDATA(typDefault), sizeof(int16));
|
1997-09-08 04:41:22 +02:00
|
|
|
i32 = i16;
|
|
|
|
break;
|
|
|
|
case sizeof(int32):
|
1999-05-29 03:45:21 +02:00
|
|
|
memcpy((char *) &i32, VARDATA(typDefault), sizeof(int32));
|
1997-09-08 04:41:22 +02:00
|
|
|
break;
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
|
|
|
returnValue = (void *) i32;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
returnValue = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ((typLen < 0 && dataSize < 0) || dataSize != typLen)
|
|
|
|
returnValue = NULL;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
returnValue = (void *) palloc(VARSIZE(typDefault));
|
1999-05-29 03:45:21 +02:00
|
|
|
memcpy((char *) returnValue,
|
|
|
|
(char *) typDefault,
|
|
|
|
(int) VARSIZE(typDefault));
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-09-01 05:29:17 +02:00
|
|
|
return returnValue;
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|