1 /*-------------------------------------------------------------------------
4 * POSTGRES relation descriptor definitions.
7 * Copyright (c) 1994, Regents of the University of California
9 * $Id: rel.h,v 1.27 1999/09/29 16:06:28 wieck Exp $
11 *-------------------------------------------------------------------------
16 #include "access/strat.h"
17 #include "access/tupdesc.h"
18 #include "catalog/pg_am.h"
19 #include "catalog/pg_class.h"
20 #include "rewrite/prs2lock.h"
21 #include "storage/fd.h"
25 * LockRelId and LockInfo really belong to lmgr.h, but it's more convenient
26 * to declare them here so we can have a LockInfoData field in a Relation.
29 typedef struct LockRelId
31 Oid relId; /* a relation identifier */
32 Oid dbId; /* a database identifier */
35 typedef struct LockInfoData
40 typedef LockInfoData *LockInfo;
43 typedef struct Trigger
59 typedef struct TriggerDesc
61 uint16 n_before_statement[4];
62 uint16 n_before_row[4];
63 uint16 n_after_row[4];
64 uint16 n_after_statement[4];
65 Trigger **tg_before_statement[4];
66 Trigger **tg_before_row[4];
67 Trigger **tg_after_row[4];
68 Trigger **tg_after_statement[4];
73 typedef struct RelationData
75 File rd_fd; /* open file descriptor */
76 int rd_nblocks; /* number of blocks in rel */
77 uint16 rd_refcnt; /* reference count */
78 bool rd_myxactonly; /* rel uses the local buffer mgr */
79 bool rd_isnailed; /* rel is nailed in cache */
80 bool rd_isnoname; /* rel has no name */
81 bool rd_nonameunlinked; /* noname rel already unlinked */
82 Form_pg_am rd_am; /* AM tuple */
83 Form_pg_class rd_rel; /* RELATION tuple */
84 Oid rd_id; /* relation's object id */
85 LockInfoData rd_lockInfo; /* lock manager's info for locking relation */
86 TupleDesc rd_att; /* tuple descriptor */
87 RuleLock *rd_rules; /* rewrite rules */
88 IndexStrategy rd_istrat;
89 RegProcedure *rd_support;
90 TriggerDesc *trigdesc;
93 typedef RelationData *Relation;
97 * RelationPtr is used in the executor to support index scans
98 * where we have to keep track of several index relations in an
102 typedef Relation *RelationPtr;
107 * True iff relation descriptor is valid.
109 #define RelationIsValid(relation) PointerIsValid(relation)
111 #define InvalidRelation ((Relation) NULL)
114 * RelationGetSystemPort
115 * Returns system port of a relation.
118 * Assumes relation descriptor is valid.
120 #define RelationGetSystemPort(relation) ((relation)->rd_fd)
123 * RelationHasReferenceCountZero
124 * True iff relation reference count is zero.
127 * Assumes relation descriptor is valid.
129 #define RelationHasReferenceCountZero(relation) \
130 ((bool)((relation)->rd_refcnt == 0))
133 * RelationSetReferenceCount
134 * Sets relation reference count.
136 #define RelationSetReferenceCount(relation,count) ((relation)->rd_refcnt = (count))
139 * RelationIncrementReferenceCount
140 * Increments relation reference count.
142 #define RelationIncrementReferenceCount(relation) ((relation)->rd_refcnt += 1)
145 * RelationDecrementReferenceCount
146 * Decrements relation reference count.
148 #define RelationDecrementReferenceCount(relation) ((relation)->rd_refcnt -= 1)
152 * Returns relation attribute values for a relation.
155 * Assumes relation descriptor is valid.
157 #define RelationGetForm(relation) ((relation)->rd_rel)
162 * returns the object id of the relation
165 #define RelationGetRelid(relation) ((relation)->rd_id)
170 * Returns the open File decscriptor
172 #define RelationGetFile(relation) ((relation)->rd_fd)
175 * RelationGetRelationName
177 * Returns a Relation Name
179 #define RelationGetRelationName(relation) (&(relation)->rd_rel->relname)
182 * RelationGetNumberOfAttributes
184 * Returns the number of attributes.
186 #define RelationGetNumberOfAttributes(relation) ((relation)->rd_rel->relnatts)
190 * Returns tuple descriptor for a relation.
192 #define RelationGetDescr(relation) ((relation)->rd_att)
195 extern IndexStrategy RelationGetIndexStrategy(Relation relation);
197 extern void RelationSetIndexSupport(Relation relation, IndexStrategy strategy,
198 RegProcedure *support);