1 /*-------------------------------------------------------------------------
4 * POSTGRES heap access method definitions.
7 * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * $Id: heapam.h,v 1.78 2002/07/20 05:16:59 momjian Exp $
12 *-------------------------------------------------------------------------
17 #include "access/htup.h"
18 #include "access/relscan.h"
19 #include "access/sdir.h"
20 #include "access/tupmacs.h"
21 #include "access/xlogutils.h"
22 #include "nodes/primnodes.h"
23 #include "storage/block.h"
24 #include "storage/lmgr.h"
25 #include "utils/rel.h"
26 #include "utils/tqual.h"
28 /* ----------------------------------------------------------------
29 * leftover cruft from old statistics code
30 * ----------------------------------------------------------------
33 #define IncrHeapAccessStat(x) ((void) 0)
38 * Fetch a user attribute's value as a Datum (might be either a
39 * value, or a pointer into the data area of the tuple).
41 * This must not be used when a system attribute might be requested.
42 * Furthermore, the passed attnum MUST be valid. Use heap_getattr()
43 * instead, if in doubt.
45 * This gets called many times, so we macro the cacheable and NULL
46 * lookups, and call nocachegetattr() for the rest.
50 extern Datum nocachegetattr(HeapTuple tup, int attnum,
51 TupleDesc att, bool *isnull);
53 #if !defined(DISABLE_COMPLEX_MACRO)
55 #define fastgetattr(tup, attnum, tupleDesc, isnull) \
57 AssertMacro((attnum) > 0), \
58 ((isnull) ? (*(isnull) = false) : (dummyret)NULL), \
59 HeapTupleNoNulls(tup) ? \
61 (tupleDesc)->attrs[(attnum)-1]->attcacheoff >= 0 ? \
63 fetchatt((tupleDesc)->attrs[(attnum)-1], \
64 (char *) (tup)->t_data + (tup)->t_data->t_hoff + \
65 (tupleDesc)->attrs[(attnum)-1]->attcacheoff) \
68 nocachegetattr((tup), (attnum), (tupleDesc), (isnull)) \
72 att_isnull((attnum)-1, (tup)->t_data->t_bits) ? \
74 ((isnull) ? (*(isnull) = true) : (dummyret)NULL), \
79 nocachegetattr((tup), (attnum), (tupleDesc), (isnull)) \
84 #else /* defined(DISABLE_COMPLEX_MACRO) */
86 extern Datum fastgetattr(HeapTuple tup, int attnum, TupleDesc tupleDesc,
88 #endif /* defined(DISABLE_COMPLEX_MACRO) */
94 * Extract an attribute of a heap tuple and return it as a Datum.
95 * This works for either system or user attributes. The given attnum
96 * is properly range-checked.
98 * If the field in question has a NULL value, we return a zero Datum
99 * and set *isnull == true. Otherwise, we set *isnull == false.
101 * <tup> is the pointer to the heap tuple. <attnum> is the attribute
102 * number of the column (field) caller wants. <tupleDesc> is a
103 * pointer to the structure describing the row and all its fields.
106 #define heap_getattr(tup, attnum, tupleDesc, isnull) \
108 AssertMacro((tup) != NULL), \
112 ((attnum) > (int) (tup)->t_data->t_natts) ? \
114 ((isnull) ? (*(isnull) = true) : (dummyret)NULL), \
118 fastgetattr((tup), (attnum), (tupleDesc), (isnull)) \
121 heap_getsysattr((tup), (attnum), (isnull)) \
125 extern Datum heap_getsysattr(HeapTuple tup, int attnum, bool *isnull);
129 * function prototypes for heap access method
131 * heap_create, heap_create_with_catalog, and heap_drop_with_catalog
132 * are declared in catalog/heap.h
138 extern Relation relation_open(Oid relationId, LOCKMODE lockmode);
139 extern Relation relation_openrv(const RangeVar *relation, LOCKMODE lockmode);
140 extern Relation relation_openr(const char *sysRelationName, LOCKMODE lockmode);
141 extern void relation_close(Relation relation, LOCKMODE lockmode);
143 extern Relation heap_open(Oid relationId, LOCKMODE lockmode);
144 extern Relation heap_openrv(const RangeVar *relation, LOCKMODE lockmode);
145 extern Relation heap_openr(const char *sysRelationName, LOCKMODE lockmode);
147 #define heap_close(r,l) relation_close(r,l)
149 extern HeapScanDesc heap_beginscan(Relation relation, Snapshot snapshot,
150 int nkeys, ScanKey key);
151 extern void heap_rescan(HeapScanDesc scan, ScanKey key);
152 extern void heap_endscan(HeapScanDesc scan);
153 extern HeapTuple heap_getnext(HeapScanDesc scan, ScanDirection direction);
155 extern bool heap_fetch(Relation relation, Snapshot snapshot,
156 HeapTuple tuple, Buffer *userbuf, bool keep_buf,
157 PgStat_Info *pgstat_info);
159 extern ItemPointer heap_get_latest_tid(Relation relation, Snapshot snapshot,
161 extern void setLastTid(const ItemPointer tid);
163 extern Oid heap_insert(Relation relation, HeapTuple tup, CommandId cid);
164 extern int heap_delete(Relation relation, ItemPointer tid, ItemPointer ctid,
166 extern int heap_update(Relation relation, ItemPointer otid, HeapTuple tup,
167 ItemPointer ctid, CommandId cid);
168 extern int heap_mark4update(Relation relation, HeapTuple tup,
169 Buffer *userbuf, CommandId cid);
171 extern Oid simple_heap_insert(Relation relation, HeapTuple tup);
172 extern void simple_heap_delete(Relation relation, ItemPointer tid);
173 extern void simple_heap_update(Relation relation, ItemPointer otid,
176 extern void heap_markpos(HeapScanDesc scan);
177 extern void heap_restrpos(HeapScanDesc scan);
179 extern void heap_redo(XLogRecPtr lsn, XLogRecord *rptr);
180 extern void heap_undo(XLogRecPtr lsn, XLogRecord *rptr);
181 extern void heap_desc(char *buf, uint8 xl_info, char *rec);
182 extern XLogRecPtr log_heap_clean(Relation reln, Buffer buffer,
183 char *unused, int unlen);
184 extern XLogRecPtr log_heap_move(Relation reln, Buffer oldbuf,
185 ItemPointerData from,
186 Buffer newbuf, HeapTuple newtup);
188 /* in common/heaptuple.c */
189 extern Size ComputeDataSize(TupleDesc tupleDesc, Datum *value, char *nulls);
190 extern void DataFill(char *data, TupleDesc tupleDesc,
191 Datum *value, char *nulls, uint16 *infomask,
193 extern int heap_attisnull(HeapTuple tup, int attnum);
194 extern Datum nocachegetattr(HeapTuple tup, int attnum,
195 TupleDesc att, bool *isnull);
196 extern HeapTuple heap_copytuple(HeapTuple tuple);
197 extern void heap_copytuple_with_tuple(HeapTuple src, HeapTuple dest);
198 extern HeapTuple heap_formtuple(TupleDesc tupleDescriptor,
199 Datum *value, char *nulls);
200 extern HeapTuple heap_modifytuple(HeapTuple tuple,
201 Relation relation, Datum *replValue, char *replNull, char *repl);
202 extern void heap_freetuple(HeapTuple tuple);
203 extern HeapTuple heap_addheader(int natts, bool withoid, Size structlen, void *structure);
205 #endif /* HEAPAM_H */