1 /*-------------------------------------------------------------------------
4 * POSTGRES heap access method definitions.
7 * Copyright (c) 1994, Regents of the University of California
9 * $Id: heapam.h,v 1.39 1998/11/27 19:33:31 vadim Exp $
11 *-------------------------------------------------------------------------
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 #include <utils/tqual.h>
23 /* ----------------------------------------------------------------
24 * heap access method statistics
25 * ----------------------------------------------------------------
28 typedef struct HeapAccessStatisticsData
30 time_t init_global_timestamp; /* time global statistics started */
31 time_t local_reset_timestamp; /* last time local reset was done */
32 time_t last_request_timestamp; /* last time stats were requested */
47 int global_BufferGetRelation;
48 int global_RelationIdGetRelation;
49 int global_RelationIdGetRelation_Buf;
50 int global_RelationNameGetRelation;
51 int global_getreldesc;
52 int global_heapgettup;
53 int global_RelationPutHeapTuple;
54 int global_RelationPutLongHeapTuple;
69 int local_BufferGetRelation;
70 int local_RelationIdGetRelation;
71 int local_RelationIdGetRelation_Buf;
72 int local_RelationNameGetRelation;
75 int local_RelationPutHeapTuple;
76 int local_RelationPutLongHeapTuple;
77 } HeapAccessStatisticsData;
79 typedef HeapAccessStatisticsData *HeapAccessStatistics;
81 #define IncrHeapAccessStat(x) \
82 (heap_access_stats == NULL ? 0 : (heap_access_stats->x)++)
87 * This gets called many times, so we macro the cacheable and NULL
88 * lookups, and call noncachegetattr() for the rest.
93 extern Datum nocachegetattr(HeapTuple tup, int attnum,
94 TupleDesc att, bool *isnull);
96 #if !defined(DISABLE_COMPLEX_MACRO)
98 #define fastgetattr(tup, attnum, tupleDesc, isnull) \
100 AssertMacro((attnum) > 0), \
101 ((isnull) ? (*(isnull) = false) : (dummyret)NULL), \
102 HeapTupleNoNulls(tup) ? \
104 ((tupleDesc)->attrs[(attnum)-1]->attcacheoff != -1 || \
107 (Datum)fetchatt(&((tupleDesc)->attrs[(attnum)-1]), \
108 (char *) (tup)->t_data + (tup)->t_data->t_hoff + \
111 (tupleDesc)->attrs[(attnum)-1]->attcacheoff \
118 nocachegetattr((tup), (attnum), (tupleDesc), (isnull)) \
122 att_isnull((attnum)-1, (tup)->t_data->t_bits) ? \
124 ((isnull) ? (*(isnull) = true) : (dummyret)NULL), \
129 nocachegetattr((tup), (attnum), (tupleDesc), (isnull)) \
134 #else /* !defined(DISABLE_COMPLEX_MACRO) */
137 fastgetattr(HeapTuple tup, int attnum, TupleDesc tupleDesc,
143 ((isnull) ? (*(isnull) = false) : (dummyret) NULL),
144 HeapTupleNoNulls(tup) ?
146 ((tupleDesc)->attrs[(attnum) - 1]->attcacheoff != -1 ||
149 (Datum) fetchatt(&((tupleDesc)->attrs[(attnum) - 1]),
150 (char *) (tup)->t_data + (tup)->t_data->t_hoff +
153 (tupleDesc)->attrs[(attnum) - 1]->attcacheoff
160 nocachegetattr((tup), (attnum), (tupleDesc), (isnull))
164 att_isnull((attnum) - 1, (tup)->t_data->t_bits) ?
166 ((isnull) ? (*(isnull) = true) : (dummyret) NULL),
171 nocachegetattr((tup), (attnum), (tupleDesc), (isnull))
187 * Find a particular field in a row represented as a heap tuple.
188 * We return a pointer into that heap tuple, which points to the
189 * first byte of the value of the field in question.
191 * If the field in question has a NULL value, we return a null
192 * pointer and return <*isnull> == true. Otherwise, we return
193 * <*isnull> == false.
195 * <tup> is the pointer to the heap tuple. <attnum> is the attribute
196 * number of the column (field) caller wants. <tupleDesc> is a
197 * pointer to the structure describing the row and all its fields.
199 * Because this macro is often called with constants, it generates
200 * compiler warnings about 'left-hand comma expression has no effect.
204 #define heap_getattr(tup, attnum, tupleDesc, isnull) \
206 AssertMacro((tup) != NULL && \
207 (attnum) > FirstLowInvalidHeapAttributeNumber && \
209 ((attnum) > (int) (tup)->t_data->t_natts) ? \
211 ((isnull) ? (*(isnull) = true) : (dummyret)NULL), \
218 fastgetattr((tup), (attnum), (tupleDesc), (isnull)) \
222 ((isnull) ? (*(isnull) = false) : (dummyret)NULL), \
223 ((attnum) == SelfItemPointerAttributeNumber) ? \
225 (Datum)((char *)&((tup)->t_self)) \
229 (Datum)*(unsigned int *) \
230 ((char *)(tup)->t_data + heap_sysoffset[-(attnum)-1]) \
236 extern HeapAccessStatistics heap_access_stats; /* in stats.c */
239 * function prototypes for heap access method
242 /* heap_create, heap_creatr, and heap_destroy are declared in catalog/heap.h */
246 extern Relation heap_open(Oid relationId);
247 extern Relation heap_openr(char *relationName);
248 extern void heap_close(Relation relation);
249 extern HeapScanDesc heap_beginscan(Relation relation, int atend,
250 Snapshot snapshot, unsigned nkeys, ScanKey key);
251 extern void heap_rescan(HeapScanDesc scan, bool scanFromEnd, ScanKey key);
252 extern void heap_endscan(HeapScanDesc scan);
253 extern HeapTuple heap_getnext(HeapScanDesc scandesc, int backw);
254 extern void heap_fetch(Relation relation, Snapshot snapshot, HeapTuple tup, Buffer *userbuf);
255 extern Oid heap_insert(Relation relation, HeapTuple tup);
256 extern int heap_delete(Relation relation, ItemPointer tid);
257 extern int heap_replace(Relation relation, ItemPointer otid,
259 extern void heap_markpos(HeapScanDesc scan);
260 extern void heap_restrpos(HeapScanDesc scan);
262 /* in common/heaptuple.c */
263 extern Size ComputeDataSize(TupleDesc tupleDesc, Datum *value, char *nulls);
264 extern void DataFill(char *data, TupleDesc tupleDesc,
265 Datum *value, char *nulls, uint16 *infomask,
267 extern int heap_attisnull(HeapTuple tup, int attnum);
268 extern int heap_sysattrlen(AttrNumber attno);
269 extern bool heap_sysattrbyval(AttrNumber attno);
270 extern Datum nocachegetattr(HeapTuple tup, int attnum,
271 TupleDesc att, bool *isnull);
272 extern HeapTuple heap_copytuple(HeapTuple tuple);
273 extern void heap_copytuple_with_tuple(HeapTuple src, HeapTuple dest);
274 extern HeapTuple heap_formtuple(TupleDesc tupleDescriptor,
275 Datum *value, char *nulls);
276 extern HeapTuple heap_modifytuple(HeapTuple tuple,
277 Relation relation, Datum *replValue, char *replNull, char *repl);
278 HeapTuple heap_addheader(uint32 natts, int structlen, char *structure);
280 /* in common/heap/stats.c */
281 extern void PrintHeapAccessStatistics(HeapAccessStatistics stats);
282 extern void initam(void);
285 extern void RelationPutHeapTuple(Relation relation, BlockNumber blockIndex,
287 extern void RelationPutHeapTupleAtEnd(Relation relation, HeapTuple tuple);
289 #endif /* HEAPAM_H */