PostgreSQL Source Code  git master
heapam.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * heapam.h
4  * POSTGRES heap access method definitions.
5  *
6  *
7  * Portions Copyright (c) 1996-2020, 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/relation.h" /* for backward compatibility */
18 #include "access/relscan.h"
19 #include "access/sdir.h"
20 #include "access/skey.h"
21 #include "access/table.h" /* for backward compatibility */
22 #include "access/tableam.h"
23 #include "nodes/lockoptions.h"
24 #include "nodes/primnodes.h"
25 #include "storage/bufpage.h"
26 #include "storage/dsm.h"
27 #include "storage/lockdefs.h"
28 #include "storage/shm_toc.h"
29 #include "utils/relcache.h"
30 #include "utils/snapshot.h"
31 
32 
33 /* "options" flag bits for heap_insert */
34 #define HEAP_INSERT_SKIP_FSM TABLE_INSERT_SKIP_FSM
35 #define HEAP_INSERT_FROZEN TABLE_INSERT_FROZEN
36 #define HEAP_INSERT_NO_LOGICAL TABLE_INSERT_NO_LOGICAL
37 #define HEAP_INSERT_SPECULATIVE 0x0010
38 
40 struct TupleTableSlot;
41 
42 #define MaxLockTupleMode LockTupleExclusive
43 
44 /*
45  * Descriptor for heap table scans.
46  */
47 typedef struct HeapScanDescData
48 {
49  TableScanDescData rs_base; /* AM independent part of the descriptor */
50 
51  /* state set up at initscan time */
52  BlockNumber rs_nblocks; /* total number of blocks in rel */
53  BlockNumber rs_startblock; /* block # to start at */
54  BlockNumber rs_numblocks; /* max number of blocks to scan */
55  /* rs_numblocks is usually InvalidBlockNumber, meaning "scan whole rel" */
56 
57  /* scan current state */
58  bool rs_inited; /* false = scan not init'd yet */
59  BlockNumber rs_cblock; /* current block # in scan, if any */
60  Buffer rs_cbuf; /* current buffer in scan, if any */
61  /* NB: if rs_cbuf is not InvalidBuffer, we hold a pin on that buffer */
62 
63  /* rs_numblocks is usually InvalidBlockNumber, meaning "scan whole rel" */
64  BufferAccessStrategy rs_strategy; /* access strategy for reads */
65 
66  HeapTupleData rs_ctup; /* current tuple in scan, if any */
67 
68  /* these fields only used in page-at-a-time mode and for bitmap scans */
69  int rs_cindex; /* current tuple's index in vistuples */
70  int rs_ntuples; /* number of visible tuples on page */
74 
75 /*
76  * Descriptor for fetches from heap via an index.
77  */
78 typedef struct IndexFetchHeapData
79 {
80  IndexFetchTableData xs_base; /* AM independent part of the descriptor */
81 
82  Buffer xs_cbuf; /* current heap buffer in scan, if any */
83  /* NB: if xs_cbuf is not InvalidBuffer, we hold a pin on that buffer */
85 
86 /* Result codes for HeapTupleSatisfiesVacuum */
87 typedef enum
88 {
89  HEAPTUPLE_DEAD, /* tuple is dead and deletable */
90  HEAPTUPLE_LIVE, /* tuple is live (committed, no deleter) */
91  HEAPTUPLE_RECENTLY_DEAD, /* tuple is dead, but not deletable yet */
92  HEAPTUPLE_INSERT_IN_PROGRESS, /* inserting xact is still in progress */
93  HEAPTUPLE_DELETE_IN_PROGRESS /* deleting xact is still in progress */
94 } HTSV_Result;
95 
96 /* ----------------
97  * function prototypes for heap access method
98  *
99  * heap_create, heap_create_with_catalog, and heap_drop_with_catalog
100  * are declared in catalog/heap.h
101  * ----------------
102  */
103 
104 
105 /*
106  * HeapScanIsValid
107  * True iff the heap scan is valid.
108  */
109 #define HeapScanIsValid(scan) PointerIsValid(scan)
110 
111 extern TableScanDesc heap_beginscan(Relation relation, Snapshot snapshot,
112  int nkeys, ScanKey key,
113  ParallelTableScanDesc parallel_scan,
114  uint32 flags);
115 extern void heap_setscanlimits(TableScanDesc scan, BlockNumber startBlk,
116  BlockNumber numBlks);
117 extern void heapgetpage(TableScanDesc scan, BlockNumber page);
118 extern void heap_rescan(TableScanDesc scan, ScanKey key, bool set_params,
119  bool allow_strat, bool allow_sync, bool allow_pagemode);
120 extern void heap_endscan(TableScanDesc scan);
121 extern HeapTuple heap_getnext(TableScanDesc scan, ScanDirection direction);
122 extern bool heap_getnextslot(TableScanDesc sscan,
123  ScanDirection direction, struct TupleTableSlot *slot);
124 
125 extern bool heap_fetch(Relation relation, Snapshot snapshot,
126  HeapTuple tuple, Buffer *userbuf);
127 extern bool heap_hot_search_buffer(ItemPointer tid, Relation relation,
128  Buffer buffer, Snapshot snapshot, HeapTuple heapTuple,
129  bool *all_dead, bool first_call);
130 
131 extern void heap_get_latest_tid(TableScanDesc scan, ItemPointer tid);
132 extern void setLastTid(const ItemPointer tid);
133 
134 extern BulkInsertState GetBulkInsertState(void);
135 extern void FreeBulkInsertState(BulkInsertState);
136 extern void ReleaseBulkInsertStatePin(BulkInsertState bistate);
137 
138 extern void heap_insert(Relation relation, HeapTuple tup, CommandId cid,
139  int options, BulkInsertState bistate);
140 extern void heap_multi_insert(Relation relation, struct TupleTableSlot **slots,
141  int ntuples, CommandId cid, int options,
142  BulkInsertState bistate);
143 extern TM_Result heap_delete(Relation relation, ItemPointer tid,
144  CommandId cid, Snapshot crosscheck, bool wait,
145  struct TM_FailureData *tmfd, bool changingPart);
146 extern void heap_finish_speculative(Relation relation, ItemPointer tid);
147 extern void heap_abort_speculative(Relation relation, ItemPointer tid);
148 extern TM_Result heap_update(Relation relation, ItemPointer otid,
149  HeapTuple newtup,
150  CommandId cid, Snapshot crosscheck, bool wait,
151  struct TM_FailureData *tmfd, LockTupleMode *lockmode);
152 extern TM_Result heap_lock_tuple(Relation relation, HeapTuple tuple,
153  CommandId cid, LockTupleMode mode, LockWaitPolicy wait_policy,
154  bool follow_update,
155  Buffer *buffer, struct TM_FailureData *tmfd);
156 
157 extern void heap_inplace_update(Relation relation, HeapTuple tuple);
158 extern bool heap_freeze_tuple(HeapTupleHeader tuple,
159  TransactionId relfrozenxid, TransactionId relminmxid,
160  TransactionId cutoff_xid, TransactionId cutoff_multi);
161 extern bool heap_tuple_needs_freeze(HeapTupleHeader tuple, TransactionId cutoff_xid,
162  MultiXactId cutoff_multi, Buffer buf);
164 
165 extern void 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 
171  ItemPointerData *items,
172  int nitems);
173 
174 /* in heap/pruneheap.c */
175 struct GlobalVisState;
176 extern void heap_page_prune_opt(Relation relation, Buffer buffer);
177 extern int heap_page_prune(Relation relation, Buffer buffer,
178  struct GlobalVisState *vistest,
179  TransactionId limited_oldest_xmin,
180  TimestampTz limited_oldest_ts,
181  bool report_stats, TransactionId *latestRemovedXid,
182  OffsetNumber *off_loc);
183 extern void heap_page_prune_execute(Buffer buffer,
184  OffsetNumber *redirected, int nredirected,
185  OffsetNumber *nowdead, int ndead,
186  OffsetNumber *nowunused, int nunused);
187 extern void heap_get_root_tuples(Page page, OffsetNumber *root_offsets);
188 
189 /* in heap/vacuumlazy.c */
190 struct VacuumParams;
191 extern void heap_vacuum_rel(Relation onerel,
192  struct VacuumParams *params, BufferAccessStrategy bstrategy);
193 extern void parallel_vacuum_main(dsm_segment *seg, shm_toc *toc);
194 
195 /* in heap/heapam_visibility.c */
196 extern bool HeapTupleSatisfiesVisibility(HeapTuple stup, Snapshot snapshot,
197  Buffer buffer);
199  Buffer buffer);
201  Buffer buffer);
203  TransactionId *dead_after);
204 extern void HeapTupleSetHintBits(HeapTupleHeader tuple, Buffer buffer,
205  uint16 infomask, TransactionId xid);
207 extern bool XidInMVCCSnapshot(TransactionId xid, Snapshot snapshot);
208 extern bool HeapTupleIsSurelyDead(HeapTuple htup,
209  struct GlobalVisState *vistest);
210 
211 /*
212  * To avoid leaking too much knowledge about reorderbuffer implementation
213  * details this is implemented in reorderbuffer.c not heapam_visibility.c
214  */
215 struct HTAB;
217  Snapshot snapshot,
218  HeapTuple htup,
219  Buffer buffer,
220  CommandId *cmin, CommandId *cmax);
221 extern void HeapCheckForSerializableConflictOut(bool valid, Relation relation, HeapTuple tuple,
222  Buffer buffer, Snapshot snapshot);
223 
224 #endif /* HEAPAM_H */
uint32 CommandId
Definition: c.h:535
bool heap_fetch(Relation relation, Snapshot snapshot, HeapTuple tuple, Buffer *userbuf)
Definition: heapam.c:1394
static PgChecksumMode mode
Definition: pg_checksums.c:61
BlockNumber rs_cblock
Definition: heapam.h:59
LockTupleMode
Definition: lockoptions.h:49
uint32 TransactionId
Definition: c.h:521
bool HeapTupleHeaderIsOnlyLocked(HeapTupleHeader tuple)
int64 TimestampTz
Definition: timestamp.h:39
TableScanDescData rs_base
Definition: heapam.h:49
void ReleaseBulkInsertStatePin(BulkInsertState bistate)
Definition: heapam.c:1832
#define MaxHeapTuplesPerPage
Definition: htup_details.h:574
bool heap_tuple_needs_eventual_freeze(HeapTupleHeader tuple)
Definition: heapam.c:6771
void heapgetpage(TableScanDesc scan, BlockNumber page)
Definition: heapam.c:353
uint32 BlockNumber
Definition: block.h:31
void HeapTupleSetHintBits(HeapTupleHeader tuple, Buffer buffer, uint16 infomask, TransactionId xid)
void parallel_vacuum_main(dsm_segment *seg, shm_toc *toc)
Definition: vacuumlazy.c:3506
struct HeapScanDescData * HeapScanDesc
Definition: heapam.h:73
HeapTupleData rs_ctup
Definition: heapam.h:66
void heap_get_root_tuples(Page page, OffsetNumber *root_offsets)
Definition: pruneheap.c:883
uint16 OffsetNumber
Definition: off.h:24
void heap_multi_insert(Relation relation, struct TupleTableSlot **slots, int ntuples, CommandId cid, int options, BulkInsertState bistate)
Definition: heapam.c:2097
TM_Result heap_lock_tuple(Relation relation, HeapTuple tuple, CommandId cid, LockTupleMode mode, LockWaitPolicy wait_policy, bool follow_update, Buffer *buffer, struct TM_FailureData *tmfd)
Definition: heapam.c:3973
void simple_heap_delete(Relation relation, ItemPointer tid)
Definition: heapam.c:2847
Definition: dynahash.c:218
bool HeapTupleSatisfiesVisibility(HeapTuple stup, Snapshot snapshot, Buffer buffer)
unsigned short uint16
Definition: c.h:374
bool heap_freeze_tuple(HeapTupleHeader tuple, TransactionId relfrozenxid, TransactionId relminmxid, TransactionId cutoff_xid, TransactionId cutoff_multi)
Definition: heapam.c:6376
BulkInsertState GetBulkInsertState(void)
Definition: heapam.c:1806
void heap_insert(Relation relation, HeapTuple tup, CommandId cid, int options, BulkInsertState bistate)
Definition: heapam.c:1859
BlockNumber rs_numblocks
Definition: heapam.h:54
bool XidInMVCCSnapshot(TransactionId xid, Snapshot snapshot)
Definition: snapmgr.c:2238
void heap_endscan(TableScanDesc scan)
Definition: heapam.c:1256
struct HeapScanDescData HeapScanDescData
Buffer xs_cbuf
Definition: heapam.h:82
static char * buf
Definition: pg_test_fsync.c:68
int heap_page_prune(Relation relation, Buffer buffer, struct GlobalVisState *vistest, TransactionId limited_oldest_xmin, TimestampTz limited_oldest_ts, bool report_stats, TransactionId *latestRemovedXid, OffsetNumber *off_loc)
Definition: pruneheap.c:223
ScanDirection
Definition: sdir.h:22
static TransactionId OldestXmin
Definition: vacuumlazy.c:335
void setLastTid(const ItemPointer tid)
Definition: tid.c:281
unsigned int uint32
Definition: c.h:375
bool rs_inited
Definition: heapam.h:58
void simple_heap_insert(Relation relation, HeapTuple tup)
Definition: heapam.c:2384
BlockNumber rs_startblock
Definition: heapam.h:53
TM_Result heap_update(Relation relation, ItemPointer otid, HeapTuple newtup, CommandId cid, Snapshot crosscheck, bool wait, struct TM_FailureData *tmfd, LockTupleMode *lockmode)
Definition: heapam.c:2893
int rs_ntuples
Definition: heapam.h:70
void heap_finish_speculative(Relation relation, ItemPointer tid)
Definition: heapam.c:5475
static HTAB * tuplecid_data
Definition: snapmgr.c:116
bool heap_hot_search_buffer(ItemPointer tid, Relation relation, Buffer buffer, Snapshot snapshot, HeapTuple heapTuple, bool *all_dead, bool first_call)
Definition: heapam.c:1509
TM_Result
Definition: tableam.h:70
BlockNumber rs_nblocks
Definition: heapam.h:52
BufferAccessStrategy rs_strategy
Definition: heapam.h:64
Buffer rs_cbuf
Definition: heapam.h:60
struct IndexFetchHeapData IndexFetchHeapData
TransactionId MultiXactId
Definition: c.h:531
OffsetNumber rs_vistuples[MaxHeapTuplesPerPage]
Definition: heapam.h:71
void heap_setscanlimits(TableScanDesc scan, BlockNumber startBlk, BlockNumber numBlks)
Definition: heapam.c:330
TM_Result heap_delete(Relation relation, ItemPointer tid, CommandId cid, Snapshot crosscheck, bool wait, struct TM_FailureData *tmfd, bool changingPart)
Definition: heapam.c:2442
struct BulkInsertStateData * BulkInsertState
Definition: heapam.h:39
bool heap_tuple_needs_freeze(HeapTupleHeader tuple, TransactionId cutoff_xid, MultiXactId cutoff_multi, Buffer buf)
Definition: heapam.c:6824
void FreeBulkInsertState(BulkInsertState)
Definition: heapam.c:1820
void heap_get_latest_tid(TableScanDesc scan, ItemPointer tid)
Definition: heapam.c:1661
TransactionId heap_compute_xid_horizon_for_tuples(Relation rel, ItemPointerData *items, int nitems)
Definition: heapam.c:6992
void heap_abort_speculative(Relation relation, ItemPointer tid)
Definition: heapam.c:5566
HeapTuple heap_getnext(TableScanDesc scan, ScanDirection direction)
Definition: heapam.c:1286
bool heap_getnextslot(TableScanDesc sscan, ScanDirection direction, struct TupleTableSlot *slot)
Definition: heapam.c:1335
void heap_page_prune_execute(Buffer buffer, OffsetNumber *redirected, int nredirected, OffsetNumber *nowdead, int ndead, OffsetNumber *nowunused, int nunused)
Definition: pruneheap.c:819
HTSV_Result
Definition: heapam.h:87
HTSV_Result HeapTupleSatisfiesVacuum(HeapTuple stup, TransactionId OldestXmin, Buffer buffer)
void heap_inplace_update(Relation relation, HeapTuple tuple)
Definition: heapam.c:5715
void heap_vacuum_rel(Relation onerel, struct VacuumParams *params, BufferAccessStrategy bstrategy)
Definition: vacuumlazy.c:419
HTSV_Result HeapTupleSatisfiesVacuumHorizon(HeapTuple stup, Buffer buffer, TransactionId *dead_after)
void simple_heap_update(Relation relation, ItemPointer otid, HeapTuple tup)
Definition: heapam.c:3885
bool HeapTupleIsSurelyDead(HeapTuple htup, struct GlobalVisState *vistest)
void HeapCheckForSerializableConflictOut(bool valid, Relation relation, HeapTuple tuple, Buffer buffer, Snapshot snapshot)
Definition: heapam.c:9019
int Buffer
Definition: buf.h:23
TableScanDesc heap_beginscan(Relation relation, Snapshot snapshot, int nkeys, ScanKey key, ParallelTableScanDesc parallel_scan, uint32 flags)
Definition: heapam.c:1141
LockWaitPolicy
Definition: lockoptions.h:36
void heap_rescan(TableScanDesc scan, ScanKey key, bool set_params, bool allow_strat, bool allow_sync, bool allow_pagemode)
Definition: heapam.c:1219
Pointer Page
Definition: bufpage.h:78
IndexFetchTableData xs_base
Definition: heapam.h:80
bool ResolveCminCmaxDuringDecoding(struct HTAB *tuplecid_data, Snapshot snapshot, HeapTuple htup, Buffer buffer, CommandId *cmin, CommandId *cmax)
TM_Result HeapTupleSatisfiesUpdate(HeapTuple stup, CommandId curcid, Buffer buffer)
void heap_page_prune_opt(Relation relation, Buffer buffer)
Definition: pruneheap.c:87