OSDN Git Service

This is part #1 for of the DEFERRED CONSTRAINT TRIGGER support.
[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.27 1999/09/29 16:06:28 wieck 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 /*
25  * LockRelId and LockInfo really belong to lmgr.h, but it's more convenient
26  * to declare them here so we can have a LockInfoData field in a Relation.
27  */
28
29 typedef struct LockRelId
30 {
31         Oid                     relId;                  /* a relation identifier */
32         Oid                     dbId;                   /* a database identifier */
33 } LockRelId;
34
35 typedef struct LockInfoData
36 {
37         LockRelId       lockRelId;
38 } LockInfoData;
39
40 typedef LockInfoData *LockInfo;
41
42
43 typedef struct Trigger
44 {
45         Oid                     tgoid;
46         char       *tgname;
47         Oid                     tgfoid;
48         FmgrInfo        tgfunc;
49         int16           tgtype;
50         bool            tgenabled;
51         bool            tgisconstraint;
52         bool            tgdeferrable;
53         bool            tginitdeferred;
54         int16           tgnargs;
55         int16           tgattr[8];
56         char      **tgargs;
57 } Trigger;
58
59 typedef struct TriggerDesc
60 {
61         uint16          n_before_statement[4];
62         uint16          n_before_row[4];
63         uint16          n_after_row[4];
64         uint16          n_after_statement[4];
65         Trigger   **tg_before_statement[4];
66         Trigger   **tg_before_row[4];
67         Trigger   **tg_after_row[4];
68         Trigger   **tg_after_statement[4];
69         Trigger    *triggers;
70 } TriggerDesc;
71
72
73 typedef struct RelationData
74 {
75         File            rd_fd;                  /* open file descriptor */
76         int                     rd_nblocks;             /* number of blocks in rel */
77         uint16          rd_refcnt;              /* reference count */
78         bool            rd_myxactonly;  /* rel uses the local buffer mgr */
79         bool            rd_isnailed;    /* rel is nailed in cache */
80         bool            rd_isnoname;    /* rel has no name */
81         bool            rd_nonameunlinked;              /* noname rel already unlinked */
82         Form_pg_am      rd_am;                  /* AM tuple */
83         Form_pg_class rd_rel;           /* RELATION tuple */
84         Oid                     rd_id;                  /* relation's object id */
85         LockInfoData rd_lockInfo;       /* lock manager's info for locking relation */
86         TupleDesc       rd_att;                 /* tuple descriptor */
87         RuleLock   *rd_rules;           /* rewrite rules */
88         IndexStrategy rd_istrat;
89         RegProcedure *rd_support;
90         TriggerDesc *trigdesc;
91 } RelationData;
92
93 typedef RelationData *Relation;
94
95
96 /* ----------------
97  *              RelationPtr is used in the executor to support index scans
98  *              where we have to keep track of several index relations in an
99  *              array.  -cim 9/10/89
100  * ----------------
101  */
102 typedef Relation *RelationPtr;
103
104
105 /*
106  * RelationIsValid
107  *              True iff relation descriptor is valid.
108  */
109 #define RelationIsValid(relation) PointerIsValid(relation)
110
111 #define InvalidRelation ((Relation) NULL)
112
113 /*
114  * RelationGetSystemPort
115  *              Returns system port of a relation.
116  *
117  * Note:
118  *              Assumes relation descriptor is valid.
119  */
120 #define RelationGetSystemPort(relation) ((relation)->rd_fd)
121
122 /*
123  * RelationHasReferenceCountZero
124  *              True iff relation reference count is zero.
125  *
126  * Note:
127  *              Assumes relation descriptor is valid.
128  */
129 #define RelationHasReferenceCountZero(relation) \
130                 ((bool)((relation)->rd_refcnt == 0))
131
132 /*
133  * RelationSetReferenceCount
134  *              Sets relation reference count.
135  */
136 #define RelationSetReferenceCount(relation,count) ((relation)->rd_refcnt = (count))
137
138 /*
139  * RelationIncrementReferenceCount
140  *              Increments relation reference count.
141  */
142 #define RelationIncrementReferenceCount(relation) ((relation)->rd_refcnt += 1)
143
144 /*
145  * RelationDecrementReferenceCount
146  *              Decrements relation reference count.
147  */
148 #define RelationDecrementReferenceCount(relation) ((relation)->rd_refcnt -= 1)
149
150 /*
151  * RelationGetForm
152  *              Returns relation attribute values for a relation.
153  *
154  * Note:
155  *              Assumes relation descriptor is valid.
156  */
157 #define RelationGetForm(relation) ((relation)->rd_rel)
158
159 /*
160  * RelationGetRelid
161  *
162  *      returns the object id of the relation
163  *
164  */
165 #define RelationGetRelid(relation) ((relation)->rd_id)
166
167 /*
168  * RelationGetFile
169  *
170  *        Returns the open File decscriptor
171  */
172 #define RelationGetFile(relation) ((relation)->rd_fd)
173
174 /*
175  * RelationGetRelationName
176  *
177  *        Returns a Relation Name
178  */
179 #define RelationGetRelationName(relation) (&(relation)->rd_rel->relname)
180
181 /*
182  * RelationGetNumberOfAttributes
183  *
184  *        Returns the number of attributes.
185  */
186 #define RelationGetNumberOfAttributes(relation) ((relation)->rd_rel->relnatts)
187
188 /*
189  * RelationGetDescr
190  *              Returns tuple descriptor for a relation.
191  */
192 #define RelationGetDescr(relation) ((relation)->rd_att)
193
194
195 extern IndexStrategy RelationGetIndexStrategy(Relation relation);
196
197 extern void RelationSetIndexSupport(Relation relation, IndexStrategy strategy,
198                                                 RegProcedure *support);
199
200 #endif   /* REL_H */