1 /*-------------------------------------------------------------------------
4 * POSTGRES heap access method definitions.
7 * Portions Copyright (c) 1996-2003, 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.87 2004/03/11 01:47:41 ishii 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 extern Datum nocachegetattr(HeapTuple tup, int attnum,
44 TupleDesc att, bool *isnull);
46 #if !defined(DISABLE_COMPLEX_MACRO)
48 #define fastgetattr(tup, attnum, tupleDesc, isnull) \
50 AssertMacro((attnum) > 0), \
51 ((isnull) ? (*(isnull) = false) : (dummyret)NULL), \
52 HeapTupleNoNulls(tup) ? \
54 (tupleDesc)->attrs[(attnum)-1]->attcacheoff >= 0 ? \
56 fetchatt((tupleDesc)->attrs[(attnum)-1], \
57 (char *) (tup)->t_data + (tup)->t_data->t_hoff + \
58 (tupleDesc)->attrs[(attnum)-1]->attcacheoff) \
61 nocachegetattr((tup), (attnum), (tupleDesc), (isnull)) \
65 att_isnull((attnum)-1, (tup)->t_data->t_bits) ? \
67 ((isnull) ? (*(isnull) = true) : (dummyret)NULL), \
72 nocachegetattr((tup), (attnum), (tupleDesc), (isnull)) \
77 #else /* defined(DISABLE_COMPLEX_MACRO) */
79 extern Datum fastgetattr(HeapTuple tup, int attnum, TupleDesc tupleDesc,
81 #endif /* defined(DISABLE_COMPLEX_MACRO) */
87 * Extract an attribute of a heap tuple and return it as a Datum.
88 * This works for either system or user attributes. The given attnum
89 * is properly range-checked.
91 * If the field in question has a NULL value, we return a zero Datum
92 * and set *isnull == true. Otherwise, we set *isnull == false.
94 * <tup> is the pointer to the heap tuple. <attnum> is the attribute
95 * number of the column (field) caller wants. <tupleDesc> is a
96 * pointer to the structure describing the row and all its fields.
99 #define heap_getattr(tup, attnum, tupleDesc, isnull) \
101 AssertMacro((tup) != NULL), \
105 ((attnum) > (int) (tup)->t_data->t_natts) ? \
107 ((isnull) ? (*(isnull) = true) : (dummyret)NULL), \
111 fastgetattr((tup), (attnum), (tupleDesc), (isnull)) \
114 heap_getsysattr((tup), (attnum), (isnull)) \
118 extern Datum heap_getsysattr(HeapTuple tup, int attnum, bool *isnull);
122 * function prototypes for heap access method
124 * heap_create, heap_create_with_catalog, and heap_drop_with_catalog
125 * are declared in catalog/heap.h
131 extern Relation relation_open(Oid relationId, LOCKMODE lockmode);
132 extern Relation conditional_relation_open(Oid relationId, LOCKMODE lockmode, bool nowait);
133 extern Relation relation_openrv(const RangeVar *relation, LOCKMODE lockmode);
134 extern Relation relation_openr(const char *sysRelationName, 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);
139 extern Relation heap_openr(const char *sysRelationName, LOCKMODE lockmode);
141 #define heap_close(r,l) relation_close(r,l)
143 extern HeapScanDesc heap_beginscan(Relation relation, Snapshot snapshot,
144 int nkeys, ScanKey key);
145 extern void heap_rescan(HeapScanDesc scan, ScanKey key);
146 extern void heap_endscan(HeapScanDesc scan);
147 extern HeapTuple heap_getnext(HeapScanDesc scan, ScanDirection direction);
149 extern bool heap_fetch(Relation relation, Snapshot snapshot,
150 HeapTuple tuple, Buffer *userbuf, bool keep_buf,
151 PgStat_Info *pgstat_info);
153 extern ItemPointer heap_get_latest_tid(Relation relation, Snapshot snapshot,
155 extern void setLastTid(const ItemPointer tid);
157 extern Oid heap_insert(Relation relation, HeapTuple tup, CommandId cid);
158 extern int heap_delete(Relation relation, ItemPointer tid, ItemPointer ctid,
159 CommandId cid, Snapshot crosscheck, bool wait);
160 extern int heap_update(Relation relation, ItemPointer otid, HeapTuple tup,
161 ItemPointer ctid, CommandId cid, Snapshot crosscheck, bool wait);
162 extern int heap_mark4update(Relation relation, HeapTuple tup,
163 Buffer *userbuf, CommandId cid);
165 extern Oid simple_heap_insert(Relation relation, HeapTuple tup);
166 extern void simple_heap_delete(Relation relation, ItemPointer tid);
167 extern void simple_heap_update(Relation relation, ItemPointer otid,
170 extern void heap_markpos(HeapScanDesc scan);
171 extern void heap_restrpos(HeapScanDesc scan);
173 extern void heap_redo(XLogRecPtr lsn, XLogRecord *rptr);
174 extern void heap_undo(XLogRecPtr lsn, XLogRecord *rptr);
175 extern void heap_desc(char *buf, uint8 xl_info, char *rec);
176 extern XLogRecPtr log_heap_clean(Relation reln, Buffer buffer,
177 OffsetNumber *unused, int uncnt);
178 extern XLogRecPtr log_heap_move(Relation reln, Buffer oldbuf,
179 ItemPointerData from,
180 Buffer newbuf, HeapTuple newtup);
182 /* in common/heaptuple.c */
183 extern Size ComputeDataSize(TupleDesc tupleDesc, Datum *value, char *nulls);
184 extern void DataFill(char *data, TupleDesc tupleDesc,
185 Datum *value, char *nulls, uint16 *infomask,
187 extern int heap_attisnull(HeapTuple tup, int attnum);
188 extern Datum nocachegetattr(HeapTuple tup, int attnum,
189 TupleDesc att, bool *isnull);
190 extern HeapTuple heap_copytuple(HeapTuple tuple);
191 extern void heap_copytuple_with_tuple(HeapTuple src, HeapTuple dest);
192 extern HeapTuple heap_formtuple(TupleDesc tupleDescriptor,
193 Datum *value, char *nulls);
194 extern HeapTuple heap_modifytuple(HeapTuple tuple,
195 Relation relation, Datum *replValue, char *replNull, char *repl);
196 extern void heap_freetuple(HeapTuple tuple);
197 extern HeapTuple heap_addheader(int natts, bool withoid, Size structlen, void *structure);
199 #endif /* HEAPAM_H */