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
|
|
|
*
|
|
|
|
*
|
2001-01-24 20:43:33 +01:00
|
|
|
* Portions Copyright (c) 1996-2001, 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
|
|
|
*
|
2001-06-19 07:11:50 +02:00
|
|
|
* $Id: rel.h,v 1.47 2001/06/19 05:11:50 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/strat.h"
|
|
|
|
#include "access/tupdesc.h"
|
1999-07-16 19:07:40 +02:00
|
|
|
#include "catalog/pg_am.h"
|
|
|
|
#include "catalog/pg_class.h"
|
1999-07-16 01:04:24 +02:00
|
|
|
#include "rewrite/prs2lock.h"
|
2000-09-07 11:58:38 +02:00
|
|
|
#include "storage/relfilenode.h"
|
1999-07-16 01:04:24 +02:00
|
|
|
#include "storage/fd.h"
|
1996-08-28 03:59:28 +02:00
|
|
|
|
2000-01-31 05:35:57 +01:00
|
|
|
/* added to prevent circular dependency. bjm 1999/11/15 */
|
|
|
|
extern char *get_temp_rel_by_physicalname(const char *relname);
|
|
|
|
|
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
|
|
|
|
{
|
1999-09-29 18:06:40 +02:00
|
|
|
Oid tgoid;
|
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;
|
|
|
|
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
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
#define TRIGGER_NUM_EVENT_CLASSES 4
|
|
|
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
{
|
2000-06-30 09:04:23 +02:00
|
|
|
File rd_fd; /* open file descriptor, or -1 if none */
|
2001-03-22 05:01:46 +01:00
|
|
|
RelFileNode rd_node; /* relation file node */
|
1997-09-08 04:41:22 +02:00
|
|
|
int rd_nblocks; /* number of blocks in rel */
|
|
|
|
uint16 rd_refcnt; /* reference count */
|
1999-09-18 21:08:25 +02:00
|
|
|
bool rd_myxactonly; /* rel uses the local buffer mgr */
|
1997-09-08 04:41:22 +02:00
|
|
|
bool rd_isnailed; /* rel is nailed in cache */
|
2000-06-17 23:49:04 +02:00
|
|
|
bool rd_indexfound; /* true if rd_indexlist is valid */
|
2001-03-22 05:01:46 +01:00
|
|
|
bool rd_uniqueindex; /* true if rel is a UNIQUE index */
|
1997-09-08 04:41:22 +02:00
|
|
|
Form_pg_am rd_am; /* AM tuple */
|
|
|
|
Form_pg_class rd_rel; /* RELATION tuple */
|
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 */
|
1999-09-18 21:08:25 +02:00
|
|
|
TupleDesc rd_att; /* tuple descriptor */
|
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-06-17 23:49:04 +02:00
|
|
|
IndexStrategy rd_istrat; /* info needed if rel is an index */
|
1997-09-08 04:41:22 +02:00
|
|
|
RegProcedure *rd_support;
|
2000-01-31 05:35:57 +01:00
|
|
|
TriggerDesc *trigdesc; /* Trigger info, or NULL if rel has none */
|
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
|
|
|
* RelationSetReferenceCount
|
1997-09-07 07:04:48 +02:00
|
|
|
* Sets relation reference count.
|
1996-08-28 03:59:28 +02:00
|
|
|
*/
|
2000-06-17 23:49:04 +02:00
|
|
|
#define RelationSetReferenceCount(relation,count) \
|
|
|
|
((relation)->rd_refcnt = (count))
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/*
|
1999-05-25 18:15:34 +02:00
|
|
|
* RelationIncrementReferenceCount
|
1997-09-07 07:04:48 +02:00
|
|
|
* Increments relation reference count.
|
1996-08-28 03:59:28 +02:00
|
|
|
*/
|
2000-06-17 23:49:04 +02:00
|
|
|
#define RelationIncrementReferenceCount(relation) \
|
|
|
|
((relation)->rd_refcnt += 1)
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/*
|
1999-05-25 18:15:34 +02:00
|
|
|
* RelationDecrementReferenceCount
|
1997-09-07 07:04:48 +02:00
|
|
|
* Decrements relation reference count.
|
1996-08-28 03:59:28 +02:00
|
|
|
*/
|
2000-02-27 08:31:00 +01:00
|
|
|
#define RelationDecrementReferenceCount(relation) \
|
|
|
|
(AssertMacro((relation)->rd_refcnt > 0), \
|
|
|
|
(relation)->rd_refcnt -= 1)
|
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
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
2000-01-31 05:35:57 +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-05-25 18:15:34 +02:00
|
|
|
* RelationGetFile
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
2000-01-31 05:35:57 +01:00
|
|
|
* Returns the open file descriptor for the rel
|
1996-08-28 03:59:28 +02:00
|
|
|
*/
|
|
|
|
#define RelationGetFile(relation) ((relation)->rd_fd)
|
|
|
|
|
|
|
|
/*
|
1999-05-25 18:15:34 +02:00
|
|
|
* RelationGetRelationName
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
2000-12-23 20:55:16 +01:00
|
|
|
* Returns the relation's logical name (as seen by the user).
|
|
|
|
*
|
|
|
|
* If the rel is a temp rel, the temp name will be returned. Therefore,
|
|
|
|
* this name is not unique. But it is the name to use in heap_openr(),
|
|
|
|
* for example.
|
1996-08-28 03:59:28 +02:00
|
|
|
*/
|
1999-11-16 05:14:03 +01:00
|
|
|
#define RelationGetRelationName(relation) \
|
|
|
|
(\
|
|
|
|
(strncmp(RelationGetPhysicalRelationName(relation), \
|
2001-06-19 07:11:50 +02:00
|
|
|
"pg_temp", 7) != 0) \
|
1999-11-16 05:14:03 +01:00
|
|
|
? \
|
|
|
|
RelationGetPhysicalRelationName(relation) \
|
|
|
|
: \
|
|
|
|
get_temp_rel_by_physicalname( \
|
|
|
|
RelationGetPhysicalRelationName(relation)) \
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* RelationGetPhysicalRelationName
|
|
|
|
*
|
2000-12-23 20:55:16 +01:00
|
|
|
* Returns the rel's physical name, ie, the name appearing in pg_class.
|
|
|
|
*
|
|
|
|
* While this name is unique across all rels in the database, it is not
|
|
|
|
* necessarily useful for accessing the rel, since a temp table of the
|
|
|
|
* same name might mask the rel. It is useful mainly for determining if
|
|
|
|
* the rel is a shared system rel or not.
|
|
|
|
*
|
|
|
|
* The macro is rather unfortunately named, since the pg_class name no longer
|
|
|
|
* has anything to do with the file name used for physical storage of the rel.
|
1999-11-16 05:14:03 +01:00
|
|
|
*/
|
2000-06-17 23:49:04 +02:00
|
|
|
#define RelationGetPhysicalRelationName(relation) \
|
|
|
|
(NameStr((relation)->rd_rel->relname))
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/*
|
1999-09-18 21:08:25 +02:00
|
|
|
* RelationGetNumberOfAttributes
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
1999-09-18 21:08:25 +02:00
|
|
|
* Returns the number of attributes.
|
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
|
|
|
|
2000-01-31 05:35:57 +01:00
|
|
|
/*
|
|
|
|
* RelationGetIndexStrategy
|
|
|
|
* Returns index strategy for a relation.
|
|
|
|
*
|
|
|
|
* Note:
|
|
|
|
* Assumes relation descriptor is valid.
|
|
|
|
* Assumes relation descriptor is for an index relation.
|
|
|
|
*/
|
|
|
|
#define RelationGetIndexStrategy(relation) ((relation)->rd_istrat)
|
1999-09-18 21:08:25 +02:00
|
|
|
|
2000-06-17 23:49:04 +02:00
|
|
|
/*
|
|
|
|
* Routines in utils/cache/rel.c
|
|
|
|
*/
|
2000-01-31 05:35:57 +01:00
|
|
|
extern void RelationSetIndexSupport(Relation relation,
|
2001-03-22 05:01:46 +01:00
|
|
|
IndexStrategy strategy,
|
|
|
|
RegProcedure *support);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1998-09-01 06:40:42 +02:00
|
|
|
#endif /* REL_H */
|