OSDN Git Service

Commit to make clearer distinction for temp names and real names.
[pg-rex/syncrep.git] / src / include / utils / rel.h
1 /*-------------------------------------------------------------------------
2  *
3  * rel.h
4  *        POSTGRES relation descriptor definitions.
5  *
6  *
7  * Copyright (c) 1994, Regents of the University of California
8  *
9  * $Id: rel.h,v 1.30 1999/11/16 04:14:03 momjian Exp $
10  *
11  *-------------------------------------------------------------------------
12  */
13 #ifndef REL_H
14 #define REL_H
15
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"
22
23 /*
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.
26  */
27
28 typedef struct LockRelId
29 {
30         Oid                     relId;                  /* a relation identifier */
31         Oid                     dbId;                   /* a database identifier */
32 } LockRelId;
33
34 typedef struct LockInfoData
35 {
36         LockRelId       lockRelId;
37 } LockInfoData;
38
39 typedef LockInfoData *LockInfo;
40
41
42 typedef struct Trigger
43 {
44         Oid                     tgoid;
45         char       *tgname;
46         Oid                     tgfoid;
47         FmgrInfo        tgfunc;
48         int16           tgtype;
49         bool            tgenabled;
50         bool            tgisconstraint;
51         bool            tgdeferrable;
52         bool            tginitdeferred;
53         int16           tgnargs;
54         int16           tgattr[8];
55         char      **tgargs;
56 } Trigger;
57
58 typedef struct TriggerDesc
59 {
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];
68         Trigger    *triggers;
69 } TriggerDesc;
70
71
72 typedef struct RelationData
73 {
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;
90 } RelationData;
91
92 typedef RelationData *Relation;
93
94
95 /* ----------------
96  *              RelationPtr is used in the executor to support index scans
97  *              where we have to keep track of several index relations in an
98  *              array.  -cim 9/10/89
99  * ----------------
100  */
101 typedef Relation *RelationPtr;
102
103
104 /*
105  * RelationIsValid
106  *              True iff relation descriptor is valid.
107  */
108 #define RelationIsValid(relation) PointerIsValid(relation)
109
110 #define InvalidRelation ((Relation) NULL)
111
112 /*
113  * RelationGetSystemPort
114  *              Returns system port of a relation.
115  *
116  * Note:
117  *              Assumes relation descriptor is valid.
118  */
119 #define RelationGetSystemPort(relation) ((relation)->rd_fd)
120
121 /*
122  * RelationHasReferenceCountZero
123  *              True iff relation reference count is zero.
124  *
125  * Note:
126  *              Assumes relation descriptor is valid.
127  */
128 #define RelationHasReferenceCountZero(relation) \
129                 ((bool)((relation)->rd_refcnt == 0))
130
131 /*
132  * RelationSetReferenceCount
133  *              Sets relation reference count.
134  */
135 #define RelationSetReferenceCount(relation,count) ((relation)->rd_refcnt = (count))
136
137 /*
138  * RelationIncrementReferenceCount
139  *              Increments relation reference count.
140  */
141 #define RelationIncrementReferenceCount(relation) ((relation)->rd_refcnt += 1)
142
143 /*
144  * RelationDecrementReferenceCount
145  *              Decrements relation reference count.
146  */
147 #define RelationDecrementReferenceCount(relation) ((relation)->rd_refcnt -= 1)
148
149 /*
150  * RelationGetForm
151  *              Returns relation attribute values for a relation.
152  *
153  * Note:
154  *              Assumes relation descriptor is valid.
155  */
156 #define RelationGetForm(relation) ((relation)->rd_rel)
157
158 /*
159  * RelationGetRelid
160  *
161  *      returns the object id of the relation
162  *
163  */
164 #define RelationGetRelid(relation) ((relation)->rd_id)
165
166 /*
167  * RelationGetFile
168  *
169  *        Returns the open File decscriptor
170  */
171 #define RelationGetFile(relation) ((relation)->rd_fd)
172
173 /*
174  * RelationGetRelationName
175  *
176  *        Returns a Relation Name
177  */
178 /* added to prevent circular dependency.  bjm 1999/11/15 */
179 char       *get_temp_rel_by_physicalname(char *relname);
180 #define RelationGetRelationName(relation) \
181 (\
182         (strncmp(RelationGetPhysicalRelationName(relation), \
183          "pg_temp.", strlen("pg_temp.")) != 0) \
184         ? \
185                 RelationGetPhysicalRelationName(relation) \
186         : \
187                 get_temp_rel_by_physicalname( \
188                         RelationGetPhysicalRelationName(relation)) \
189 )
190
191
192 /*
193  * RelationGetPhysicalRelationName
194  *
195  *        Returns a Relation Name
196  */
197 #define RelationGetPhysicalRelationName(relation) (NameStr((relation)->rd_rel->relname))
198
199 /*
200  * RelationGetNumberOfAttributes
201  *
202  *        Returns the number of attributes.
203  */
204 #define RelationGetNumberOfAttributes(relation) ((relation)->rd_rel->relnatts)
205
206 /*
207  * RelationGetDescr
208  *              Returns tuple descriptor for a relation.
209  */
210 #define RelationGetDescr(relation) ((relation)->rd_att)
211
212
213 extern IndexStrategy RelationGetIndexStrategy(Relation relation);
214
215 extern void RelationSetIndexSupport(Relation relation, IndexStrategy strategy,
216                                                 RegProcedure *support);
217
218 #endif   /* REL_H */