1996-08-28 03:59:28 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* rel.h
|
2000-01-31 05:35:57 +01:00
|
|
|
* POSTGRES relation descriptor (a/k/a relcache entry) definitions.
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
|
|
|
*
|
2004-08-29 06:13:13 +02:00
|
|
|
* Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
2004-09-16 18:58:44 +02:00
|
|
|
* $PostgreSQL: pgsql/src/include/utils/rel.h,v 1.80 2004/09/16 16:58:43 tgl Exp $
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
#ifndef REL_H
|
1996-08-28 03:59:28 +02:00
|
|
|
#define REL_H
|
|
|
|
|
1999-07-16 01:04:24 +02:00
|
|
|
#include "access/tupdesc.h"
|
1999-07-16 19:07:40 +02:00
|
|
|
#include "catalog/pg_am.h"
|
|
|
|
#include "catalog/pg_class.h"
|
2002-02-19 21:11:20 +01:00
|
|
|
#include "catalog/pg_index.h"
|
1999-07-16 01:04:24 +02:00
|
|
|
#include "rewrite/prs2lock.h"
|
2001-06-28 01:31:40 +02:00
|
|
|
#include "storage/block.h"
|
|
|
|
#include "storage/relfilenode.h"
|
1996-08-28 03:59:28 +02:00
|
|
|
|
2000-01-31 05:35:57 +01:00
|
|
|
|
1999-09-18 21:08:25 +02:00
|
|
|
/*
|
|
|
|
* LockRelId and LockInfo really belong to lmgr.h, but it's more convenient
|
|
|
|
* to declare them here so we can have a LockInfoData field in a Relation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef struct LockRelId
|
|
|
|
{
|
|
|
|
Oid relId; /* a relation identifier */
|
|
|
|
Oid dbId; /* a database identifier */
|
|
|
|
} LockRelId;
|
|
|
|
|
|
|
|
typedef struct LockInfoData
|
|
|
|
{
|
|
|
|
LockRelId lockRelId;
|
|
|
|
} LockInfoData;
|
|
|
|
|
|
|
|
typedef LockInfoData *LockInfo;
|
|
|
|
|
2000-01-31 05:35:57 +01:00
|
|
|
/*
|
|
|
|
* Likewise, this struct really belongs to trigger.h, but for convenience
|
|
|
|
* we put it here.
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct Trigger
|
|
|
|
{
|
2002-04-02 00:36:13 +02:00
|
|
|
Oid tgoid; /* OID of trigger (pg_trigger row) */
|
|
|
|
/* Remaining fields are copied from pg_trigger, see pg_trigger.h */
|
1997-09-08 04:41:22 +02:00
|
|
|
char *tgname;
|
|
|
|
Oid tgfoid;
|
|
|
|
int16 tgtype;
|
1999-09-29 18:06:40 +02:00
|
|
|
bool tgenabled;
|
|
|
|
bool tgisconstraint;
|
2002-04-02 00:36:13 +02:00
|
|
|
Oid tgconstrrelid;
|
1999-09-29 18:06:40 +02:00
|
|
|
bool tgdeferrable;
|
|
|
|
bool tginitdeferred;
|
1997-09-08 04:41:22 +02:00
|
|
|
int16 tgnargs;
|
2000-01-10 18:14:46 +01:00
|
|
|
int16 tgattr[FUNC_MAX_ARGS];
|
1997-09-08 04:41:22 +02:00
|
|
|
char **tgargs;
|
1997-09-08 23:56:23 +02:00
|
|
|
} Trigger;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
typedef struct TriggerDesc
|
|
|
|
{
|
2001-06-01 04:41:36 +02:00
|
|
|
/*
|
2001-10-25 07:50:21 +02:00
|
|
|
* Index data to identify which triggers are which. Since each
|
|
|
|
* trigger can appear in more than one class, for each class we
|
|
|
|
* provide a list of integer indexes into the triggers array.
|
2001-06-01 04:41:36 +02:00
|
|
|
*/
|
2002-11-23 04:59:09 +01:00
|
|
|
#define TRIGGER_NUM_EVENT_CLASSES 3
|
2001-06-01 04:41:36 +02:00
|
|
|
|
|
|
|
uint16 n_before_statement[TRIGGER_NUM_EVENT_CLASSES];
|
|
|
|
uint16 n_before_row[TRIGGER_NUM_EVENT_CLASSES];
|
|
|
|
uint16 n_after_row[TRIGGER_NUM_EVENT_CLASSES];
|
|
|
|
uint16 n_after_statement[TRIGGER_NUM_EVENT_CLASSES];
|
|
|
|
int *tg_before_statement[TRIGGER_NUM_EVENT_CLASSES];
|
|
|
|
int *tg_before_row[TRIGGER_NUM_EVENT_CLASSES];
|
|
|
|
int *tg_after_row[TRIGGER_NUM_EVENT_CLASSES];
|
|
|
|
int *tg_after_statement[TRIGGER_NUM_EVENT_CLASSES];
|
|
|
|
|
|
|
|
/* The actual array of triggers is here */
|
1997-09-08 04:41:22 +02:00
|
|
|
Trigger *triggers;
|
2000-01-31 05:35:57 +01:00
|
|
|
int numtriggers;
|
1997-09-08 23:56:23 +02:00
|
|
|
} TriggerDesc;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2001-06-22 21:16:24 +02:00
|
|
|
|
2003-11-09 22:30:38 +01:00
|
|
|
/*
|
2001-06-22 21:16:24 +02:00
|
|
|
* Same for the statistics collector data in Relation and scan data.
|
|
|
|
*/
|
2001-10-25 07:50:21 +02:00
|
|
|
typedef struct PgStat_Info
|
2001-06-22 21:16:24 +02:00
|
|
|
{
|
2001-10-25 07:50:21 +02:00
|
|
|
void *tabentry;
|
|
|
|
bool no_stats;
|
|
|
|
bool heap_scan_counted;
|
|
|
|
bool index_scan_counted;
|
2001-06-22 21:16:24 +02:00
|
|
|
} PgStat_Info;
|
|
|
|
|
2004-02-10 02:55:27 +01:00
|
|
|
|
2000-01-31 05:35:57 +01:00
|
|
|
/*
|
|
|
|
* Here are the contents of a relation cache entry.
|
|
|
|
*/
|
1999-09-18 21:08:25 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct RelationData
|
|
|
|
{
|
2004-02-10 02:55:27 +01:00
|
|
|
RelFileNode rd_node; /* relation physical identifier */
|
|
|
|
/* use "struct" here to avoid needing to include smgr.h: */
|
2004-08-29 07:07:03 +02:00
|
|
|
struct SMgrRelationData *rd_smgr; /* cached file handle, or NULL */
|
2001-10-25 07:50:21 +02:00
|
|
|
BlockNumber rd_targblock; /* current insertion target block, or
|
|
|
|
* InvalidBlockNumber */
|
2001-06-28 01:31:40 +02:00
|
|
|
int rd_refcnt; /* reference count */
|
2002-08-06 04:36:35 +02:00
|
|
|
bool rd_istemp; /* rel uses the local buffer mgr */
|
2004-08-28 22:31:44 +02:00
|
|
|
bool rd_isnailed; /* rel is nailed in cache */
|
|
|
|
bool rd_isvalid; /* relcache entry is valid */
|
2004-08-29 07:07:03 +02:00
|
|
|
char rd_indexvalid; /* state of rd_indexlist: 0 = not valid, 1
|
|
|
|
* = valid, 2 = temporarily forced */
|
2004-09-16 18:58:44 +02:00
|
|
|
SubTransactionId rd_createSubid; /* rel was created in current xact */
|
2004-08-29 07:07:03 +02:00
|
|
|
|
2004-08-28 22:31:44 +02:00
|
|
|
/*
|
2004-09-16 18:58:44 +02:00
|
|
|
* rd_createSubid is the ID of the highest subtransaction the rel has
|
2004-08-28 22:31:44 +02:00
|
|
|
* survived into; or zero if the rel was not created in the current
|
2004-09-16 18:58:44 +02:00
|
|
|
* top transaction. This should be relied on only for optimization
|
2004-08-29 07:07:03 +02:00
|
|
|
* purposes; it is possible for new-ness to be "forgotten" (eg, after
|
|
|
|
* CLUSTER).
|
2004-08-28 22:31:44 +02:00
|
|
|
*/
|
1997-09-08 04:41:22 +02:00
|
|
|
Form_pg_class rd_rel; /* RELATION tuple */
|
2002-02-19 21:11:20 +01:00
|
|
|
TupleDesc rd_att; /* tuple descriptor */
|
1999-09-18 21:08:25 +02:00
|
|
|
Oid rd_id; /* relation's object id */
|
2000-06-17 23:49:04 +02:00
|
|
|
List *rd_indexlist; /* list of OIDs of indexes on relation */
|
|
|
|
LockInfoData rd_lockInfo; /* lock mgr's info for locking relation */
|
1997-09-08 04:41:22 +02:00
|
|
|
RuleLock *rd_rules; /* rewrite rules */
|
2000-06-30 09:04:23 +02:00
|
|
|
MemoryContext rd_rulescxt; /* private memory cxt for rd_rules, if any */
|
2000-01-31 05:35:57 +01:00
|
|
|
TriggerDesc *trigdesc; /* Trigger info, or NULL if rel has none */
|
2001-06-22 21:16:24 +02:00
|
|
|
|
2002-02-19 21:11:20 +01:00
|
|
|
/* These are non-NULL only for an index relation: */
|
|
|
|
Form_pg_index rd_index; /* pg_index tuple describing this index */
|
2003-08-04 02:43:34 +02:00
|
|
|
struct HeapTupleData *rd_indextuple; /* all of pg_index tuple */
|
|
|
|
/* "struct HeapTupleData *" avoids need to include htup.h here */
|
2002-02-19 21:11:20 +01:00
|
|
|
Form_pg_am rd_am; /* pg_am tuple for index's AM */
|
|
|
|
|
2003-11-09 22:30:38 +01:00
|
|
|
/*
|
|
|
|
* index access support info (used only for an index relation)
|
|
|
|
*
|
2003-11-12 22:15:59 +01:00
|
|
|
* Note: only default operators and support procs for each opclass are
|
2004-08-29 07:07:03 +02:00
|
|
|
* cached, namely those with subtype zero. The arrays are indexed by
|
2003-11-09 22:30:38 +01:00
|
|
|
* strategy or support number, which is a sufficient identifier given
|
|
|
|
* that restriction.
|
|
|
|
*/
|
2001-10-07 01:21:45 +02:00
|
|
|
MemoryContext rd_indexcxt; /* private memory cxt for this stuff */
|
2002-02-19 21:11:20 +01:00
|
|
|
Oid *rd_operator; /* OIDs of index operators */
|
2001-10-07 01:21:45 +02:00
|
|
|
RegProcedure *rd_support; /* OIDs of support procedures */
|
2001-10-25 07:50:21 +02:00
|
|
|
struct FmgrInfo *rd_supportinfo; /* lookup info for support
|
|
|
|
* procedures */
|
2001-10-07 01:21:45 +02:00
|
|
|
/* "struct FmgrInfo" avoids need to include fmgr.h here */
|
2003-05-28 18:04:02 +02:00
|
|
|
List *rd_indexprs; /* index expression trees, if any */
|
|
|
|
List *rd_indpred; /* index predicate tree, if any */
|
2001-10-07 01:21:45 +02:00
|
|
|
|
|
|
|
/* statistics collection area */
|
2001-10-25 07:50:21 +02:00
|
|
|
PgStat_Info pgstat_info;
|
1997-09-08 23:56:23 +02:00
|
|
|
} RelationData;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
typedef RelationData *Relation;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
1999-09-18 21:08:25 +02:00
|
|
|
|
1996-08-28 03:59:28 +02:00
|
|
|
/* ----------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* RelationPtr is used in the executor to support index scans
|
|
|
|
* where we have to keep track of several index relations in an
|
|
|
|
* array. -cim 9/10/89
|
1996-08-28 03:59:28 +02:00
|
|
|
* ----------------
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef Relation *RelationPtr;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
1999-05-25 18:15:34 +02:00
|
|
|
* RelationIsValid
|
1997-09-07 07:04:48 +02:00
|
|
|
* True iff relation descriptor is valid.
|
1996-08-28 03:59:28 +02:00
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
#define RelationIsValid(relation) PointerIsValid(relation)
|
1996-08-28 03:59:28 +02:00
|
|
|
|
1999-09-18 21:08:25 +02:00
|
|
|
#define InvalidRelation ((Relation) NULL)
|
|
|
|
|
1996-08-28 03:59:28 +02:00
|
|
|
/*
|
1999-05-25 18:15:34 +02:00
|
|
|
* RelationHasReferenceCountZero
|
1997-09-07 07:04:48 +02:00
|
|
|
* True iff relation reference count is zero.
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
|
|
|
* Note:
|
1997-09-07 07:04:48 +02:00
|
|
|
* Assumes relation descriptor is valid.
|
1996-08-28 03:59:28 +02:00
|
|
|
*/
|
|
|
|
#define RelationHasReferenceCountZero(relation) \
|
1997-09-07 07:04:48 +02:00
|
|
|
((bool)((relation)->rd_refcnt == 0))
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/*
|
1999-05-25 18:15:34 +02:00
|
|
|
* RelationGetForm
|
2000-01-31 05:35:57 +01:00
|
|
|
* Returns pg_class tuple for a relation.
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
|
|
|
* Note:
|
1997-09-07 07:04:48 +02:00
|
|
|
* Assumes relation descriptor is valid.
|
1996-08-28 03:59:28 +02:00
|
|
|
*/
|
1998-09-01 05:29:17 +02:00
|
|
|
#define RelationGetForm(relation) ((relation)->rd_rel)
|
1996-08-28 03:59:28 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
/*
|
1999-05-25 18:15:34 +02:00
|
|
|
* RelationGetRelid
|
2004-01-06 19:07:32 +01:00
|
|
|
* Returns the OID of the relation
|
1996-08-28 03:59:28 +02:00
|
|
|
*/
|
1998-08-19 04:04:17 +02:00
|
|
|
#define RelationGetRelid(relation) ((relation)->rd_id)
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/*
|
1999-09-18 21:08:25 +02:00
|
|
|
* RelationGetNumberOfAttributes
|
2004-01-06 19:07:32 +01:00
|
|
|
* Returns the number of attributes in a relation.
|
1996-08-28 03:59:28 +02:00
|
|
|
*/
|
|
|
|
#define RelationGetNumberOfAttributes(relation) ((relation)->rd_rel->relnatts)
|
|
|
|
|
|
|
|
/*
|
1999-05-25 18:15:34 +02:00
|
|
|
* RelationGetDescr
|
1997-09-07 07:04:48 +02:00
|
|
|
* Returns tuple descriptor for a relation.
|
1996-08-28 03:59:28 +02:00
|
|
|
*/
|
1998-09-01 05:29:17 +02:00
|
|
|
#define RelationGetDescr(relation) ((relation)->rd_att)
|
1996-08-28 03:59:28 +02:00
|
|
|
|
2001-06-19 14:03:41 +02:00
|
|
|
/*
|
|
|
|
* RelationGetRelationName
|
2004-01-06 19:07:32 +01:00
|
|
|
* Returns the rel's name.
|
2001-06-19 14:03:41 +02:00
|
|
|
*
|
2002-03-31 08:26:32 +02:00
|
|
|
* Note that the name is only unique within the containing namespace.
|
2001-06-19 14:03:41 +02:00
|
|
|
*/
|
|
|
|
#define RelationGetRelationName(relation) \
|
2002-03-31 08:26:32 +02:00
|
|
|
(NameStr((relation)->rd_rel->relname))
|
2001-06-19 14:03:41 +02:00
|
|
|
|
2002-03-26 20:17:02 +01:00
|
|
|
/*
|
|
|
|
* RelationGetNamespace
|
2004-01-06 19:07:32 +01:00
|
|
|
* Returns the rel's namespace OID.
|
2002-03-26 20:17:02 +01:00
|
|
|
*/
|
|
|
|
#define RelationGetNamespace(relation) \
|
|
|
|
((relation)->rd_rel->relnamespace)
|
|
|
|
|
2004-08-28 22:31:44 +02:00
|
|
|
/*
|
|
|
|
* RELATION_IS_LOCAL
|
|
|
|
* If a rel is either temp or newly created in the current transaction,
|
|
|
|
* it can be assumed to be visible only to the current backend.
|
|
|
|
*
|
|
|
|
* Beware of multiple eval of argument
|
|
|
|
*/
|
|
|
|
#define RELATION_IS_LOCAL(relation) \
|
2004-09-16 18:58:44 +02:00
|
|
|
((relation)->rd_istemp || \
|
|
|
|
(relation)->rd_createSubid != InvalidSubTransactionId)
|
2004-08-28 22:31:44 +02:00
|
|
|
|
2004-07-17 05:32:14 +02:00
|
|
|
/* routines in utils/cache/relcache.c */
|
|
|
|
extern void RelationIncrementReferenceCount(Relation rel);
|
|
|
|
extern void RelationDecrementReferenceCount(Relation rel);
|
|
|
|
|
2001-11-05 18:46:40 +01:00
|
|
|
#endif /* REL_H */
|