OSDN Git Service

rebuid:
[eos/hostdependX86MAC64.git] / util / X86MAC64 / include / postgresql / server / access / heapam.h
1 /*-------------------------------------------------------------------------
2  *
3  * heapam.h
4  *        POSTGRES heap access method definitions.
5  *
6  *
7  * Portions Copyright (c) 1996-2014, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * src/include/access/heapam.h
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef HEAPAM_H
15 #define HEAPAM_H
16
17 #include "access/sdir.h"
18 #include "access/skey.h"
19 #include "nodes/primnodes.h"
20 #include "storage/bufpage.h"
21 #include "storage/lock.h"
22 #include "utils/relcache.h"
23 #include "utils/snapshot.h"
24
25
26 /* "options" flag bits for heap_insert */
27 #define HEAP_INSERT_SKIP_WAL    0x0001
28 #define HEAP_INSERT_SKIP_FSM    0x0002
29 #define HEAP_INSERT_FROZEN              0x0004
30
31 typedef struct BulkInsertStateData *BulkInsertState;
32
33 /*
34  * Possible lock modes for a tuple.
35  */
36 typedef enum LockTupleMode
37 {
38         /* SELECT FOR KEY SHARE */
39         LockTupleKeyShare,
40         /* SELECT FOR SHARE */
41         LockTupleShare,
42         /* SELECT FOR NO KEY UPDATE, and UPDATEs that don't modify key columns */
43         LockTupleNoKeyExclusive,
44         /* SELECT FOR UPDATE, UPDATEs that modify key columns, and DELETE */
45         LockTupleExclusive
46 } LockTupleMode;
47
48 #define MaxLockTupleMode        LockTupleExclusive
49
50 /*
51  * When heap_update, heap_delete, or heap_lock_tuple fail because the target
52  * tuple is already outdated, they fill in this struct to provide information
53  * to the caller about what happened.
54  * ctid is the target's ctid link: it is the same as the target's TID if the
55  * target was deleted, or the location of the replacement tuple if the target
56  * was updated.
57  * xmax is the outdating transaction's XID.  If the caller wants to visit the
58  * replacement tuple, it must check that this matches before believing the
59  * replacement is really a match.
60  * cmax is the outdating command's CID, but only when the failure code is
61  * HeapTupleSelfUpdated (i.e., something in the current transaction outdated
62  * the tuple); otherwise cmax is zero.  (We make this restriction because
63  * HeapTupleHeaderGetCmax doesn't work for tuples outdated in other
64  * transactions.)
65  */
66 typedef struct HeapUpdateFailureData
67 {
68         ItemPointerData ctid;
69         TransactionId xmax;
70         CommandId       cmax;
71 } HeapUpdateFailureData;
72
73
74 /* ----------------
75  *              function prototypes for heap access method
76  *
77  * heap_create, heap_create_with_catalog, and heap_drop_with_catalog
78  * are declared in catalog/heap.h
79  * ----------------
80  */
81
82 /* in heap/heapam.c */
83 extern Relation relation_open(Oid relationId, LOCKMODE lockmode);
84 extern Relation try_relation_open(Oid relationId, LOCKMODE lockmode);
85 extern Relation relation_openrv(const RangeVar *relation, LOCKMODE lockmode);
86 extern Relation relation_openrv_extended(const RangeVar *relation,
87                                                  LOCKMODE lockmode, bool missing_ok);
88 extern void relation_close(Relation relation, LOCKMODE lockmode);
89
90 extern Relation heap_open(Oid relationId, LOCKMODE lockmode);
91 extern Relation heap_openrv(const RangeVar *relation, LOCKMODE lockmode);
92 extern Relation heap_openrv_extended(const RangeVar *relation,
93                                          LOCKMODE lockmode, bool missing_ok);
94
95 #define heap_close(r,l)  relation_close(r,l)
96
97 /* struct definition appears in relscan.h */
98 typedef struct HeapScanDescData *HeapScanDesc;
99
100 /*
101  * HeapScanIsValid
102  *              True iff the heap scan is valid.
103  */
104 #define HeapScanIsValid(scan) PointerIsValid(scan)
105
106 extern HeapScanDesc heap_beginscan(Relation relation, Snapshot snapshot,
107                            int nkeys, ScanKey key);
108 extern HeapScanDesc heap_beginscan_catalog(Relation relation, int nkeys,
109                                            ScanKey key);
110 extern HeapScanDesc heap_beginscan_strat(Relation relation, Snapshot snapshot,
111                                          int nkeys, ScanKey key,
112                                          bool allow_strat, bool allow_sync);
113 extern HeapScanDesc heap_beginscan_bm(Relation relation, Snapshot snapshot,
114                                   int nkeys, ScanKey key);
115 extern void heap_rescan(HeapScanDesc scan, ScanKey key);
116 extern void heap_endscan(HeapScanDesc scan);
117 extern HeapTuple heap_getnext(HeapScanDesc scan, ScanDirection direction);
118
119 extern bool heap_fetch(Relation relation, Snapshot snapshot,
120                    HeapTuple tuple, Buffer *userbuf, bool keep_buf,
121                    Relation stats_relation);
122 extern bool heap_hot_search_buffer(ItemPointer tid, Relation relation,
123                                            Buffer buffer, Snapshot snapshot, HeapTuple heapTuple,
124                                            bool *all_dead, bool first_call);
125 extern bool heap_hot_search(ItemPointer tid, Relation relation,
126                                 Snapshot snapshot, bool *all_dead);
127
128 extern void heap_get_latest_tid(Relation relation, Snapshot snapshot,
129                                         ItemPointer tid);
130 extern void setLastTid(const ItemPointer tid);
131
132 extern BulkInsertState GetBulkInsertState(void);
133 extern void FreeBulkInsertState(BulkInsertState);
134
135 extern Oid heap_insert(Relation relation, HeapTuple tup, CommandId cid,
136                         int options, BulkInsertState bistate);
137 extern void heap_multi_insert(Relation relation, HeapTuple *tuples, int ntuples,
138                                   CommandId cid, int options, BulkInsertState bistate);
139 extern HTSU_Result heap_delete(Relation relation, ItemPointer tid,
140                         CommandId cid, Snapshot crosscheck, bool wait,
141                         HeapUpdateFailureData *hufd);
142 extern HTSU_Result heap_update(Relation relation, ItemPointer otid,
143                         HeapTuple newtup,
144                         CommandId cid, Snapshot crosscheck, bool wait,
145                         HeapUpdateFailureData *hufd, LockTupleMode *lockmode);
146 extern HTSU_Result heap_lock_tuple(Relation relation, HeapTuple tuple,
147                                 CommandId cid, LockTupleMode mode, bool nowait,
148                                 bool follow_update,
149                                 Buffer *buffer, HeapUpdateFailureData *hufd);
150 extern void heap_inplace_update(Relation relation, HeapTuple tuple);
151 extern bool heap_freeze_tuple(HeapTupleHeader tuple, TransactionId cutoff_xid,
152                                   TransactionId cutoff_multi);
153 extern bool heap_tuple_needs_freeze(HeapTupleHeader tuple, TransactionId cutoff_xid,
154                                                 MultiXactId cutoff_multi, Buffer buf);
155
156 extern Oid      simple_heap_insert(Relation relation, HeapTuple tup);
157 extern void simple_heap_delete(Relation relation, ItemPointer tid);
158 extern void simple_heap_update(Relation relation, ItemPointer otid,
159                                    HeapTuple tup);
160
161 extern void heap_markpos(HeapScanDesc scan);
162 extern void heap_restrpos(HeapScanDesc scan);
163
164 extern void heap_sync(Relation relation);
165
166 /* in heap/pruneheap.c */
167 extern void heap_page_prune_opt(Relation relation, Buffer buffer);
168 extern int heap_page_prune(Relation relation, Buffer buffer,
169                                 TransactionId OldestXmin,
170                                 bool report_stats, TransactionId *latestRemovedXid);
171 extern void heap_page_prune_execute(Buffer buffer,
172                                                 OffsetNumber *redirected, int nredirected,
173                                                 OffsetNumber *nowdead, int ndead,
174                                                 OffsetNumber *nowunused, int nunused);
175 extern void heap_get_root_tuples(Page page, OffsetNumber *root_offsets);
176
177 /* in heap/syncscan.c */
178 extern void ss_report_location(Relation rel, BlockNumber location);
179 extern BlockNumber ss_get_location(Relation rel, BlockNumber relnblocks);
180 extern void SyncScanShmemInit(void);
181 extern Size SyncScanShmemSize(void);
182
183 #endif   /* HEAPAM_H */