1 /*-------------------------------------------------------------------------
4 * POSTGRES heap access method definitions.
7 * Portions Copyright (c) 1996-2014, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * src/include/access/heapam.h
12 *-------------------------------------------------------------------------
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"
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
31 typedef struct BulkInsertStateData *BulkInsertState;
34 * Possible lock modes for a tuple.
36 typedef enum LockTupleMode
38 /* SELECT FOR KEY SHARE */
40 /* SELECT FOR SHARE */
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 */
48 #define MaxLockTupleMode LockTupleExclusive
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
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
66 typedef struct HeapUpdateFailureData
71 } HeapUpdateFailureData;
75 * function prototypes for heap access method
77 * heap_create, heap_create_with_catalog, and heap_drop_with_catalog
78 * are declared in catalog/heap.h
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);
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);
95 #define heap_close(r,l) relation_close(r,l)
97 /* struct definition appears in relscan.h */
98 typedef struct HeapScanDescData *HeapScanDesc;
102 * True iff the heap scan is valid.
104 #define HeapScanIsValid(scan) PointerIsValid(scan)
106 extern HeapScanDesc heap_beginscan(Relation relation, Snapshot snapshot,
107 int nkeys, ScanKey key);
108 extern HeapScanDesc heap_beginscan_catalog(Relation relation, int nkeys,
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);
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);
128 extern void heap_get_latest_tid(Relation relation, Snapshot snapshot,
130 extern void setLastTid(const ItemPointer tid);
132 extern BulkInsertState GetBulkInsertState(void);
133 extern void FreeBulkInsertState(BulkInsertState);
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,
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,
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);
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,
161 extern void heap_markpos(HeapScanDesc scan);
162 extern void heap_restrpos(HeapScanDesc scan);
164 extern void heap_sync(Relation relation);
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);
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);
183 #endif /* HEAPAM_H */