~vcs-imports/mammoth-replicator/trunk

« back to all changes in this revision

Viewing changes to src/include/access/heapam.h

  • Committer: alvherre
  • Date: 2005-12-16 21:24:52 UTC
  • Revision ID: svn-v4:db760fc0-0f08-0410-9d63-cc6633f64896:trunk:1
Initial import of the REL8_0_3 sources from the Pgsql CVS repository.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*-------------------------------------------------------------------------
 
2
 *
 
3
 * heapam.h
 
4
 *        POSTGRES heap access method definitions.
 
5
 *
 
6
 *
 
7
 * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
 
8
 * Portions Copyright (c) 1994, Regents of the University of California
 
9
 *
 
10
 * $PostgreSQL: pgsql/src/include/access/heapam.h,v 1.93 2004-12-31 22:03:21 pgsql Exp $
 
11
 *
 
12
 *-------------------------------------------------------------------------
 
13
 */
 
14
#ifndef HEAPAM_H
 
15
#define HEAPAM_H
 
16
 
 
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"
 
27
 
 
28
/* ----------------
 
29
 *              fastgetattr
 
30
 *
 
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).
 
33
 *
 
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.
 
37
 *
 
38
 *              This gets called many times, so we macro the cacheable and NULL
 
39
 *              lookups, and call nocachegetattr() for the rest.
 
40
 * ----------------
 
41
 */
 
42
 
 
43
extern Datum nocachegetattr(HeapTuple tup, int attnum,
 
44
                           TupleDesc att, bool *isnull);
 
45
 
 
46
#if !defined(DISABLE_COMPLEX_MACRO)
 
47
 
 
48
#define fastgetattr(tup, attnum, tupleDesc, isnull)                                     \
 
49
(                                                                                                                                       \
 
50
        AssertMacro((attnum) > 0),                                                                              \
 
51
        ((isnull) ? (*(isnull) = false) : (dummyret)NULL),                              \
 
52
        HeapTupleNoNulls(tup) ?                                                                                 \
 
53
        (                                                                                                                               \
 
54
                (tupleDesc)->attrs[(attnum)-1]->attcacheoff >= 0 ?                      \
 
55
                (                                                                                                                       \
 
56
                        fetchatt((tupleDesc)->attrs[(attnum)-1],                                \
 
57
                                (char *) (tup)->t_data + (tup)->t_data->t_hoff +        \
 
58
                                        (tupleDesc)->attrs[(attnum)-1]->attcacheoff)    \
 
59
                )                                                                                                                       \
 
60
                :                                                                                                                       \
 
61
                        nocachegetattr((tup), (attnum), (tupleDesc), (isnull))  \
 
62
        )                                                                                                                               \
 
63
        :                                                                                                                               \
 
64
        (                                                                                                                               \
 
65
                att_isnull((attnum)-1, (tup)->t_data->t_bits) ?                         \
 
66
                (                                                                                                                       \
 
67
                        ((isnull) ? (*(isnull) = true) : (dummyret)NULL),               \
 
68
                        (Datum)NULL                                                                                             \
 
69
                )                                                                                                                       \
 
70
                :                                                                                                                       \
 
71
                (                                                                                                                       \
 
72
                        nocachegetattr((tup), (attnum), (tupleDesc), (isnull))  \
 
73
                )                                                                                                                       \
 
74
        )                                                                                                                               \
 
75
)
 
76
 
 
77
#else                                                   /* defined(DISABLE_COMPLEX_MACRO) */
 
78
 
 
79
extern Datum fastgetattr(HeapTuple tup, int attnum, TupleDesc tupleDesc,
 
80
                        bool *isnull);
 
81
#endif   /* defined(DISABLE_COMPLEX_MACRO) */
 
82
 
 
83
 
 
84
/* ----------------
 
85
 *              heap_getattr
 
86
 *
 
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.
 
90
 *
 
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.
 
93
 *
 
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.
 
97
 * ----------------
 
98
 */
 
99
#define heap_getattr(tup, attnum, tupleDesc, isnull) \
 
100
( \
 
101
        AssertMacro((tup) != NULL), \
 
102
        ( \
 
103
                ((attnum) > 0) ? \
 
104
                ( \
 
105
                        ((attnum) > (int) (tup)->t_data->t_natts) ? \
 
106
                        ( \
 
107
                                ((isnull) ? (*(isnull) = true) : (dummyret)NULL), \
 
108
                                (Datum)NULL \
 
109
                        ) \
 
110
                        : \
 
111
                                fastgetattr((tup), (attnum), (tupleDesc), (isnull)) \
 
112
                ) \
 
113
                : \
 
114
                        heap_getsysattr((tup), (attnum), (tupleDesc), (isnull)) \
 
115
        ) \
 
116
)
 
117
 
 
118
extern Datum heap_getsysattr(HeapTuple tup, int attnum, TupleDesc tupleDesc,
 
119
                                bool *isnull);
 
120
 
 
121
 
 
122
/* ----------------
 
123
 *              function prototypes for heap access method
 
124
 *
 
125
 * heap_create, heap_create_with_catalog, and heap_drop_with_catalog
 
126
 * are declared in catalog/heap.h
 
127
 * ----------------
 
128
 */
 
129
 
 
130
/* heapam.c */
 
131
 
 
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);
 
137
 
 
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);
 
141
 
 
142
#define heap_close(r,l)  relation_close(r,l)
 
143
 
 
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);
 
149
 
 
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);
 
156
 
 
157
extern ItemPointer heap_get_latest_tid(Relation relation, Snapshot snapshot,
 
158
                                        ItemPointer tid);
 
159
extern void setLastTid(const ItemPointer tid);
 
160
 
 
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);
 
168
 
 
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,
 
172
                                   HeapTuple tup);
 
173
 
 
174
extern void heap_markpos(HeapScanDesc scan);
 
175
extern void heap_restrpos(HeapScanDesc scan);
 
176
 
 
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);
 
185
 
 
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,
 
190
                 bits8 *bit);
 
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,
 
199
                                 Relation relation,
 
200
                                 Datum *replValues,
 
201
                                 char *replNulls,
 
202
                                 char *replActions);
 
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);
 
207
 
 
208
#endif   /* HEAPAM_H */