1 /*-------------------------------------------------------------------------
4 * POSTGRES relation descriptor (a/k/a relcache entry) definitions.
7 * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * $Id: rel.h,v 1.36 2000/04/12 17:16:55 momjian Exp $
12 *-------------------------------------------------------------------------
17 #include "access/strat.h"
18 #include "access/tupdesc.h"
19 #include "catalog/pg_am.h"
20 #include "catalog/pg_class.h"
21 #include "rewrite/prs2lock.h"
22 #include "storage/fd.h"
24 /* added to prevent circular dependency. bjm 1999/11/15 */
25 extern char *get_temp_rel_by_physicalname(const char *relname);
28 * LockRelId and LockInfo really belong to lmgr.h, but it's more convenient
29 * to declare them here so we can have a LockInfoData field in a Relation.
32 typedef struct LockRelId
34 Oid relId; /* a relation identifier */
35 Oid dbId; /* a database identifier */
38 typedef struct LockInfoData
43 typedef LockInfoData *LockInfo;
46 * Likewise, this struct really belongs to trigger.h, but for convenience
50 typedef struct Trigger
62 int16 tgattr[FUNC_MAX_ARGS];
66 typedef struct TriggerDesc
68 /* index data to identify which triggers are which */
69 uint16 n_before_statement[4];
70 uint16 n_before_row[4];
71 uint16 n_after_row[4];
72 uint16 n_after_statement[4];
73 Trigger **tg_before_statement[4];
74 Trigger **tg_before_row[4];
75 Trigger **tg_after_row[4];
76 Trigger **tg_after_statement[4];
77 /* the actual array of triggers is here */
83 * Here are the contents of a relation cache entry.
86 typedef struct RelationData
88 File rd_fd; /* open file descriptor */
89 int rd_nblocks; /* number of blocks in rel */
90 uint16 rd_refcnt; /* reference count */
91 bool rd_myxactonly; /* rel uses the local buffer mgr */
92 bool rd_isnailed; /* rel is nailed in cache */
93 bool rd_isnoname; /* rel has no name */
94 bool rd_unlinked; /* rel already unlinked or not created yet */
95 Form_pg_am rd_am; /* AM tuple */
96 Form_pg_class rd_rel; /* RELATION tuple */
97 Oid rd_id; /* relation's object id */
98 LockInfoData rd_lockInfo; /* lock manager's info for locking
100 TupleDesc rd_att; /* tuple descriptor */
101 RuleLock *rd_rules; /* rewrite rules */
102 IndexStrategy rd_istrat;
103 RegProcedure *rd_support;
104 TriggerDesc *trigdesc; /* Trigger info, or NULL if rel has none */
107 typedef RelationData *Relation;
111 * RelationPtr is used in the executor to support index scans
112 * where we have to keep track of several index relations in an
113 * array. -cim 9/10/89
116 typedef Relation *RelationPtr;
121 * True iff relation descriptor is valid.
123 #define RelationIsValid(relation) PointerIsValid(relation)
125 #define InvalidRelation ((Relation) NULL)
128 * RelationHasReferenceCountZero
129 * True iff relation reference count is zero.
132 * Assumes relation descriptor is valid.
134 #define RelationHasReferenceCountZero(relation) \
135 ((bool)((relation)->rd_refcnt == 0))
138 * RelationSetReferenceCount
139 * Sets relation reference count.
141 #define RelationSetReferenceCount(relation,count) ((relation)->rd_refcnt = (count))
144 * RelationIncrementReferenceCount
145 * Increments relation reference count.
147 #define RelationIncrementReferenceCount(relation) ((relation)->rd_refcnt += 1)
150 * RelationDecrementReferenceCount
151 * Decrements relation reference count.
153 #define RelationDecrementReferenceCount(relation) \
154 (AssertMacro((relation)->rd_refcnt > 0), \
155 (relation)->rd_refcnt -= 1)
159 * Returns pg_class tuple for a relation.
162 * Assumes relation descriptor is valid.
164 #define RelationGetForm(relation) ((relation)->rd_rel)
169 * returns the OID of the relation
171 #define RelationGetRelid(relation) ((relation)->rd_id)
176 * Returns the open file descriptor for the rel
178 #define RelationGetFile(relation) ((relation)->rd_fd)
181 * RelationGetRelationName
183 * Returns a Relation Name
185 #define RelationGetRelationName(relation) \
187 (strncmp(RelationGetPhysicalRelationName(relation), \
188 "pg_temp.", strlen("pg_temp.")) != 0) \
190 RelationGetPhysicalRelationName(relation) \
192 get_temp_rel_by_physicalname( \
193 RelationGetPhysicalRelationName(relation)) \
198 * RelationGetPhysicalRelationName
200 * Returns a Relation Name
202 #define RelationGetPhysicalRelationName(relation) (NameStr((relation)->rd_rel->relname))
205 * RelationGetNumberOfAttributes
207 * Returns the number of attributes.
209 #define RelationGetNumberOfAttributes(relation) ((relation)->rd_rel->relnatts)
213 * Returns tuple descriptor for a relation.
215 #define RelationGetDescr(relation) ((relation)->rd_att)
218 * RelationGetIndexStrategy
219 * Returns index strategy for a relation.
222 * Assumes relation descriptor is valid.
223 * Assumes relation descriptor is for an index relation.
225 #define RelationGetIndexStrategy(relation) ((relation)->rd_istrat)
228 extern void RelationSetIndexSupport(Relation relation,
229 IndexStrategy strategy,
230 RegProcedure *support);