OSDN Git Service

Reduce size of inlining.
[pg-rex/syncrep.git] / src / include / access / heapam.h
1 /*-------------------------------------------------------------------------
2  *
3  * heapam.h--
4  *        POSTGRES heap access method definitions.
5  *
6  *
7  * Copyright (c) 1994, Regents of the University of California
8  *
9  * $Id: heapam.h,v 1.28 1998/02/01 05:38:38 momjian Exp $
10  *
11  *-------------------------------------------------------------------------
12  */
13 #ifndef HEAPAM_H
14 #define HEAPAM_H
15
16 #include <access/tupmacs.h>
17 #include <access/htup.h>
18 #include <access/relscan.h>
19 #include <storage/block.h>
20 #include <utils/rel.h>
21
22 /* ----------------------------------------------------------------
23  *                              heap access method statistics
24  * ----------------------------------------------------------------
25  */
26
27 typedef struct HeapAccessStatisticsData
28 {
29         time_t          init_global_timestamp;  /* time global statistics started */
30         time_t          local_reset_timestamp;  /* last time local reset was done */
31         time_t          last_request_timestamp; /* last time stats were requested */
32
33         int                     global_open;
34         int                     global_openr;
35         int                     global_close;
36         int                     global_beginscan;
37         int                     global_rescan;
38         int                     global_endscan;
39         int                     global_getnext;
40         int                     global_fetch;
41         int                     global_insert;
42         int                     global_delete;
43         int                     global_replace;
44         int                     global_markpos;
45         int                     global_restrpos;
46         int                     global_BufferGetRelation;
47         int                     global_RelationIdGetRelation;
48         int                     global_RelationIdGetRelation_Buf;
49         int                     global_RelationNameGetRelation;
50         int                     global_getreldesc;
51         int                     global_heapgettup;
52         int                     global_RelationPutHeapTuple;
53         int                     global_RelationPutLongHeapTuple;
54
55         int                     local_open;
56         int                     local_openr;
57         int                     local_close;
58         int                     local_beginscan;
59         int                     local_rescan;
60         int                     local_endscan;
61         int                     local_getnext;
62         int                     local_fetch;
63         int                     local_insert;
64         int                     local_delete;
65         int                     local_replace;
66         int                     local_markpos;
67         int                     local_restrpos;
68         int                     local_BufferGetRelation;
69         int                     local_RelationIdGetRelation;
70         int                     local_RelationIdGetRelation_Buf;
71         int                     local_RelationNameGetRelation;
72         int                     local_getreldesc;
73         int                     local_heapgettup;
74         int                     local_RelationPutHeapTuple;
75         int                     local_RelationPutLongHeapTuple;
76 } HeapAccessStatisticsData;
77
78 typedef HeapAccessStatisticsData *HeapAccessStatistics;
79
80 #define IncrHeapAccessStat(x) \
81         (heap_access_stats == NULL ? 0 : (heap_access_stats->x)++)
82
83 /* ----------------
84  *              fastgetattr
85  *
86  *              This gets called many times, so we macro the cacheable and NULL
87  *              lookups, and call noncachegetattr() for the rest.
88  *
89  * ----------------
90  */
91 #define fastgetattr(tup, attnum, tupleDesc, isnull) \
92 ( \
93         AssertMacro((attnum) > 0) ? \
94         ( \
95                 ((isnull) ? (*(isnull) = false) : (dummyret)NULL), \
96                 HeapTupleNoNulls(tup) ? \
97                 ( \
98                         ((tupleDesc)->attrs[(attnum)-1]->attcacheoff > 0 || \
99                          (attnum) == 1) ? \
100                         ( \
101                                 (Datum)fetchatt(&((tupleDesc)->attrs[(attnum)-1]), \
102                                         (char *) (tup) + (tup)->t_hoff + \
103                                         ( \
104                                                 ((attnum) != 1) ? \
105                                                         (tupleDesc)->attrs[(attnum)-1]->attcacheoff \
106                                                 : \
107                                                         0 \
108                                         ) \
109                                 ) \
110                         ) \
111                         : \
112                                 nocachegetattr((tup), (attnum), (tupleDesc), (isnull)) \
113                 ) \
114                 : \
115                 ( \
116                         att_isnull((attnum)-1, (tup)->t_bits) ? \
117                         ( \
118                                 ((isnull) ? (*(isnull) = true) : (dummyret)NULL), \
119                                 (Datum)NULL \
120                         ) \
121                         : \
122                         ( \
123                                 nocachegetattr((tup), (attnum), (tupleDesc), (isnull)) \
124                         ) \
125                 ) \
126         ) \
127         : \
128         ( \
129                  (Datum)NULL \
130         ) \
131 )
132
133
134         
135 /* ----------------
136  *              heap_getattr
137  *
138  *              Find a particular field in a row represented as a heap tuple.
139  *              We return a pointer into that heap tuple, which points to the
140  *              first byte of the value of the field in question.
141  *
142  *              If the field in question has a NULL value, we return a null
143  *              pointer and return <*isnull> == true.  Otherwise, we return
144  *              <*isnull> == false.
145  *
146  *              <tup> is the pointer to the heap tuple.  <attnum> is the attribute
147  *              number of the column (field) caller wants.      <tupleDesc> is a
148  *              pointer to the structure describing the row and all its fields.
149  *
150  *              Because this macro is often called with constants, it generates
151  *              compiler warnings about 'left-hand comma expression has no effect.
152  *
153  * ----------------
154  */
155 #define heap_getattr(tup, attnum, tupleDesc, isnull) \
156 ( \
157         AssertMacro((tup) != NULL && \
158                 (attnum) > FirstLowInvalidHeapAttributeNumber && \
159                 (attnum) != 0) ? \
160         ( \
161                 ((attnum) > (int) (tup)->t_natts) ? \
162                 ( \
163                         ((isnull) ? (*(isnull) = true) : (dummyret)NULL), \
164                         (Datum)NULL \
165                 ) \
166                 : \
167                 ( \
168                         ((attnum) > 0) ? \
169                         ( \
170                                 fastgetattr((tup), (attnum), (tupleDesc), (isnull)) \
171                         ) \
172                         : \
173                         ( \
174                                 ((isnull) ? (*(isnull) = false) : (dummyret)NULL), \
175                                 ((attnum) == SelfItemPointerAttributeNumber) ? \
176                                 ( \
177                                         (Datum)((char *)(tup) + \
178                                                 heap_sysoffset[-SelfItemPointerAttributeNumber-1]) \
179                                 ) \
180                                 : \
181                                 ( \
182                                         (Datum)*(unsigned int *) \
183                                                 ((char *)(tup) + heap_sysoffset[-(attnum)-1]) \
184                                 ) \
185                         ) \
186                 ) \
187         ) \
188         : \
189         ( \
190                  (Datum)NULL \
191         ) \
192 )
193
194 extern HeapAccessStatistics heap_access_stats;  /* in stats.c */
195
196 /* ----------------
197  *              function prototypes for heap access method
198  * ----------------
199  */
200 /* heap_create, heap_creatr, and heap_destroy are declared in catalog/heap.h */
201
202 /* heapam.c */
203 extern void doinsert(Relation relation, HeapTuple tup);
204
205 extern Relation heap_open(Oid relationId);
206 extern Relation heap_openr(char *relationName);
207 extern void heap_close(Relation relation);
208 extern HeapScanDesc heap_beginscan(Relation relation, int atend,
209                            bool seeself, unsigned nkeys, ScanKey key);
210 extern void heap_rescan(HeapScanDesc sdesc, bool scanFromEnd, ScanKey key);
211 extern void heap_endscan(HeapScanDesc sdesc);
212 extern HeapTuple heap_getnext(HeapScanDesc scandesc, int backw, Buffer *b);
213 extern HeapTuple heap_fetch(Relation relation, bool seeself, ItemPointer tid, Buffer *b);
214 extern Oid      heap_insert(Relation relation, HeapTuple tup);
215 extern int      heap_delete(Relation relation, ItemPointer tid);
216 extern int heap_replace(Relation relation, ItemPointer otid,
217                          HeapTuple tup);
218 extern void heap_markpos(HeapScanDesc sdesc);
219 extern void heap_restrpos(HeapScanDesc sdesc);
220
221 /* in common/heaptuple.c */
222 extern Size ComputeDataSize(TupleDesc tupleDesc, Datum value[], char nulls[]);
223 extern void DataFill(char *data, TupleDesc tupleDesc,
224                  Datum value[], char nulls[], uint16 *infomask,
225                  bits8 *bit);
226 extern int      heap_attisnull(HeapTuple tup, int attnum);
227 extern int      heap_sysattrlen(AttrNumber attno);
228 extern bool heap_sysattrbyval(AttrNumber attno);
229 extern Datum heap_getsysattr(HeapTuple tup, Buffer b, int attnum);
230 extern Datum nocachegetattr(HeapTuple tup, int attnum,
231                                                  TupleDesc att, bool *isnull);
232 extern HeapTuple heap_copytuple(HeapTuple tuple);
233 extern HeapTuple heap_formtuple(TupleDesc tupleDescriptor,
234                            Datum value[], char nulls[]);
235 extern HeapTuple heap_modifytuple(HeapTuple tuple, Buffer buffer,
236          Relation relation, Datum replValue[], char replNull[], char repl[]);
237 HeapTuple       heap_addheader(uint32 natts, int structlen, char *structure);
238
239 /* in common/heap/stats.c */
240 extern void PrintHeapAccessStatistics(HeapAccessStatistics stats);
241 extern void initam(void);
242
243 /* hio.c */
244 extern void RelationPutHeapTuple(Relation relation, BlockNumber blockIndex,
245                                          HeapTuple tuple);
246 extern void RelationPutHeapTupleAtEnd(Relation relation, HeapTuple tuple);
247
248 #endif                                                  /* HEAPAM_H */