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.93 2004-12-31 22:03:21 pgsql 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), (tupleDesc), (isnull)) \
118
extern Datum heap_getsysattr(HeapTuple tup, int attnum, TupleDesc tupleDesc,
123
* function prototypes for heap access method
125
* heap_create, heap_create_with_catalog, and heap_drop_with_catalog
126
* 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 Relation relation_openr(const char *sysRelationName, LOCKMODE lockmode);
136
extern void relation_close(Relation relation, LOCKMODE lockmode);
138
extern Relation heap_open(Oid relationId, LOCKMODE lockmode);
139
extern Relation heap_openrv(const RangeVar *relation, LOCKMODE lockmode);
140
extern Relation heap_openr(const char *sysRelationName, LOCKMODE lockmode);
142
#define heap_close(r,l) relation_close(r,l)
144
extern HeapScanDesc heap_beginscan(Relation relation, Snapshot snapshot,
145
int nkeys, ScanKey key);
146
extern void heap_rescan(HeapScanDesc scan, ScanKey key);
147
extern void heap_endscan(HeapScanDesc scan);
148
extern HeapTuple heap_getnext(HeapScanDesc scan, ScanDirection direction);
150
extern bool heap_fetch(Relation relation, Snapshot snapshot,
151
HeapTuple tuple, Buffer *userbuf, bool keep_buf,
152
PgStat_Info *pgstat_info);
153
extern bool heap_release_fetch(Relation relation, Snapshot snapshot,
154
HeapTuple tuple, Buffer *userbuf, bool keep_buf,
155
PgStat_Info *pgstat_info);
157
extern ItemPointer heap_get_latest_tid(Relation relation, Snapshot snapshot,
159
extern void setLastTid(const ItemPointer tid);
161
extern Oid heap_insert(Relation relation, HeapTuple tup, CommandId cid);
162
extern int heap_delete(Relation relation, ItemPointer tid, ItemPointer ctid,
163
CommandId cid, Snapshot crosscheck, bool wait);
164
extern int heap_update(Relation relation, ItemPointer otid, HeapTuple tup,
165
ItemPointer ctid, CommandId cid, Snapshot crosscheck, bool wait);
166
extern int heap_mark4update(Relation relation, HeapTuple tup,
167
Buffer *userbuf, CommandId cid);
169
extern Oid simple_heap_insert(Relation relation, HeapTuple tup);
170
extern void simple_heap_delete(Relation relation, ItemPointer tid);
171
extern void simple_heap_update(Relation relation, ItemPointer otid,
174
extern void heap_markpos(HeapScanDesc scan);
175
extern void heap_restrpos(HeapScanDesc scan);
177
extern void heap_redo(XLogRecPtr lsn, XLogRecord *rptr);
178
extern void heap_undo(XLogRecPtr lsn, XLogRecord *rptr);
179
extern void heap_desc(char *buf, uint8 xl_info, char *rec);
180
extern XLogRecPtr log_heap_clean(Relation reln, Buffer buffer,
181
OffsetNumber *unused, int uncnt);
182
extern XLogRecPtr log_heap_move(Relation reln, Buffer oldbuf,
183
ItemPointerData from,
184
Buffer newbuf, HeapTuple newtup);
186
/* in common/heaptuple.c */
187
extern Size ComputeDataSize(TupleDesc tupleDesc, Datum *values, char *nulls);
188
extern void DataFill(char *data, TupleDesc tupleDesc,
189
Datum *values, char *nulls, uint16 *infomask,
191
extern int heap_attisnull(HeapTuple tup, int attnum);
192
extern Datum nocachegetattr(HeapTuple tup, int attnum,
193
TupleDesc att, bool *isnull);
194
extern HeapTuple heap_copytuple(HeapTuple tuple);
195
extern void heap_copytuple_with_tuple(HeapTuple src, HeapTuple dest);
196
extern HeapTuple heap_formtuple(TupleDesc tupleDescriptor,
197
Datum *values, char *nulls);
198
extern HeapTuple heap_modifytuple(HeapTuple tuple,
203
extern void heap_deformtuple(HeapTuple tuple, TupleDesc tupleDesc,
204
Datum *values, char *nulls);
205
extern void heap_freetuple(HeapTuple tuple);
206
extern HeapTuple heap_addheader(int natts, bool withoid, Size structlen, void *structure);
208
#endif /* HEAPAM_H */