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