OSDN Git Service

Ye-old pgindent run. Same 4-space tabs.
[pg-rex/syncrep.git] / src / include / utils / rel.h
1 /*-------------------------------------------------------------------------
2  *
3  * rel.h
4  *        POSTGRES relation descriptor (a/k/a relcache entry) definitions.
5  *
6  *
7  * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * $Id: rel.h,v 1.36 2000/04/12 17:16:55 momjian Exp $
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef REL_H
15 #define REL_H
16
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"
23
24 /* added to prevent circular dependency.  bjm 1999/11/15 */
25 extern char *get_temp_rel_by_physicalname(const char *relname);
26
27 /*
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.
30  */
31
32 typedef struct LockRelId
33 {
34         Oid                     relId;                  /* a relation identifier */
35         Oid                     dbId;                   /* a database identifier */
36 } LockRelId;
37
38 typedef struct LockInfoData
39 {
40         LockRelId       lockRelId;
41 } LockInfoData;
42
43 typedef LockInfoData *LockInfo;
44
45 /*
46  * Likewise, this struct really belongs to trigger.h, but for convenience
47  * we put it here.
48  */
49
50 typedef struct Trigger
51 {
52         Oid                     tgoid;
53         char       *tgname;
54         Oid                     tgfoid;
55         FmgrInfo        tgfunc;
56         int16           tgtype;
57         bool            tgenabled;
58         bool            tgisconstraint;
59         bool            tgdeferrable;
60         bool            tginitdeferred;
61         int16           tgnargs;
62         int16           tgattr[FUNC_MAX_ARGS];
63         char      **tgargs;
64 } Trigger;
65
66 typedef struct TriggerDesc
67 {
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 */
78         Trigger    *triggers;
79         int                     numtriggers;
80 } TriggerDesc;
81
82 /*
83  * Here are the contents of a relation cache entry.
84  */
85
86 typedef struct RelationData
87 {
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
99                                                                  * relation */
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 */
105 } RelationData;
106
107 typedef RelationData *Relation;
108
109
110 /* ----------------
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
114  * ----------------
115  */
116 typedef Relation *RelationPtr;
117
118
119 /*
120  * RelationIsValid
121  *              True iff relation descriptor is valid.
122  */
123 #define RelationIsValid(relation) PointerIsValid(relation)
124
125 #define InvalidRelation ((Relation) NULL)
126
127 /*
128  * RelationHasReferenceCountZero
129  *              True iff relation reference count is zero.
130  *
131  * Note:
132  *              Assumes relation descriptor is valid.
133  */
134 #define RelationHasReferenceCountZero(relation) \
135                 ((bool)((relation)->rd_refcnt == 0))
136
137 /*
138  * RelationSetReferenceCount
139  *              Sets relation reference count.
140  */
141 #define RelationSetReferenceCount(relation,count) ((relation)->rd_refcnt = (count))
142
143 /*
144  * RelationIncrementReferenceCount
145  *              Increments relation reference count.
146  */
147 #define RelationIncrementReferenceCount(relation) ((relation)->rd_refcnt += 1)
148
149 /*
150  * RelationDecrementReferenceCount
151  *              Decrements relation reference count.
152  */
153 #define RelationDecrementReferenceCount(relation) \
154         (AssertMacro((relation)->rd_refcnt > 0), \
155          (relation)->rd_refcnt -= 1)
156
157 /*
158  * RelationGetForm
159  *              Returns pg_class tuple for a relation.
160  *
161  * Note:
162  *              Assumes relation descriptor is valid.
163  */
164 #define RelationGetForm(relation) ((relation)->rd_rel)
165
166 /*
167  * RelationGetRelid
168  *
169  *      returns the OID of the relation
170  */
171 #define RelationGetRelid(relation) ((relation)->rd_id)
172
173 /*
174  * RelationGetFile
175  *
176  *        Returns the open file descriptor for the rel
177  */
178 #define RelationGetFile(relation) ((relation)->rd_fd)
179
180 /*
181  * RelationGetRelationName
182  *
183  *        Returns a Relation Name
184  */
185 #define RelationGetRelationName(relation) \
186 (\
187         (strncmp(RelationGetPhysicalRelationName(relation), \
188          "pg_temp.", strlen("pg_temp.")) != 0) \
189         ? \
190                 RelationGetPhysicalRelationName(relation) \
191         : \
192                 get_temp_rel_by_physicalname( \
193                         RelationGetPhysicalRelationName(relation)) \
194 )
195
196
197 /*
198  * RelationGetPhysicalRelationName
199  *
200  *        Returns a Relation Name
201  */
202 #define RelationGetPhysicalRelationName(relation) (NameStr((relation)->rd_rel->relname))
203
204 /*
205  * RelationGetNumberOfAttributes
206  *
207  *        Returns the number of attributes.
208  */
209 #define RelationGetNumberOfAttributes(relation) ((relation)->rd_rel->relnatts)
210
211 /*
212  * RelationGetDescr
213  *              Returns tuple descriptor for a relation.
214  */
215 #define RelationGetDescr(relation) ((relation)->rd_att)
216
217 /*
218  * RelationGetIndexStrategy
219  *              Returns index strategy for a relation.
220  *
221  * Note:
222  *              Assumes relation descriptor is valid.
223  *              Assumes relation descriptor is for an index relation.
224  */
225 #define RelationGetIndexStrategy(relation) ((relation)->rd_istrat)
226
227
228 extern void RelationSetIndexSupport(Relation relation,
229                                                 IndexStrategy strategy,
230                                                 RegProcedure *support);
231
232 #endif   /* REL_H */