OSDN Git Service

pgindent run.
[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-2002, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * $Id: rel.h,v 1.66 2003/08/04 00:43:32 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 "catalog/pg_index.h"
22 #include "rewrite/prs2lock.h"
23 #include "storage/block.h"
24 #include "storage/fd.h"
25 #include "storage/relfilenode.h"
26
27
28 /*
29  * LockRelId and LockInfo really belong to lmgr.h, but it's more convenient
30  * to declare them here so we can have a LockInfoData field in a Relation.
31  */
32
33 typedef struct LockRelId
34 {
35         Oid                     relId;                  /* a relation identifier */
36         Oid                     dbId;                   /* a database identifier */
37 } LockRelId;
38
39 typedef struct LockInfoData
40 {
41         LockRelId       lockRelId;
42 } LockInfoData;
43
44 typedef LockInfoData *LockInfo;
45
46 /*
47  * Likewise, this struct really belongs to trigger.h, but for convenience
48  * we put it here.
49  */
50 typedef struct Trigger
51 {
52         Oid                     tgoid;                  /* OID of trigger (pg_trigger row) */
53         /* Remaining fields are copied from pg_trigger, see pg_trigger.h */
54         char       *tgname;
55         Oid                     tgfoid;
56         int16           tgtype;
57         bool            tgenabled;
58         bool            tgisconstraint;
59         Oid                     tgconstrrelid;
60         bool            tgdeferrable;
61         bool            tginitdeferred;
62         int16           tgnargs;
63         int16           tgattr[FUNC_MAX_ARGS];
64         char      **tgargs;
65 } Trigger;
66
67 typedef struct TriggerDesc
68 {
69         /*
70          * Index data to identify which triggers are which.  Since each
71          * trigger can appear in more than one class, for each class we
72          * provide a list of integer indexes into the triggers array.
73          */
74 #define TRIGGER_NUM_EVENT_CLASSES  3
75
76         uint16          n_before_statement[TRIGGER_NUM_EVENT_CLASSES];
77         uint16          n_before_row[TRIGGER_NUM_EVENT_CLASSES];
78         uint16          n_after_row[TRIGGER_NUM_EVENT_CLASSES];
79         uint16          n_after_statement[TRIGGER_NUM_EVENT_CLASSES];
80         int                *tg_before_statement[TRIGGER_NUM_EVENT_CLASSES];
81         int                *tg_before_row[TRIGGER_NUM_EVENT_CLASSES];
82         int                *tg_after_row[TRIGGER_NUM_EVENT_CLASSES];
83         int                *tg_after_statement[TRIGGER_NUM_EVENT_CLASSES];
84
85         /* The actual array of triggers is here */
86         Trigger    *triggers;
87         int                     numtriggers;
88 } TriggerDesc;
89
90
91 /* ----------
92  * Same for the statistics collector data in Relation and scan data.
93  * ----------
94  */
95 typedef struct PgStat_Info
96 {
97         void       *tabentry;
98         bool            no_stats;
99         bool            heap_scan_counted;
100         bool            index_scan_counted;
101 } PgStat_Info;
102
103 /*
104  * Here are the contents of a relation cache entry.
105  */
106
107 typedef struct RelationData
108 {
109         File            rd_fd;                  /* open file descriptor, or -1 if none */
110         RelFileNode rd_node;            /* file node (physical identifier) */
111         BlockNumber rd_nblocks;         /* number of blocks in rel */
112         BlockNumber rd_targblock;       /* current insertion target block, or
113                                                                  * InvalidBlockNumber */
114         int                     rd_refcnt;              /* reference count */
115         bool            rd_isnew;               /* rel was created in current xact */
116
117         /*
118          * NOTE: rd_isnew should be relied on only for optimization purposes;
119          * it is possible for new-ness to be "forgotten" (eg, after CLUSTER).
120          */
121         bool            rd_istemp;              /* rel uses the local buffer mgr */
122         bool            rd_isnailed;    /* rel is nailed in cache */
123         bool            rd_indexfound;  /* true if rd_indexlist is valid */
124         Form_pg_class rd_rel;           /* RELATION tuple */
125         TupleDesc       rd_att;                 /* tuple descriptor */
126         Oid                     rd_id;                  /* relation's object id */
127         List       *rd_indexlist;       /* list of OIDs of indexes on relation */
128         LockInfoData rd_lockInfo;       /* lock mgr's info for locking relation */
129         RuleLock   *rd_rules;           /* rewrite rules */
130         MemoryContext rd_rulescxt;      /* private memory cxt for rd_rules, if any */
131         TriggerDesc *trigdesc;          /* Trigger info, or NULL if rel has none */
132
133         /* These are non-NULL only for an index relation: */
134         Form_pg_index rd_index;         /* pg_index tuple describing this index */
135         struct HeapTupleData *rd_indextuple;            /* all of pg_index tuple */
136         /* "struct HeapTupleData *" avoids need to include htup.h here  */
137         Form_pg_am      rd_am;                  /* pg_am tuple for index's AM */
138
139         /* index access support info (used only for an index relation) */
140         MemoryContext rd_indexcxt;      /* private memory cxt for this stuff */
141         IndexStrategy rd_istrat;        /* operator strategy map */
142         Oid                *rd_operator;        /* OIDs of index operators */
143         RegProcedure *rd_support;       /* OIDs of support procedures */
144         struct FmgrInfo *rd_supportinfo;        /* lookup info for support
145                                                                                  * procedures */
146         /* "struct FmgrInfo" avoids need to include fmgr.h here */
147         List       *rd_indexprs;        /* index expression trees, if any */
148         List       *rd_indpred;         /* index predicate tree, if any */
149
150         /* statistics collection area */
151         PgStat_Info pgstat_info;
152 } RelationData;
153
154 typedef RelationData *Relation;
155
156
157 /* ----------------
158  *              RelationPtr is used in the executor to support index scans
159  *              where we have to keep track of several index relations in an
160  *              array.  -cim 9/10/89
161  * ----------------
162  */
163 typedef Relation *RelationPtr;
164
165
166 /*
167  * RelationIsValid
168  *              True iff relation descriptor is valid.
169  */
170 #define RelationIsValid(relation) PointerIsValid(relation)
171
172 #define InvalidRelation ((Relation) NULL)
173
174 /*
175  * RelationHasReferenceCountZero
176  *              True iff relation reference count is zero.
177  *
178  * Note:
179  *              Assumes relation descriptor is valid.
180  */
181 #define RelationHasReferenceCountZero(relation) \
182                 ((bool)((relation)->rd_refcnt == 0))
183
184 /*
185  * RelationSetReferenceCount
186  *              Sets relation reference count.
187  */
188 #define RelationSetReferenceCount(relation,count) \
189         ((relation)->rd_refcnt = (count))
190
191 /*
192  * RelationIncrementReferenceCount
193  *              Increments relation reference count.
194  */
195 #define RelationIncrementReferenceCount(relation) \
196         ((relation)->rd_refcnt += 1)
197
198 /*
199  * RelationDecrementReferenceCount
200  *              Decrements relation reference count.
201  */
202 #define RelationDecrementReferenceCount(relation) \
203         (AssertMacro((relation)->rd_refcnt > 0), \
204          (relation)->rd_refcnt -= 1)
205
206 /*
207  * RelationGetForm
208  *              Returns pg_class tuple for a relation.
209  *
210  * Note:
211  *              Assumes relation descriptor is valid.
212  */
213 #define RelationGetForm(relation) ((relation)->rd_rel)
214
215 /*
216  * RelationGetRelid
217  *
218  *      returns the OID of the relation
219  */
220 #define RelationGetRelid(relation) ((relation)->rd_id)
221
222 /*
223  * RelationGetFile
224  *
225  *        Returns the open file descriptor for the rel
226  */
227 #define RelationGetFile(relation) ((relation)->rd_fd)
228
229 /*
230  * RelationGetNumberOfAttributes
231  *
232  *        Returns the number of attributes.
233  */
234 #define RelationGetNumberOfAttributes(relation) ((relation)->rd_rel->relnatts)
235
236 /*
237  * RelationGetDescr
238  *              Returns tuple descriptor for a relation.
239  */
240 #define RelationGetDescr(relation) ((relation)->rd_att)
241
242 /*
243  * RelationGetIndexStrategy
244  *              Returns index strategy for a relation.
245  *
246  * Note:
247  *              Assumes relation descriptor is valid.
248  *              Assumes relation descriptor is for an index relation.
249  */
250 #define RelationGetIndexStrategy(relation) ((relation)->rd_istrat)
251
252 /*
253  * RelationGetRelationName
254  *
255  *        Returns the rel's name.
256  *
257  * Note that the name is only unique within the containing namespace.
258  */
259 #define RelationGetRelationName(relation) \
260         (NameStr((relation)->rd_rel->relname))
261
262 /*
263  * RelationGetNamespace
264  *
265  *        Returns the rel's namespace OID.
266  */
267 #define RelationGetNamespace(relation) \
268         ((relation)->rd_rel->relnamespace)
269
270 #endif   /* REL_H */