1 /*-------------------------------------------------------------------------
4 * POSTGRES relation descriptor definitions.
7 * Copyright (c) 1994, Regents of the University of California
9 * $Id: rel.h,v 1.31 2000/01/10 17:14:44 momjian 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"
24 * LockRelId and LockInfo really belong to lmgr.h, but it's more convenient
25 * to declare them here so we can have a LockInfoData field in a Relation.
28 typedef struct LockRelId
30 Oid relId; /* a relation identifier */
31 Oid dbId; /* a database identifier */
34 typedef struct LockInfoData
39 typedef LockInfoData *LockInfo;
42 typedef struct Trigger
54 int16 tgattr[FUNC_MAX_ARGS];
58 typedef struct TriggerDesc
60 uint16 n_before_statement[4];
61 uint16 n_before_row[4];
62 uint16 n_after_row[4];
63 uint16 n_after_statement[4];
64 Trigger **tg_before_statement[4];
65 Trigger **tg_before_row[4];
66 Trigger **tg_after_row[4];
67 Trigger **tg_after_statement[4];
72 typedef struct RelationData
74 File rd_fd; /* open file descriptor */
75 int rd_nblocks; /* number of blocks in rel */
76 uint16 rd_refcnt; /* reference count */
77 bool rd_myxactonly; /* rel uses the local buffer mgr */
78 bool rd_isnailed; /* rel is nailed in cache */
79 bool rd_isnoname; /* rel has no name */
80 bool rd_unlinked; /* rel already unlinked or not created yet */
81 Form_pg_am rd_am; /* AM tuple */
82 Form_pg_class rd_rel; /* RELATION tuple */
83 Oid rd_id; /* relation's object id */
84 LockInfoData rd_lockInfo; /* lock manager's info for locking relation */
85 TupleDesc rd_att; /* tuple descriptor */
86 RuleLock *rd_rules; /* rewrite rules */
87 IndexStrategy rd_istrat;
88 RegProcedure *rd_support;
89 TriggerDesc *trigdesc;
92 typedef RelationData *Relation;
96 * RelationPtr is used in the executor to support index scans
97 * where we have to keep track of several index relations in an
101 typedef Relation *RelationPtr;
106 * True iff relation descriptor is valid.
108 #define RelationIsValid(relation) PointerIsValid(relation)
110 #define InvalidRelation ((Relation) NULL)
113 * RelationGetSystemPort
114 * Returns system port of a relation.
117 * Assumes relation descriptor is valid.
119 #define RelationGetSystemPort(relation) ((relation)->rd_fd)
122 * RelationHasReferenceCountZero
123 * True iff relation reference count is zero.
126 * Assumes relation descriptor is valid.
128 #define RelationHasReferenceCountZero(relation) \
129 ((bool)((relation)->rd_refcnt == 0))
132 * RelationSetReferenceCount
133 * Sets relation reference count.
135 #define RelationSetReferenceCount(relation,count) ((relation)->rd_refcnt = (count))
138 * RelationIncrementReferenceCount
139 * Increments relation reference count.
141 #define RelationIncrementReferenceCount(relation) ((relation)->rd_refcnt += 1)
144 * RelationDecrementReferenceCount
145 * Decrements relation reference count.
147 #define RelationDecrementReferenceCount(relation) ((relation)->rd_refcnt -= 1)
151 * Returns relation attribute values for a relation.
154 * Assumes relation descriptor is valid.
156 #define RelationGetForm(relation) ((relation)->rd_rel)
161 * returns the object id of the relation
164 #define RelationGetRelid(relation) ((relation)->rd_id)
169 * Returns the open File decscriptor
171 #define RelationGetFile(relation) ((relation)->rd_fd)
174 * RelationGetRelationName
176 * Returns a Relation Name
178 /* added to prevent circular dependency. bjm 1999/11/15 */
179 char *get_temp_rel_by_physicalname(char *relname);
180 #define RelationGetRelationName(relation) \
182 (strncmp(RelationGetPhysicalRelationName(relation), \
183 "pg_temp.", strlen("pg_temp.")) != 0) \
185 RelationGetPhysicalRelationName(relation) \
187 get_temp_rel_by_physicalname( \
188 RelationGetPhysicalRelationName(relation)) \
193 * RelationGetPhysicalRelationName
195 * Returns a Relation Name
197 #define RelationGetPhysicalRelationName(relation) (NameStr((relation)->rd_rel->relname))
200 * RelationGetNumberOfAttributes
202 * Returns the number of attributes.
204 #define RelationGetNumberOfAttributes(relation) ((relation)->rd_rel->relnatts)
208 * Returns tuple descriptor for a relation.
210 #define RelationGetDescr(relation) ((relation)->rd_att)
213 extern IndexStrategy RelationGetIndexStrategy(Relation relation);
215 extern void RelationSetIndexSupport(Relation relation, IndexStrategy strategy,
216 RegProcedure *support);