1 /*-------------------------------------------------------------------------
4 * POSTGRES heap access method definitions.
7 * Copyright (c) 1994, Regents of the University of California
9 * $Id: heapam.h,v 1.20 1997/10/30 23:37:01 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 TimeQual timeQual, 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, TimeQual timeQual,
132 ItemPointer tid, Buffer *b);
133 extern Oid heap_insert(Relation relation, HeapTuple tup);
134 extern int heap_delete(Relation relation, ItemPointer tid);
136 heap_replace(Relation relation, ItemPointer otid,
138 extern void heap_markpos(HeapScanDesc sdesc);
139 extern void heap_restrpos(HeapScanDesc sdesc);
141 /* in common/heaptuple.c */
142 extern Size ComputeDataSize(TupleDesc tupleDesc, Datum value[], char nulls[]);
144 DataFill(char *data, TupleDesc tupleDesc,
145 Datum value[], char nulls[], char *infomask,
147 extern int heap_attisnull(HeapTuple tup, int attnum);
148 extern int heap_sysattrlen(AttrNumber attno);
149 extern bool heap_sysattrbyval(AttrNumber attno);
150 extern Datum heap_getsysattr(HeapTuple tup, Buffer b, int attnum);
151 extern Datum fastgetattr(HeapTuple tup, int attnum,
152 TupleDesc att, bool *isnull);
153 extern HeapTuple heap_copytuple(HeapTuple tuple);
155 heap_formtuple(TupleDesc tupleDescriptor,
156 Datum value[], char nulls[]);
158 heap_modifytuple(HeapTuple tuple, Buffer buffer,
159 Relation relation, Datum replValue[], char replNull[], char repl[]);
160 HeapTuple heap_addheader(uint32 natts, int structlen, char *structure);
162 /* in common/heap/stats.c */
163 extern void PrintHeapAccessStatistics(HeapAccessStatistics stats);
164 extern void initam(void);
168 RelationPutHeapTuple(Relation relation, BlockNumber blockIndex,
170 extern void RelationPutHeapTupleAtEnd(Relation relation, HeapTuple tuple);
172 #endif /* HEAPAM_H */