1 /*-------------------------------------------------------------------------
4 * POSTGRES heap access method definitions.
7 * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * $PostgreSQL: pgsql/src/include/access/heapam.h,v 1.101 2005/06/06 17:01:24 tgl 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"
31 * Fetch a user attribute's value as a Datum (might be either a
32 * value, or a pointer into the data area of the tuple).
34 * This must not be used when a system attribute might be requested.
35 * Furthermore, the passed attnum MUST be valid. Use heap_getattr()
36 * instead, if in doubt.
38 * This gets called many times, so we macro the cacheable and NULL
39 * lookups, and call nocachegetattr() for the rest.
43 #if !defined(DISABLE_COMPLEX_MACRO)
45 #define fastgetattr(tup, attnum, tupleDesc, isnull) \
47 AssertMacro((attnum) > 0), \
48 ((isnull) ? (*(isnull) = false) : (dummyret)NULL), \
49 HeapTupleNoNulls(tup) ? \
51 (tupleDesc)->attrs[(attnum)-1]->attcacheoff >= 0 ? \
53 fetchatt((tupleDesc)->attrs[(attnum)-1], \
54 (char *) (tup)->t_data + (tup)->t_data->t_hoff + \
55 (tupleDesc)->attrs[(attnum)-1]->attcacheoff) \
58 nocachegetattr((tup), (attnum), (tupleDesc), (isnull)) \
62 att_isnull((attnum)-1, (tup)->t_data->t_bits) ? \
64 ((isnull) ? (*(isnull) = true) : (dummyret)NULL), \
69 nocachegetattr((tup), (attnum), (tupleDesc), (isnull)) \
74 #else /* defined(DISABLE_COMPLEX_MACRO) */
76 extern Datum fastgetattr(HeapTuple tup, int attnum, TupleDesc tupleDesc,
78 #endif /* defined(DISABLE_COMPLEX_MACRO) */
84 * Extract an attribute of a heap tuple and return it as a Datum.
85 * This works for either system or user attributes. The given attnum
86 * is properly range-checked.
88 * If the field in question has a NULL value, we return a zero Datum
89 * and set *isnull == true. Otherwise, we set *isnull == false.
91 * <tup> is the pointer to the heap tuple. <attnum> is the attribute
92 * number of the column (field) caller wants. <tupleDesc> is a
93 * pointer to the structure describing the row and all its fields.
96 #define heap_getattr(tup, attnum, tupleDesc, isnull) \
98 AssertMacro((tup) != NULL), \
102 ((attnum) > (int) (tup)->t_data->t_natts) ? \
104 ((isnull) ? (*(isnull) = true) : (dummyret)NULL), \
108 fastgetattr((tup), (attnum), (tupleDesc), (isnull)) \
111 heap_getsysattr((tup), (attnum), (tupleDesc), (isnull)) \
117 * function prototypes for heap access method
119 * heap_create, heap_create_with_catalog, and heap_drop_with_catalog
120 * are declared in catalog/heap.h
132 extern Relation relation_open(Oid relationId, LOCKMODE lockmode);
133 extern Relation conditional_relation_open(Oid relationId, LOCKMODE lockmode, bool nowait);
134 extern Relation relation_openrv(const RangeVar *relation, LOCKMODE lockmode);
135 extern void relation_close(Relation relation, LOCKMODE lockmode);
137 extern Relation heap_open(Oid relationId, LOCKMODE lockmode);
138 extern Relation heap_openrv(const RangeVar *relation, LOCKMODE lockmode);
140 #define heap_close(r,l) relation_close(r,l)
142 extern HeapScanDesc heap_beginscan(Relation relation, Snapshot snapshot,
143 int nkeys, ScanKey key);
144 extern void heap_rescan(HeapScanDesc scan, ScanKey key);
145 extern void heap_endscan(HeapScanDesc scan);
146 extern HeapTuple heap_getnext(HeapScanDesc scan, ScanDirection direction);
148 extern bool heap_fetch(Relation relation, Snapshot snapshot,
149 HeapTuple tuple, Buffer *userbuf, bool keep_buf,
150 PgStat_Info *pgstat_info);
151 extern bool heap_release_fetch(Relation relation, Snapshot snapshot,
152 HeapTuple tuple, Buffer *userbuf, bool keep_buf,
153 PgStat_Info *pgstat_info);
155 extern ItemPointer heap_get_latest_tid(Relation relation, Snapshot snapshot,
157 extern void setLastTid(const ItemPointer tid);
159 extern Oid heap_insert(Relation relation, HeapTuple tup, CommandId cid);
160 extern HTSU_Result heap_delete(Relation relation, ItemPointer tid, ItemPointer ctid,
161 CommandId cid, Snapshot crosscheck, bool wait);
162 extern HTSU_Result heap_update(Relation relation, ItemPointer otid, HeapTuple tup,
163 ItemPointer ctid, CommandId cid, Snapshot crosscheck, bool wait);
164 extern HTSU_Result heap_lock_tuple(Relation relation, HeapTuple tup,
165 Buffer *userbuf, CommandId cid, LockTupleMode mode);
167 extern Oid simple_heap_insert(Relation relation, HeapTuple tup);
168 extern void simple_heap_delete(Relation relation, ItemPointer tid);
169 extern void simple_heap_update(Relation relation, ItemPointer otid,
172 extern void heap_markpos(HeapScanDesc scan);
173 extern void heap_restrpos(HeapScanDesc scan);
175 extern void heap_redo(XLogRecPtr lsn, XLogRecord *rptr);
176 extern void heap_desc(char *buf, uint8 xl_info, char *rec);
177 extern XLogRecPtr log_heap_clean(Relation reln, Buffer buffer,
178 OffsetNumber *unused, int uncnt);
179 extern XLogRecPtr log_heap_move(Relation reln, Buffer oldbuf,
180 ItemPointerData from,
181 Buffer newbuf, HeapTuple newtup);
183 /* in common/heaptuple.c */
184 extern Size heap_compute_data_size(TupleDesc tupleDesc,
185 Datum *values, bool *isnull);
186 extern void heap_fill_tuple(TupleDesc tupleDesc,
187 Datum *values, bool *isnull,
188 char *data, uint16 *infomask, bits8 *bit);
189 extern bool heap_attisnull(HeapTuple tup, int attnum);
190 extern Datum nocachegetattr(HeapTuple tup, int attnum,
191 TupleDesc att, bool *isnull);
192 extern Datum heap_getsysattr(HeapTuple tup, int attnum, TupleDesc tupleDesc,
194 extern HeapTuple heap_copytuple(HeapTuple tuple);
195 extern void heap_copytuple_with_tuple(HeapTuple src, HeapTuple dest);
196 extern HeapTuple heap_form_tuple(TupleDesc tupleDescriptor,
197 Datum *values, bool *isnull);
198 extern HeapTuple heap_formtuple(TupleDesc tupleDescriptor,
199 Datum *values, char *nulls);
200 extern HeapTuple heap_modify_tuple(HeapTuple tuple,
205 extern HeapTuple heap_modifytuple(HeapTuple tuple,
210 extern void heap_deform_tuple(HeapTuple tuple, TupleDesc tupleDesc,
211 Datum *values, bool *isnull);
212 extern void heap_deformtuple(HeapTuple tuple, TupleDesc tupleDesc,
213 Datum *values, char *nulls);
214 extern void heap_freetuple(HeapTuple tuple);
215 extern HeapTuple heap_addheader(int natts, bool withoid,
216 Size structlen, void *structure);
218 #endif /* HEAPAM_H */