1 /*-------------------------------------------------------------------------
4 * POSTGRES heap access method definitions.
7 * Copyright (c) 1994, Regents of the University of California
9 * $Id: heapam.h,v 1.22 1997/11/20 23:23:31 momjian Exp $
11 *-------------------------------------------------------------------------
16 #include <access/htup.h>
17 #include <access/relscan.h>
18 #include <storage/block.h>
19 #include <utils/rel.h>
21 /* ----------------------------------------------------------------
22 * heap access method statistics
23 * ----------------------------------------------------------------
26 typedef struct HeapAccessStatisticsData
28 time_t init_global_timestamp; /* time global statistics started */
29 time_t local_reset_timestamp; /* last time local reset was done */
30 time_t last_request_timestamp; /* last time stats were requested */
45 int global_BufferGetRelation;
46 int global_RelationIdGetRelation;
47 int global_RelationIdGetRelation_Buf;
48 int global_RelationNameGetRelation;
49 int global_getreldesc;
50 int global_heapgettup;
51 int global_RelationPutHeapTuple;
52 int global_RelationPutLongHeapTuple;
67 int local_BufferGetRelation;
68 int local_RelationIdGetRelation;
69 int local_RelationIdGetRelation_Buf;
70 int local_RelationNameGetRelation;
73 int local_RelationPutHeapTuple;
74 int local_RelationPutLongHeapTuple;
75 } HeapAccessStatisticsData;
77 typedef HeapAccessStatisticsData *HeapAccessStatistics;
79 #define IncrHeapAccessStat(x) \
80 (heap_access_stats == NULL ? 0 : (heap_access_stats->x)++)
85 * Find a particular field in a row represented as a heap tuple.
86 * We return a pointer into that heap tuple, which points to the
87 * first byte of the value of the field in question.
89 * If the field in question has a NULL value, we return a null
90 * pointer and return <*isnull> == true. Otherwise, we return
93 * <tup> is the pointer to the heap tuple. <attnum> is the attribute
94 * number of the column (field) caller wants. <tupleDesc> is a
95 * pointer to the structure describing the row and all its fields.
97 * Because this macro is often called with constants, it generates
98 * compiler warnings about 'left-hand comma expression has no effect.
100 * ---------------- */
101 #define heap_getattr(tup, b, attnum, tupleDesc, isnull) \
102 (AssertMacro((tup) != NULL) ? \
103 ((attnum) > (int) (tup)->t_natts) ? \
104 (((isnull) ? (*(isnull) = true) : (void)NULL), (Datum)NULL) : \
106 fastgetattr((tup), (attnum), (tupleDesc), (isnull)) : \
107 (((isnull) ? (*(isnull) = false) : (void)NULL), heap_getsysattr((tup), (b), (attnum))) : \
110 extern HeapAccessStatistics heap_access_stats; /* in stats.c */
113 * function prototypes for heap access method
116 /* heap_create, heap_creatr, and heap_destroy are declared in catalog/heap.h */
119 extern void doinsert(Relation relation, HeapTuple tup);
121 extern Relation heap_open(Oid relationId);
122 extern Relation heap_openr(char *relationName);
123 extern void heap_close(Relation relation);
125 heap_beginscan(Relation relation, int atend,
126 bool seeself, unsigned nkeys, ScanKey key);
127 extern void heap_rescan(HeapScanDesc sdesc, bool scanFromEnd, ScanKey key);
128 extern void heap_endscan(HeapScanDesc sdesc);
129 extern HeapTuple heap_getnext(HeapScanDesc scandesc, int backw, Buffer *b);
131 heap_fetch(Relation relation, bool seeself, ItemPointer tid, Buffer *b);
132 extern Oid heap_insert(Relation relation, HeapTuple tup);
133 extern int heap_delete(Relation relation, ItemPointer tid);
135 heap_replace(Relation relation, ItemPointer otid,
137 extern void heap_markpos(HeapScanDesc sdesc);
138 extern void heap_restrpos(HeapScanDesc sdesc);
140 /* in common/heaptuple.c */
141 extern Size ComputeDataSize(TupleDesc tupleDesc, Datum value[], char nulls[]);
143 DataFill(char *data, TupleDesc tupleDesc,
144 Datum value[], char nulls[], uint16 *infomask,
146 extern int heap_attisnull(HeapTuple tup, int attnum);
147 extern int heap_sysattrlen(AttrNumber attno);
148 extern bool heap_sysattrbyval(AttrNumber attno);
149 extern Datum heap_getsysattr(HeapTuple tup, Buffer b, int attnum);
150 extern Datum fastgetattr(HeapTuple tup, int attnum,
151 TupleDesc att, bool *isnull);
152 extern HeapTuple heap_copytuple(HeapTuple tuple);
154 heap_formtuple(TupleDesc tupleDescriptor,
155 Datum value[], char nulls[]);
157 heap_modifytuple(HeapTuple tuple, Buffer buffer,
158 Relation relation, Datum replValue[], char replNull[], char repl[]);
159 HeapTuple heap_addheader(uint32 natts, int structlen, char *structure);
161 /* in common/heap/stats.c */
162 extern void PrintHeapAccessStatistics(HeapAccessStatistics stats);
163 extern void initam(void);
167 RelationPutHeapTuple(Relation relation, BlockNumber blockIndex,
169 extern void RelationPutHeapTupleAtEnd(Relation relation, HeapTuple tuple);
171 #endif /* HEAPAM_H */