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.38 2000/06/18 22:44:34 tgl 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_unlinked; /* rel already unlinked or not created yet */
94 bool rd_indexfound; /* true if rd_indexlist is valid */
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 List *rd_indexlist; /* list of OIDs of indexes on relation */
99 LockInfoData rd_lockInfo; /* lock mgr's info for locking relation */
100 TupleDesc rd_att; /* tuple descriptor */
101 RuleLock *rd_rules; /* rewrite rules */
102 IndexStrategy rd_istrat; /* info needed if rel is an index */
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) \
142 ((relation)->rd_refcnt = (count))
145 * RelationIncrementReferenceCount
146 * Increments relation reference count.
148 #define RelationIncrementReferenceCount(relation) \
149 ((relation)->rd_refcnt += 1)
152 * RelationDecrementReferenceCount
153 * Decrements relation reference count.
155 #define RelationDecrementReferenceCount(relation) \
156 (AssertMacro((relation)->rd_refcnt > 0), \
157 (relation)->rd_refcnt -= 1)
161 * Returns pg_class tuple for a relation.
164 * Assumes relation descriptor is valid.
166 #define RelationGetForm(relation) ((relation)->rd_rel)
171 * returns the OID of the relation
173 #define RelationGetRelid(relation) ((relation)->rd_id)
178 * Returns the open file descriptor for the rel
180 #define RelationGetFile(relation) ((relation)->rd_fd)
183 * RelationGetRelationName
185 * Returns a Relation Name
187 #define RelationGetRelationName(relation) \
189 (strncmp(RelationGetPhysicalRelationName(relation), \
190 "pg_temp.", strlen("pg_temp.")) != 0) \
192 RelationGetPhysicalRelationName(relation) \
194 get_temp_rel_by_physicalname( \
195 RelationGetPhysicalRelationName(relation)) \
200 * RelationGetPhysicalRelationName
202 * Returns a Relation Name
204 #define RelationGetPhysicalRelationName(relation) \
205 (NameStr((relation)->rd_rel->relname))
208 * RelationGetNumberOfAttributes
210 * Returns the number of attributes.
212 #define RelationGetNumberOfAttributes(relation) ((relation)->rd_rel->relnatts)
216 * Returns tuple descriptor for a relation.
218 #define RelationGetDescr(relation) ((relation)->rd_att)
221 * RelationGetIndexStrategy
222 * Returns index strategy for a relation.
225 * Assumes relation descriptor is valid.
226 * Assumes relation descriptor is for an index relation.
228 #define RelationGetIndexStrategy(relation) ((relation)->rd_istrat)
231 * Routines in utils/cache/rel.c
233 extern void RelationSetIndexSupport(Relation relation,
234 IndexStrategy strategy,
235 RegProcedure *support);