OSDN Git Service

b0e32214adff841d8c35f64cb924b2954d20582d
[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-2002, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * $Id: heapam.h,v 1.78 2002/07/20 05:16:59 momjian 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  *                              leftover cruft from old statistics code
30  * ----------------------------------------------------------------
31  */
32
33 #define IncrHeapAccessStat(x)   ((void) 0)
34
35 /* ----------------
36  *              fastgetattr
37  *
38  *              Fetch a user attribute's value as a Datum (might be either a
39  *              value, or a pointer into the data area of the tuple).
40  *
41  *              This must not be used when a system attribute might be requested.
42  *              Furthermore, the passed attnum MUST be valid.  Use heap_getattr()
43  *              instead, if in doubt.
44  *
45  *              This gets called many times, so we macro the cacheable and NULL
46  *              lookups, and call nocachegetattr() for the rest.
47  * ----------------
48  */
49
50 extern Datum nocachegetattr(HeapTuple tup, int attnum,
51                            TupleDesc att, bool *isnull);
52
53 #if !defined(DISABLE_COMPLEX_MACRO)
54
55 #define fastgetattr(tup, attnum, tupleDesc, isnull)                                     \
56 (                                                                                                                                       \
57         AssertMacro((attnum) > 0),                                                                              \
58         ((isnull) ? (*(isnull) = false) : (dummyret)NULL),                              \
59         HeapTupleNoNulls(tup) ?                                                                                 \
60         (                                                                                                                               \
61                 (tupleDesc)->attrs[(attnum)-1]->attcacheoff >= 0 ?                      \
62                 (                                                                                                                       \
63                         fetchatt((tupleDesc)->attrs[(attnum)-1],                                \
64                                 (char *) (tup)->t_data + (tup)->t_data->t_hoff +        \
65                                         (tupleDesc)->attrs[(attnum)-1]->attcacheoff)    \
66                 )                                                                                                                       \
67                 :                                                                                                                       \
68                         nocachegetattr((tup), (attnum), (tupleDesc), (isnull))  \
69         )                                                                                                                               \
70         :                                                                                                                               \
71         (                                                                                                                               \
72                 att_isnull((attnum)-1, (tup)->t_data->t_bits) ?                         \
73                 (                                                                                                                       \
74                         ((isnull) ? (*(isnull) = true) : (dummyret)NULL),               \
75                         (Datum)NULL                                                                                             \
76                 )                                                                                                                       \
77                 :                                                                                                                       \
78                 (                                                                                                                       \
79                         nocachegetattr((tup), (attnum), (tupleDesc), (isnull))  \
80                 )                                                                                                                       \
81         )                                                                                                                               \
82 )
83
84 #else                                                   /* defined(DISABLE_COMPLEX_MACRO) */
85
86 extern Datum fastgetattr(HeapTuple tup, int attnum, TupleDesc tupleDesc,
87                         bool *isnull);
88 #endif   /* defined(DISABLE_COMPLEX_MACRO) */
89
90
91 /* ----------------
92  *              heap_getattr
93  *
94  *              Extract an attribute of a heap tuple and return it as a Datum.
95  *              This works for either system or user attributes.  The given attnum
96  *              is properly range-checked.
97  *
98  *              If the field in question has a NULL value, we return a zero Datum
99  *              and set *isnull == true.  Otherwise, we set *isnull == false.
100  *
101  *              <tup> is the pointer to the heap tuple.  <attnum> is the attribute
102  *              number of the column (field) caller wants.      <tupleDesc> is a
103  *              pointer to the structure describing the row and all its fields.
104  * ----------------
105  */
106 #define heap_getattr(tup, attnum, tupleDesc, isnull) \
107 ( \
108         AssertMacro((tup) != NULL), \
109         ( \
110                 ((attnum) > 0) ? \
111                 ( \
112                         ((attnum) > (int) (tup)->t_data->t_natts) ? \
113                         ( \
114                                 ((isnull) ? (*(isnull) = true) : (dummyret)NULL), \
115                                 (Datum)NULL \
116                         ) \
117                         : \
118                                 fastgetattr((tup), (attnum), (tupleDesc), (isnull)) \
119                 ) \
120                 : \
121                         heap_getsysattr((tup), (attnum), (isnull)) \
122         ) \
123 )
124
125 extern Datum heap_getsysattr(HeapTuple tup, int attnum, bool *isnull);
126
127
128 /* ----------------
129  *              function prototypes for heap access method
130  *
131  * heap_create, heap_create_with_catalog, and heap_drop_with_catalog
132  * are declared in catalog/heap.h
133  * ----------------
134  */
135
136 /* heapam.c */
137
138 extern Relation relation_open(Oid relationId, LOCKMODE lockmode);
139 extern Relation relation_openrv(const RangeVar *relation, LOCKMODE lockmode);
140 extern Relation relation_openr(const char *sysRelationName, LOCKMODE lockmode);
141 extern void relation_close(Relation relation, LOCKMODE lockmode);
142
143 extern Relation heap_open(Oid relationId, LOCKMODE lockmode);
144 extern Relation heap_openrv(const RangeVar *relation, LOCKMODE lockmode);
145 extern Relation heap_openr(const char *sysRelationName, LOCKMODE lockmode);
146
147 #define heap_close(r,l)  relation_close(r,l)
148
149 extern HeapScanDesc heap_beginscan(Relation relation, Snapshot snapshot,
150                                                                    int nkeys, ScanKey key);
151 extern void heap_rescan(HeapScanDesc scan, ScanKey key);
152 extern void heap_endscan(HeapScanDesc scan);
153 extern HeapTuple heap_getnext(HeapScanDesc scan, ScanDirection direction);
154
155 extern bool heap_fetch(Relation relation, Snapshot snapshot,
156                                            HeapTuple tuple, Buffer *userbuf, bool keep_buf,
157                                            PgStat_Info *pgstat_info);
158
159 extern ItemPointer heap_get_latest_tid(Relation relation, Snapshot snapshot,
160                                                                            ItemPointer tid);
161 extern void setLastTid(const ItemPointer tid);
162
163 extern Oid      heap_insert(Relation relation, HeapTuple tup, CommandId cid);
164 extern int      heap_delete(Relation relation, ItemPointer tid, ItemPointer ctid,
165                                                 CommandId cid);
166 extern int heap_update(Relation relation, ItemPointer otid, HeapTuple tup,
167                                            ItemPointer ctid, CommandId cid);
168 extern int      heap_mark4update(Relation relation, HeapTuple tup,
169                                                          Buffer *userbuf, CommandId cid);
170
171 extern Oid      simple_heap_insert(Relation relation, HeapTuple tup);
172 extern void simple_heap_delete(Relation relation, ItemPointer tid);
173 extern void simple_heap_update(Relation relation, ItemPointer otid,
174                                    HeapTuple tup);
175
176 extern void heap_markpos(HeapScanDesc scan);
177 extern void heap_restrpos(HeapScanDesc scan);
178
179 extern void heap_redo(XLogRecPtr lsn, XLogRecord *rptr);
180 extern void heap_undo(XLogRecPtr lsn, XLogRecord *rptr);
181 extern void heap_desc(char *buf, uint8 xl_info, char *rec);
182 extern XLogRecPtr log_heap_clean(Relation reln, Buffer buffer,
183                            char *unused, int unlen);
184 extern XLogRecPtr log_heap_move(Relation reln, Buffer oldbuf,
185                           ItemPointerData from,
186                           Buffer newbuf, HeapTuple newtup);
187
188 /* in common/heaptuple.c */
189 extern Size ComputeDataSize(TupleDesc tupleDesc, Datum *value, char *nulls);
190 extern void DataFill(char *data, TupleDesc tupleDesc,
191                  Datum *value, char *nulls, uint16 *infomask,
192                  bits8 *bit);
193 extern int      heap_attisnull(HeapTuple tup, int attnum);
194 extern Datum nocachegetattr(HeapTuple tup, int attnum,
195                            TupleDesc att, bool *isnull);
196 extern HeapTuple heap_copytuple(HeapTuple tuple);
197 extern void heap_copytuple_with_tuple(HeapTuple src, HeapTuple dest);
198 extern HeapTuple heap_formtuple(TupleDesc tupleDescriptor,
199                            Datum *value, char *nulls);
200 extern HeapTuple heap_modifytuple(HeapTuple tuple,
201                 Relation relation, Datum *replValue, char *replNull, char *repl);
202 extern void heap_freetuple(HeapTuple tuple);
203 extern HeapTuple heap_addheader(int natts, bool withoid, Size structlen, void *structure);
204
205 #endif   /* HEAPAM_H */