1 /*-------------------------------------------------------------------------
4 * POSTGRES heap access method definitions.
7 * Copyright (c) 1994, Regents of the University of California
9 * $Id: heapam.h,v 1.28 1998/02/01 05:38:38 momjian 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>
22 /* ----------------------------------------------------------------
23 * heap access method statistics
24 * ----------------------------------------------------------------
27 typedef struct HeapAccessStatisticsData
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 */
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;
68 int local_BufferGetRelation;
69 int local_RelationIdGetRelation;
70 int local_RelationIdGetRelation_Buf;
71 int local_RelationNameGetRelation;
74 int local_RelationPutHeapTuple;
75 int local_RelationPutLongHeapTuple;
76 } HeapAccessStatisticsData;
78 typedef HeapAccessStatisticsData *HeapAccessStatistics;
80 #define IncrHeapAccessStat(x) \
81 (heap_access_stats == NULL ? 0 : (heap_access_stats->x)++)
86 * This gets called many times, so we macro the cacheable and NULL
87 * lookups, and call noncachegetattr() for the rest.
91 #define fastgetattr(tup, attnum, tupleDesc, isnull) \
93 AssertMacro((attnum) > 0) ? \
95 ((isnull) ? (*(isnull) = false) : (dummyret)NULL), \
96 HeapTupleNoNulls(tup) ? \
98 ((tupleDesc)->attrs[(attnum)-1]->attcacheoff > 0 || \
101 (Datum)fetchatt(&((tupleDesc)->attrs[(attnum)-1]), \
102 (char *) (tup) + (tup)->t_hoff + \
105 (tupleDesc)->attrs[(attnum)-1]->attcacheoff \
112 nocachegetattr((tup), (attnum), (tupleDesc), (isnull)) \
116 att_isnull((attnum)-1, (tup)->t_bits) ? \
118 ((isnull) ? (*(isnull) = true) : (dummyret)NULL), \
123 nocachegetattr((tup), (attnum), (tupleDesc), (isnull)) \
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.
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.
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.
150 * Because this macro is often called with constants, it generates
151 * compiler warnings about 'left-hand comma expression has no effect.
155 #define heap_getattr(tup, attnum, tupleDesc, isnull) \
157 AssertMacro((tup) != NULL && \
158 (attnum) > FirstLowInvalidHeapAttributeNumber && \
161 ((attnum) > (int) (tup)->t_natts) ? \
163 ((isnull) ? (*(isnull) = true) : (dummyret)NULL), \
170 fastgetattr((tup), (attnum), (tupleDesc), (isnull)) \
174 ((isnull) ? (*(isnull) = false) : (dummyret)NULL), \
175 ((attnum) == SelfItemPointerAttributeNumber) ? \
177 (Datum)((char *)(tup) + \
178 heap_sysoffset[-SelfItemPointerAttributeNumber-1]) \
182 (Datum)*(unsigned int *) \
183 ((char *)(tup) + heap_sysoffset[-(attnum)-1]) \
194 extern HeapAccessStatistics heap_access_stats; /* in stats.c */
197 * function prototypes for heap access method
200 /* heap_create, heap_creatr, and heap_destroy are declared in catalog/heap.h */
203 extern void doinsert(Relation relation, HeapTuple tup);
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,
218 extern void heap_markpos(HeapScanDesc sdesc);
219 extern void heap_restrpos(HeapScanDesc sdesc);
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,
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);
239 /* in common/heap/stats.c */
240 extern void PrintHeapAccessStatistics(HeapAccessStatistics stats);
241 extern void initam(void);
244 extern void RelationPutHeapTuple(Relation relation, BlockNumber blockIndex,
246 extern void RelationPutHeapTupleAtEnd(Relation relation, HeapTuple tuple);
248 #endif /* HEAPAM_H */