OSDN Git Service

Remove the mostly-stubbed-out-anyway support routines for WAL UNDO.
[pg-rex/syncrep.git] / src / include / access / heapam.h
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.101 2005/06/06 17:01:24 tgl 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 #if !defined(DISABLE_COMPLEX_MACRO)
44
45 #define fastgetattr(tup, attnum, tupleDesc, isnull)                                     \
46 (                                                                                                                                       \
47         AssertMacro((attnum) > 0),                                                                              \
48         ((isnull) ? (*(isnull) = false) : (dummyret)NULL),                              \
49         HeapTupleNoNulls(tup) ?                                                                                 \
50         (                                                                                                                               \
51                 (tupleDesc)->attrs[(attnum)-1]->attcacheoff >= 0 ?                      \
52                 (                                                                                                                       \
53                         fetchatt((tupleDesc)->attrs[(attnum)-1],                                \
54                                 (char *) (tup)->t_data + (tup)->t_data->t_hoff +        \
55                                         (tupleDesc)->attrs[(attnum)-1]->attcacheoff)    \
56                 )                                                                                                                       \
57                 :                                                                                                                       \
58                         nocachegetattr((tup), (attnum), (tupleDesc), (isnull))  \
59         )                                                                                                                               \
60         :                                                                                                                               \
61         (                                                                                                                               \
62                 att_isnull((attnum)-1, (tup)->t_data->t_bits) ?                         \
63                 (                                                                                                                       \
64                         ((isnull) ? (*(isnull) = true) : (dummyret)NULL),               \
65                         (Datum)NULL                                                                                             \
66                 )                                                                                                                       \
67                 :                                                                                                                       \
68                 (                                                                                                                       \
69                         nocachegetattr((tup), (attnum), (tupleDesc), (isnull))  \
70                 )                                                                                                                       \
71         )                                                                                                                               \
72 )
73
74 #else                                                   /* defined(DISABLE_COMPLEX_MACRO) */
75
76 extern Datum fastgetattr(HeapTuple tup, int attnum, TupleDesc tupleDesc,
77                         bool *isnull);
78 #endif   /* defined(DISABLE_COMPLEX_MACRO) */
79
80
81 /* ----------------
82  *              heap_getattr
83  *
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.
87  *
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.
90  *
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.
94  * ----------------
95  */
96 #define heap_getattr(tup, attnum, tupleDesc, isnull) \
97 ( \
98         AssertMacro((tup) != NULL), \
99         ( \
100                 ((attnum) > 0) ? \
101                 ( \
102                         ((attnum) > (int) (tup)->t_data->t_natts) ? \
103                         ( \
104                                 ((isnull) ? (*(isnull) = true) : (dummyret)NULL), \
105                                 (Datum)NULL \
106                         ) \
107                         : \
108                                 fastgetattr((tup), (attnum), (tupleDesc), (isnull)) \
109                 ) \
110                 : \
111                         heap_getsysattr((tup), (attnum), (tupleDesc), (isnull)) \
112         ) \
113 )
114
115
116 /* ----------------
117  *              function prototypes for heap access method
118  *
119  * heap_create, heap_create_with_catalog, and heap_drop_with_catalog
120  * are declared in catalog/heap.h
121  * ----------------
122  */
123
124 /* heapam.c */
125
126 typedef enum
127 {
128         LockTupleShared,
129         LockTupleExclusive
130 } LockTupleMode;
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 void relation_close(Relation relation, LOCKMODE lockmode);
136
137 extern Relation heap_open(Oid relationId, LOCKMODE lockmode);
138 extern Relation heap_openrv(const RangeVar *relation, LOCKMODE lockmode);
139
140 #define heap_close(r,l)  relation_close(r,l)
141
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);
147
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);
154
155 extern ItemPointer heap_get_latest_tid(Relation relation, Snapshot snapshot,
156                                         ItemPointer tid);
157 extern void setLastTid(const ItemPointer tid);
158
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);
166
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,
170                                    HeapTuple tup);
171
172 extern void heap_markpos(HeapScanDesc scan);
173 extern void heap_restrpos(HeapScanDesc scan);
174
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);
182
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,
193                                 bool *isnull);
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,
201                                  TupleDesc tupleDesc,
202                                  Datum *replValues,
203                                  bool *replIsnull,
204                                  bool *doReplace);
205 extern HeapTuple heap_modifytuple(HeapTuple tuple,
206                                  TupleDesc tupleDesc,
207                                  Datum *replValues,
208                                  char *replNulls,
209                                  char *replActions);
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);
217
218 #endif   /* HEAPAM_H */