~vcs-imports/mammoth-replicator/trunk

« back to all changes in this revision

Viewing changes to src/include/utils/rel.h

  • Committer: alvherre
  • Date: 2005-12-16 21:24:52 UTC
  • Revision ID: svn-v4:db760fc0-0f08-0410-9d63-cc6633f64896:trunk:1
Initial import of the REL8_0_3 sources from the Pgsql CVS repository.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*-------------------------------------------------------------------------
 
2
 *
 
3
 * rel.h
 
4
 *        POSTGRES relation descriptor (a/k/a relcache entry) definitions.
 
5
 *
 
6
 *
 
7
 * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
 
8
 * Portions Copyright (c) 1994, Regents of the University of California
 
9
 *
 
10
 * $PostgreSQL: pgsql/src/include/utils/rel.h,v 1.82 2005-01-10 20:02:24 tgl Exp $
 
11
 *
 
12
 *-------------------------------------------------------------------------
 
13
 */
 
14
#ifndef REL_H
 
15
#define REL_H
 
16
 
 
17
#include "access/tupdesc.h"
 
18
#include "catalog/pg_am.h"
 
19
#include "catalog/pg_class.h"
 
20
#include "catalog/pg_index.h"
 
21
#include "rewrite/prs2lock.h"
 
22
#include "storage/block.h"
 
23
#include "storage/relfilenode.h"
 
24
 
 
25
 
 
26
/*
 
27
 * LockRelId and LockInfo really belong to lmgr.h, but it's more convenient
 
28
 * to declare them here so we can have a LockInfoData field in a Relation.
 
29
 */
 
30
 
 
31
typedef struct LockRelId
 
32
{
 
33
        Oid                     relId;                  /* a relation identifier */
 
34
        Oid                     dbId;                   /* a database identifier */
 
35
} LockRelId;
 
36
 
 
37
typedef struct LockInfoData
 
38
{
 
39
        LockRelId       lockRelId;
 
40
} LockInfoData;
 
41
 
 
42
typedef LockInfoData *LockInfo;
 
43
 
 
44
/*
 
45
 * Likewise, this struct really belongs to trigger.h, but for convenience
 
46
 * we put it here.
 
47
 */
 
48
typedef struct Trigger
 
49
{
 
50
        Oid                     tgoid;                  /* OID of trigger (pg_trigger row) */
 
51
        /* Remaining fields are copied from pg_trigger, see pg_trigger.h */
 
52
        char       *tgname;
 
53
        Oid                     tgfoid;
 
54
        int16           tgtype;
 
55
        bool            tgenabled;
 
56
        bool            tgisconstraint;
 
57
        Oid                     tgconstrrelid;
 
58
        bool            tgdeferrable;
 
59
        bool            tginitdeferred;
 
60
        int16           tgnargs;
 
61
        int16           tgattr[FUNC_MAX_ARGS];
 
62
        char      **tgargs;
 
63
} Trigger;
 
64
 
 
65
typedef struct TriggerDesc
 
66
{
 
67
        /*
 
68
         * Index data to identify which triggers are which.  Since each
 
69
         * trigger can appear in more than one class, for each class we
 
70
         * provide a list of integer indexes into the triggers array.
 
71
         */
 
72
#define TRIGGER_NUM_EVENT_CLASSES  3
 
73
 
 
74
        uint16          n_before_statement[TRIGGER_NUM_EVENT_CLASSES];
 
75
        uint16          n_before_row[TRIGGER_NUM_EVENT_CLASSES];
 
76
        uint16          n_after_row[TRIGGER_NUM_EVENT_CLASSES];
 
77
        uint16          n_after_statement[TRIGGER_NUM_EVENT_CLASSES];
 
78
        int                *tg_before_statement[TRIGGER_NUM_EVENT_CLASSES];
 
79
        int                *tg_before_row[TRIGGER_NUM_EVENT_CLASSES];
 
80
        int                *tg_after_row[TRIGGER_NUM_EVENT_CLASSES];
 
81
        int                *tg_after_statement[TRIGGER_NUM_EVENT_CLASSES];
 
82
 
 
83
        /* The actual array of triggers is here */
 
84
        Trigger    *triggers;
 
85
        int                     numtriggers;
 
86
} TriggerDesc;
 
87
 
 
88
 
 
89
/*
 
90
 * Same for the statistics collector data in Relation and scan data.
 
91
 */
 
92
typedef struct PgStat_Info
 
93
{
 
94
        void       *tabentry;
 
95
        bool            no_stats;
 
96
        bool            heap_scan_counted;
 
97
        bool            index_scan_counted;
 
98
} PgStat_Info;
 
99
 
 
100
 
 
101
/*
 
102
 * Here are the contents of a relation cache entry.
 
103
 */
 
104
 
 
105
typedef struct RelationData
 
106
{
 
107
        RelFileNode rd_node;            /* relation physical identifier */
 
108
        /* use "struct" here to avoid needing to include smgr.h: */
 
109
        struct SMgrRelationData *rd_smgr;       /* cached file handle, or NULL */
 
110
        BlockNumber rd_targblock;       /* current insertion target block, or
 
111
                                                                 * InvalidBlockNumber */
 
112
        int                     rd_refcnt;              /* reference count */
 
113
        bool            rd_istemp;              /* rel uses the local buffer mgr */
 
114
        bool            rd_isnailed;    /* rel is nailed in cache */
 
115
        bool            rd_isvalid;             /* relcache entry is valid */
 
116
        char            rd_indexvalid;  /* state of rd_indexlist: 0 = not valid, 1
 
117
                                                                 * = valid, 2 = temporarily forced */
 
118
        SubTransactionId rd_createSubid;        /* rel was created in current xact */
 
119
 
 
120
        /*
 
121
         * rd_createSubid is the ID of the highest subtransaction the rel has
 
122
         * survived into; or zero if the rel was not created in the current
 
123
         * top transaction.  This should be relied on only for optimization
 
124
         * purposes; it is possible for new-ness to be "forgotten" (eg, after
 
125
         * CLUSTER).
 
126
         */
 
127
        Form_pg_class rd_rel;           /* RELATION tuple */
 
128
        TupleDesc       rd_att;                 /* tuple descriptor */
 
129
        Oid                     rd_id;                  /* relation's object id */
 
130
        List       *rd_indexlist;       /* list of OIDs of indexes on relation */
 
131
        LockInfoData rd_lockInfo;       /* lock mgr's info for locking relation */
 
132
        RuleLock   *rd_rules;           /* rewrite rules */
 
133
        MemoryContext rd_rulescxt;      /* private memory cxt for rd_rules, if any */
 
134
        TriggerDesc *trigdesc;          /* Trigger info, or NULL if rel has none */
 
135
 
 
136
        /* These are non-NULL only for an index relation: */
 
137
        Form_pg_index rd_index;         /* pg_index tuple describing this index */
 
138
        struct HeapTupleData *rd_indextuple;            /* all of pg_index tuple */
 
139
        /* "struct HeapTupleData *" avoids need to include htup.h here  */
 
140
        Form_pg_am      rd_am;                  /* pg_am tuple for index's AM */
 
141
 
 
142
        /*
 
143
         * index access support info (used only for an index relation)
 
144
         *
 
145
         * Note: only default operators and support procs for each opclass are
 
146
         * cached, namely those with subtype zero.      The arrays are indexed by
 
147
         * strategy or support number, which is a sufficient identifier given
 
148
         * that restriction.
 
149
         */
 
150
        MemoryContext rd_indexcxt;      /* private memory cxt for this stuff */
 
151
        Oid                *rd_operator;        /* OIDs of index operators */
 
152
        RegProcedure *rd_support;       /* OIDs of support procedures */
 
153
        struct FmgrInfo *rd_supportinfo;        /* lookup info for support
 
154
                                                                                 * procedures */
 
155
        /* "struct FmgrInfo" avoids need to include fmgr.h here */
 
156
        List       *rd_indexprs;        /* index expression trees, if any */
 
157
        List       *rd_indpred;         /* index predicate tree, if any */
 
158
 
 
159
        /* statistics collection area */
 
160
        PgStat_Info pgstat_info;
 
161
} RelationData;
 
162
 
 
163
typedef RelationData *Relation;
 
164
 
 
165
 
 
166
/* ----------------
 
167
 *              RelationPtr is used in the executor to support index scans
 
168
 *              where we have to keep track of several index relations in an
 
169
 *              array.  -cim 9/10/89
 
170
 * ----------------
 
171
 */
 
172
typedef Relation *RelationPtr;
 
173
 
 
174
 
 
175
/*
 
176
 * RelationIsValid
 
177
 *              True iff relation descriptor is valid.
 
178
 */
 
179
#define RelationIsValid(relation) PointerIsValid(relation)
 
180
 
 
181
#define InvalidRelation ((Relation) NULL)
 
182
 
 
183
/*
 
184
 * RelationHasReferenceCountZero
 
185
 *              True iff relation reference count is zero.
 
186
 *
 
187
 * Note:
 
188
 *              Assumes relation descriptor is valid.
 
189
 */
 
190
#define RelationHasReferenceCountZero(relation) \
 
191
                ((bool)((relation)->rd_refcnt == 0))
 
192
 
 
193
/*
 
194
 * RelationGetForm
 
195
 *              Returns pg_class tuple for a relation.
 
196
 *
 
197
 * Note:
 
198
 *              Assumes relation descriptor is valid.
 
199
 */
 
200
#define RelationGetForm(relation) ((relation)->rd_rel)
 
201
 
 
202
/*
 
203
 * RelationGetRelid
 
204
 *              Returns the OID of the relation
 
205
 */
 
206
#define RelationGetRelid(relation) ((relation)->rd_id)
 
207
 
 
208
/*
 
209
 * RelationGetNumberOfAttributes
 
210
 *              Returns the number of attributes in a relation.
 
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
 * RelationGetRelationName
 
222
 *              Returns the rel's name.
 
223
 *
 
224
 * Note that the name is only unique within the containing namespace.
 
225
 */
 
226
#define RelationGetRelationName(relation) \
 
227
        (NameStr((relation)->rd_rel->relname))
 
228
 
 
229
/*
 
230
 * RelationGetNamespace
 
231
 *              Returns the rel's namespace OID.
 
232
 */
 
233
#define RelationGetNamespace(relation) \
 
234
        ((relation)->rd_rel->relnamespace)
 
235
 
 
236
/*
 
237
 * RelationOpenSmgr
 
238
 *              Open the relation at the smgr level, if not already done.
 
239
 */
 
240
#define RelationOpenSmgr(relation) \
 
241
        do { \
 
242
                if ((relation)->rd_smgr == NULL) \
 
243
                        smgrsetowner(&((relation)->rd_smgr), smgropen((relation)->rd_node)); \
 
244
        } while (0)
 
245
 
 
246
/*
 
247
 * RelationCloseSmgr
 
248
 *              Close the relation at the smgr level, if not already done.
 
249
 *
 
250
 * Note: smgrclose should unhook from owner pointer, hence the Assert.
 
251
 */
 
252
#define RelationCloseSmgr(relation) \
 
253
        do { \
 
254
                if ((relation)->rd_smgr != NULL) \
 
255
                { \
 
256
                        smgrclose((relation)->rd_smgr); \
 
257
                        Assert((relation)->rd_smgr == NULL); \
 
258
                } \
 
259
        } while (0)
 
260
 
 
261
/*
 
262
 * RELATION_IS_LOCAL
 
263
 *              If a rel is either temp or newly created in the current transaction,
 
264
 *              it can be assumed to be visible only to the current backend.
 
265
 *
 
266
 * Beware of multiple eval of argument
 
267
 */
 
268
#define RELATION_IS_LOCAL(relation) \
 
269
        ((relation)->rd_istemp || \
 
270
         (relation)->rd_createSubid != InvalidSubTransactionId)
 
271
 
 
272
/* routines in utils/cache/relcache.c */
 
273
extern void RelationIncrementReferenceCount(Relation rel);
 
274
extern void RelationDecrementReferenceCount(Relation rel);
 
275
 
 
276
#endif   /* REL_H */