OSDN Git Service

Add NOWAIT option to LOCK command
[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-2003, 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.87 2004/03/11 01:47:41 ishii 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), (isnull)) \
115         ) \
116 )
117
118 extern Datum heap_getsysattr(HeapTuple tup, int attnum, bool *isnull);
119
120
121 /* ----------------
122  *              function prototypes for heap access method
123  *
124  * heap_create, heap_create_with_catalog, and heap_drop_with_catalog
125  * are declared in catalog/heap.h
126  * ----------------
127  */
128
129 /* heapam.c */
130
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);
136
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);
140
141 #define heap_close(r,l)  relation_close(r,l)
142
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);
148
149 extern bool heap_fetch(Relation relation, Snapshot snapshot,
150                    HeapTuple tuple, Buffer *userbuf, bool keep_buf,
151                    PgStat_Info *pgstat_info);
152
153 extern ItemPointer heap_get_latest_tid(Relation relation, Snapshot snapshot,
154                                         ItemPointer tid);
155 extern void setLastTid(const ItemPointer tid);
156
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);
164
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,
168                                    HeapTuple tup);
169
170 extern void heap_markpos(HeapScanDesc scan);
171 extern void heap_restrpos(HeapScanDesc scan);
172
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);
181
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,
186                  bits8 *bit);
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);
198
199 #endif   /* HEAPAM_H */