OSDN Git Service

More archive cleanup.
[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.14 1997/11/21 19:12:32 momjian Exp $
10  *
11  *-------------------------------------------------------------------------
12  */
13 #ifndef REL_H
14 #define REL_H
15
16 #include <catalog/pg_am.h>
17 #include <catalog/pg_class.h>
18 #include <access/strat.h>
19 #include <access/tupdesc.h>
20 #include <rewrite/prs2lock.h>
21 #include <storage/fd.h>
22
23 typedef struct Trigger
24 {
25         char       *tgname;
26         Oid                     tgfoid;
27         func_ptr        tgfunc;
28         func_ptr        tgplfunc;
29         int16           tgtype;
30         int16           tgnargs;
31         int16           tgattr[8];
32         char      **tgargs;
33 } Trigger;
34
35 typedef struct TriggerDesc
36 {
37         uint16          n_before_statement[4];
38         uint16          n_before_row[4];
39         uint16          n_after_row[4];
40         uint16          n_after_statement[4];
41         Trigger   **tg_before_statement[4];
42         Trigger   **tg_before_row[4];
43         Trigger   **tg_after_row[4];
44         Trigger   **tg_after_statement[4];
45         Trigger    *triggers;
46 } TriggerDesc;
47
48 typedef struct RelationData
49 {
50         File            rd_fd;                  /* open file descriptor */
51         int                     rd_nblocks;             /* number of blocks in rel */
52         uint16          rd_refcnt;              /* reference count */
53         bool            rd_islocal;             /* uses the local buffer mgr */
54         bool            rd_isnailed;    /* rel is nailed in cache */
55         bool            rd_istemp;              /* rel is a temp rel */
56         bool            rd_tmpunlinked; /* temp rel already unlinked */
57         Form_pg_am      rd_am;                  /* AM tuple */
58         Form_pg_class rd_rel;           /* RELATION tuple */
59         Oid                     rd_id;                  /* relations's object id */
60         Pointer         lockInfo;               /* ptr. to misc. info. */
61         TupleDesc       rd_att;                 /* tuple desciptor */
62         RuleLock   *rd_rules;           /* rewrite rules */
63         IndexStrategy rd_istrat;
64         RegProcedure *rd_support;
65         TriggerDesc *trigdesc;
66 } RelationData;
67
68 typedef RelationData *Relation;
69
70 /* ----------------
71  *              RelationPtr is used in the executor to support index scans
72  *              where we have to keep track of several index relations in an
73  *              array.  -cim 9/10/89
74  * ----------------
75  */
76 typedef Relation *RelationPtr;
77
78 #define InvalidRelation ((Relation)NULL)
79
80 /*
81  * RelationIsValid --
82  *              True iff relation descriptor is valid.
83  */
84 #define RelationIsValid(relation) PointerIsValid(relation)
85
86 /*
87  * RelationGetSystemPort --
88  *              Returns system port of a relation.
89  *
90  * Note:
91  *              Assumes relation descriptor is valid.
92  */
93 #define RelationGetSystemPort(relation) ((relation)->rd_fd)
94
95 /*
96  * RelationGetLockInfo --
97  *              Returns the lock information structure in the reldesc
98  *
99  */
100 #define RelationGetLockInfo(relation) ((relation)->lockInfo)
101
102 /*
103  * RelationHasReferenceCountZero --
104  *              True iff relation reference count is zero.
105  *
106  * Note:
107  *              Assumes relation descriptor is valid.
108  */
109 #define RelationHasReferenceCountZero(relation) \
110                 ((bool)((relation)->rd_refcnt == 0))
111
112 /*
113  * RelationSetReferenceCount --
114  *              Sets relation reference count.
115  */
116 #define RelationSetReferenceCount(relation,count) ((relation)->rd_refcnt = count)
117
118 /*
119  * RelationIncrementReferenceCount --
120  *              Increments relation reference count.
121  */
122 #define RelationIncrementReferenceCount(relation) ((relation)->rd_refcnt += 1);
123
124 /*
125  * RelationDecrementReferenceCount --
126  *              Decrements relation reference count.
127  */
128 #define RelationDecrementReferenceCount(relation) ((relation)->rd_refcnt -= 1)
129
130 /*
131  * RelationGetAccessMethodTupleForm --
132  *              Returns access method attribute values for a relation.
133  *
134  * Note:
135  *              Assumes relation descriptor is valid.
136  */
137 #define RelationGetAccessMethodTupleForm(relation) ((relation)->rd_am)
138
139 /*
140  * RelationGetRelationTupleForm --
141  *              Returns relation attribute values for a relation.
142  *
143  * Note:
144  *              Assumes relation descriptor is valid.
145  */
146 #define RelationGetRelationTupleForm(relation) ((relation)->rd_rel)
147
148
149 /*
150  * RelationGetRelationId --
151  *
152  *      returns the object id of the relation
153  *
154  */
155 #define RelationGetRelationId(relation) ((relation)->rd_id)
156
157 /*
158  * RelationGetFile --
159  *
160  *        Returns the open File decscriptor
161  */
162 #define RelationGetFile(relation) ((relation)->rd_fd)
163
164
165 /*
166  * RelationGetRelationName --
167  *
168  *        Returns a Relation Name
169  */
170 #define RelationGetRelationName(relation) (&(relation)->rd_rel->relname)
171
172 /*
173  * RelationGetRelationName --
174  *
175  *        Returns a the number of attributes.
176  */
177 #define RelationGetNumberOfAttributes(relation) ((relation)->rd_rel->relnatts)
178
179 /*
180  * RelationGetTupleDescriptor --
181  *              Returns tuple descriptor for a relation.
182  *
183  * Note:
184  *              Assumes relation descriptor is valid.
185  */
186 #define RelationGetTupleDescriptor(relation) ((relation)->rd_att)
187
188 extern IndexStrategy RelationGetIndexStrategy(Relation relation);
189
190 extern void
191 RelationSetIndexSupport(Relation relation, IndexStrategy strategy,
192                                                 RegProcedure *support);
193
194 #endif                                                  /* REL_H */