OSDN Git Service

Reimplement nodeMaterial to use a temporary BufFile (or even memory, if the
[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.38 2000/06/18 22:44:34 tgl 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_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 */
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) \
142         ((relation)->rd_refcnt = (count))
143
144 /*
145  * RelationIncrementReferenceCount
146  *              Increments relation reference count.
147  */
148 #define RelationIncrementReferenceCount(relation) \
149         ((relation)->rd_refcnt += 1)
150
151 /*
152  * RelationDecrementReferenceCount
153  *              Decrements relation reference count.
154  */
155 #define RelationDecrementReferenceCount(relation) \
156         (AssertMacro((relation)->rd_refcnt > 0), \
157          (relation)->rd_refcnt -= 1)
158
159 /*
160  * RelationGetForm
161  *              Returns pg_class tuple for a relation.
162  *
163  * Note:
164  *              Assumes relation descriptor is valid.
165  */
166 #define RelationGetForm(relation) ((relation)->rd_rel)
167
168 /*
169  * RelationGetRelid
170  *
171  *      returns the OID of the relation
172  */
173 #define RelationGetRelid(relation) ((relation)->rd_id)
174
175 /*
176  * RelationGetFile
177  *
178  *        Returns the open file descriptor for the rel
179  */
180 #define RelationGetFile(relation) ((relation)->rd_fd)
181
182 /*
183  * RelationGetRelationName
184  *
185  *        Returns a Relation Name
186  */
187 #define RelationGetRelationName(relation) \
188 (\
189         (strncmp(RelationGetPhysicalRelationName(relation), \
190          "pg_temp.", strlen("pg_temp.")) != 0) \
191         ? \
192                 RelationGetPhysicalRelationName(relation) \
193         : \
194                 get_temp_rel_by_physicalname( \
195                         RelationGetPhysicalRelationName(relation)) \
196 )
197
198
199 /*
200  * RelationGetPhysicalRelationName
201  *
202  *        Returns a Relation Name
203  */
204 #define RelationGetPhysicalRelationName(relation) \
205         (NameStr((relation)->rd_rel->relname))
206
207 /*
208  * RelationGetNumberOfAttributes
209  *
210  *        Returns the number of attributes.
211  */
212 #define RelationGetNumberOfAttributes(relation) ((relation)->rd_rel->relnatts)
213
214 /*
215  * RelationGetDescr
216  *              Returns tuple descriptor for a relation.
217  */
218 #define RelationGetDescr(relation) ((relation)->rd_att)
219
220 /*
221  * RelationGetIndexStrategy
222  *              Returns index strategy for a relation.
223  *
224  * Note:
225  *              Assumes relation descriptor is valid.
226  *              Assumes relation descriptor is for an index relation.
227  */
228 #define RelationGetIndexStrategy(relation) ((relation)->rd_istrat)
229
230 /*
231  * Routines in utils/cache/rel.c
232  */
233 extern void RelationSetIndexSupport(Relation relation,
234                                                                         IndexStrategy strategy,
235                                                                         RegProcedure *support);
236
237 #endif   /* REL_H */