1 /*-------------------------------------------------------------------------
4 * POSTGRES heap access method definitions.
7 * Copyright (c) 1994, Regents of the University of California
9 * $Id: heapam.h,v 1.13 1997/09/08 02:34:10 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 #define heap_getattr(tup, b, attnum, tupleDesc, isnull) \
98 (AssertMacro((tup) != NULL) ? \
99 ((attnum) > (int) (tup)->t_natts) ? \
100 (((isnull) ? (*(isnull) = true) : (char)NULL), (char *)NULL) : \
102 fastgetattr((tup), (attnum), (tupleDesc), (isnull)) : \
103 (((isnull) ? (*(isnull) = false) : (char)NULL), heap_getsysattr((tup), (b), (attnum))) : \
106 extern HeapAccessStatistics heap_access_stats; /* in stats.c */
109 * function prototypes for heap access method
112 /* heap_create, heap_creatr, and heap_destroy are declared in catalog/heap.h */
115 extern void doinsert(Relation relation, HeapTuple tup);
117 extern Relation heap_open(Oid relationId);
118 extern Relation heap_openr(char *relationName);
119 extern void heap_close(Relation relation);
121 heap_beginscan(Relation relation, int atend,
122 TimeQual timeQual, unsigned nkeys, ScanKey key);
123 extern void heap_rescan(HeapScanDesc sdesc, bool scanFromEnd, ScanKey key);
124 extern void heap_endscan(HeapScanDesc sdesc);
125 extern HeapTuple heap_getnext(HeapScanDesc scandesc, int backw, Buffer * b);
127 heap_fetch(Relation relation, TimeQual timeQual,
128 ItemPointer tid, Buffer * b);
129 extern Oid heap_insert(Relation relation, HeapTuple tup);
130 extern int heap_delete(Relation relation, ItemPointer tid);
132 heap_replace(Relation relation, ItemPointer otid,
134 extern void heap_markpos(HeapScanDesc sdesc);
135 extern void heap_restrpos(HeapScanDesc sdesc);
137 /* in common/heaptuple.c */
138 extern Size ComputeDataSize(TupleDesc tupleDesc, Datum value[], char nulls[]);
140 DataFill(char *data, TupleDesc tupleDesc,
141 Datum value[], char nulls[], char *infomask,
143 extern int heap_attisnull(HeapTuple tup, int attnum);
144 extern int heap_sysattrlen(AttrNumber attno);
145 extern bool heap_sysattrbyval(AttrNumber attno);
146 extern char *heap_getsysattr(HeapTuple tup, Buffer b, int attnum);
148 fastgetattr(HeapTuple tup, int attnum,
149 TupleDesc att, bool * isnull);
150 extern HeapTuple heap_copytuple(HeapTuple tuple);
152 heap_formtuple(TupleDesc tupleDescriptor,
153 Datum value[], char nulls[]);
155 heap_modifytuple(HeapTuple tuple, Buffer buffer,
156 Relation relation, Datum replValue[], char replNull[], char repl[]);
157 HeapTuple heap_addheader(uint32 natts, int structlen, char *structure);
159 /* in common/heap/stats.c */
160 extern void PrintHeapAccessStatistics(HeapAccessStatistics stats);
161 extern void initam(void);
165 RelationPutHeapTuple(Relation relation, BlockNumber blockIndex,
167 extern void RelationPutHeapTupleAtEnd(Relation relation, HeapTuple tuple);
169 #endif /* HEAPAM_H */