1996-08-28 03:59:28 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* rel.h
|
1997-09-07 07:04:48 +02:00
|
|
|
* POSTGRES relation descriptor definitions.
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
1999-11-04 09:01:09 +01:00
|
|
|
* $Id: rel.h,v 1.28 1999/11/04 08:01:09 inoue 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"
|
|
|
|
#include "storage/fd.h"
|
1996-08-28 03:59:28 +02: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;
|
|
|
|
|
|
|
|
|
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;
|
1998-01-15 20:46:37 +01:00
|
|
|
FmgrInfo tgfunc;
|
1997-09-08 04:41:22 +02:00
|
|
|
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;
|
|
|
|
int16 tgattr[8];
|
|
|
|
char **tgargs;
|
1997-09-08 23:56:23 +02:00
|
|
|
} Trigger;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
typedef struct TriggerDesc
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
uint16 n_before_statement[4];
|
|
|
|
uint16 n_before_row[4];
|
|
|
|
uint16 n_after_row[4];
|
|
|
|
uint16 n_after_statement[4];
|
|
|
|
Trigger **tg_before_statement[4];
|
|
|
|
Trigger **tg_before_row[4];
|
|
|
|
Trigger **tg_after_row[4];
|
|
|
|
Trigger **tg_after_statement[4];
|
|
|
|
Trigger *triggers;
|
1997-09-08 23:56:23 +02:00
|
|
|
} TriggerDesc;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1999-09-18 21:08:25 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct RelationData
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
File rd_fd; /* open file descriptor */
|
|
|
|
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 */
|
1999-02-02 04:45:56 +01:00
|
|
|
bool rd_isnoname; /* rel has no name */
|
1999-11-04 09:01:09 +01:00
|
|
|
bool rd_unlinked; /* rel already unlinked or not created yet */
|
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 */
|
|
|
|
LockInfoData rd_lockInfo; /* lock manager's info for locking relation */
|
|
|
|
TupleDesc rd_att; /* tuple descriptor */
|
1997-09-08 04:41:22 +02:00
|
|
|
RuleLock *rd_rules; /* rewrite rules */
|
|
|
|
IndexStrategy rd_istrat;
|
|
|
|
RegProcedure *rd_support;
|
|
|
|
TriggerDesc *trigdesc;
|
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
|
|
|
* RelationGetSystemPort
|
1997-09-07 07:04:48 +02:00
|
|
|
* Returns system port of 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
|
|
|
*/
|
|
|
|
#define RelationGetSystemPort(relation) ((relation)->rd_fd)
|
|
|
|
|
|
|
|
/*
|
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
|
|
|
*/
|
1999-09-18 21:08:25 +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
|
|
|
*/
|
1999-09-18 21:08:25 +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
|
|
|
*/
|
|
|
|
#define RelationDecrementReferenceCount(relation) ((relation)->rd_refcnt -= 1)
|
|
|
|
|
|
|
|
/*
|
1999-05-25 18:15:34 +02:00
|
|
|
* RelationGetForm
|
1997-09-07 07:04:48 +02:00
|
|
|
* Returns relation attribute values 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
|
|
|
*
|
1997-09-07 07:04:48 +02:00
|
|
|
* returns the object id 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
|
|
|
*
|
1997-09-07 07:04:48 +02:00
|
|
|
* Returns the open File decscriptor
|
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
|
|
|
*
|
1997-09-07 07:04:48 +02:00
|
|
|
* Returns a Relation Name
|
1996-08-28 03:59:28 +02:00
|
|
|
*/
|
|
|
|
#define RelationGetRelationName(relation) (&(relation)->rd_rel->relname)
|
|
|
|
|
|
|
|
/*
|
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
|
|
|
|
1999-09-18 21:08:25 +02:00
|
|
|
|
1996-08-28 03:59:28 +02:00
|
|
|
extern IndexStrategy RelationGetIndexStrategy(Relation relation);
|
|
|
|
|
1998-09-01 06:40:42 +02:00
|
|
|
extern void RelationSetIndexSupport(Relation relation, IndexStrategy strategy,
|
1997-09-08 23:56:23 +02:00
|
|
|
RegProcedure *support);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1998-09-01 06:40:42 +02:00
|
|
|
#endif /* REL_H */
|