Fix failure to verify PGC_[SU_]BACKEND GUCs in pg_file_settings view.
[pgsql.git] / src / include / access / heapam.h
blobd2275769d413f3df5afca2dca2d31fae9488e7bc
1 /*-------------------------------------------------------------------------
3 * heapam.h
4 * POSTGRES heap access method definitions.
7 * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * src/include/access/heapam.h
12 *-------------------------------------------------------------------------
14 #ifndef HEAPAM_H
15 #define HEAPAM_H
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/lockdefs.h"
27 #include "utils/relcache.h"
28 #include "utils/snapshot.h"
31 /* "options" flag bits for heap_insert */
32 #define HEAP_INSERT_SKIP_WAL TABLE_INSERT_SKIP_WAL
33 #define HEAP_INSERT_SKIP_FSM TABLE_INSERT_SKIP_FSM
34 #define HEAP_INSERT_FROZEN TABLE_INSERT_FROZEN
35 #define HEAP_INSERT_NO_LOGICAL TABLE_INSERT_NO_LOGICAL
36 #define HEAP_INSERT_SPECULATIVE 0x0010
38 typedef struct BulkInsertStateData *BulkInsertState;
39 struct TupleTableSlot;
41 #define MaxLockTupleMode LockTupleExclusive
44 * Descriptor for heap table scans.
46 typedef struct HeapScanDescData
48 TableScanDescData rs_base; /* AM independent part of the descriptor */
50 /* state set up at initscan time */
51 BlockNumber rs_nblocks; /* total number of blocks in rel */
52 BlockNumber rs_startblock; /* block # to start at */
53 BlockNumber rs_numblocks; /* max number of blocks to scan */
54 /* rs_numblocks is usually InvalidBlockNumber, meaning "scan whole rel" */
56 /* scan current state */
57 bool rs_inited; /* false = scan not init'd yet */
58 BlockNumber rs_cblock; /* current block # in scan, if any */
59 Buffer rs_cbuf; /* current buffer in scan, if any */
60 /* NB: if rs_cbuf is not InvalidBuffer, we hold a pin on that buffer */
62 /* rs_numblocks is usually InvalidBlockNumber, meaning "scan whole rel" */
63 BufferAccessStrategy rs_strategy; /* access strategy for reads */
65 HeapTupleData rs_ctup; /* current tuple in scan, if any */
67 /* these fields only used in page-at-a-time mode and for bitmap scans */
68 int rs_cindex; /* current tuple's index in vistuples */
69 int rs_ntuples; /* number of visible tuples on page */
70 OffsetNumber rs_vistuples[MaxHeapTuplesPerPage]; /* their offsets */
71 } HeapScanDescData;
72 typedef struct HeapScanDescData *HeapScanDesc;
75 * Descriptor for fetches from heap via an index.
77 typedef struct IndexFetchHeapData
79 IndexFetchTableData xs_base; /* AM independent part of the descriptor */
81 Buffer xs_cbuf; /* current heap buffer in scan, if any */
82 /* NB: if xs_cbuf is not InvalidBuffer, we hold a pin on that buffer */
83 } IndexFetchHeapData;
85 /* Result codes for HeapTupleSatisfiesVacuum */
86 typedef enum
88 HEAPTUPLE_DEAD, /* tuple is dead and deletable */
89 HEAPTUPLE_LIVE, /* tuple is live (committed, no deleter) */
90 HEAPTUPLE_RECENTLY_DEAD, /* tuple is dead, but not deletable yet */
91 HEAPTUPLE_INSERT_IN_PROGRESS, /* inserting xact is still in progress */
92 HEAPTUPLE_DELETE_IN_PROGRESS /* deleting xact is still in progress */
93 } HTSV_Result;
95 /* ----------------
96 * function prototypes for heap access method
98 * heap_create, heap_create_with_catalog, and heap_drop_with_catalog
99 * are declared in catalog/heap.h
100 * ----------------
105 * HeapScanIsValid
106 * True iff the heap scan is valid.
108 #define HeapScanIsValid(scan) PointerIsValid(scan)
110 extern TableScanDesc heap_beginscan(Relation relation, Snapshot snapshot,
111 int nkeys, ScanKey key,
112 ParallelTableScanDesc parallel_scan,
113 uint32 flags);
114 extern void heap_setscanlimits(TableScanDesc scan, BlockNumber startBlk,
115 BlockNumber endBlk);
116 extern void heapgetpage(TableScanDesc scan, BlockNumber page);
117 extern void heap_rescan(TableScanDesc scan, ScanKey key, bool set_params,
118 bool allow_strat, bool allow_sync, bool allow_pagemode);
119 extern void heap_endscan(TableScanDesc scan);
120 extern HeapTuple heap_getnext(TableScanDesc scan, ScanDirection direction);
121 extern bool heap_getnextslot(TableScanDesc sscan,
122 ScanDirection direction, struct TupleTableSlot *slot);
124 extern bool heap_fetch(Relation relation, Snapshot snapshot,
125 HeapTuple tuple, Buffer *userbuf);
126 extern bool heap_fetch_extended(Relation relation, Snapshot snapshot,
127 HeapTuple tuple, Buffer *userbuf,
128 bool keep_buf);
129 extern bool heap_hot_search_buffer(ItemPointer tid, Relation relation,
130 Buffer buffer, Snapshot snapshot, HeapTuple heapTuple,
131 bool *all_dead, bool first_call);
133 extern void heap_get_latest_tid(TableScanDesc scan, ItemPointer tid);
134 extern void setLastTid(const ItemPointer tid);
136 extern BulkInsertState GetBulkInsertState(void);
137 extern void FreeBulkInsertState(BulkInsertState);
138 extern void ReleaseBulkInsertStatePin(BulkInsertState bistate);
140 extern void heap_insert(Relation relation, HeapTuple tup, CommandId cid,
141 int options, BulkInsertState bistate);
142 extern void heap_multi_insert(Relation relation, struct TupleTableSlot **slots,
143 int ntuples, CommandId cid, int options,
144 BulkInsertState bistate);
145 extern TM_Result heap_delete(Relation relation, ItemPointer tid,
146 CommandId cid, Snapshot crosscheck, bool wait,
147 struct TM_FailureData *tmfd, bool changingPart);
148 extern void heap_finish_speculative(Relation relation, ItemPointer tid);
149 extern void heap_abort_speculative(Relation relation, ItemPointer tid);
150 extern TM_Result heap_update(Relation relation, ItemPointer otid,
151 HeapTuple newtup,
152 CommandId cid, Snapshot crosscheck, bool wait,
153 struct TM_FailureData *tmfd, LockTupleMode *lockmode);
154 extern TM_Result heap_lock_tuple(Relation relation, HeapTuple tuple,
155 CommandId cid, LockTupleMode mode, LockWaitPolicy wait_policy,
156 bool follow_update,
157 Buffer *buffer, struct TM_FailureData *tmfd);
159 extern void heap_inplace_update(Relation relation, HeapTuple tuple);
160 extern bool heap_freeze_tuple(HeapTupleHeader tuple,
161 TransactionId relfrozenxid, TransactionId relminmxid,
162 TransactionId cutoff_xid, TransactionId cutoff_multi);
163 extern bool heap_tuple_needs_freeze(HeapTupleHeader tuple, TransactionId cutoff_xid,
164 MultiXactId cutoff_multi, Buffer buf);
165 extern bool heap_tuple_needs_eventual_freeze(HeapTupleHeader tuple);
167 extern void simple_heap_insert(Relation relation, HeapTuple tup);
168 extern void simple_heap_delete(Relation relation, ItemPointer tid);
169 extern void simple_heap_update(Relation relation, ItemPointer otid,
170 HeapTuple tup);
172 extern void heap_sync(Relation relation);
174 extern TransactionId heap_compute_xid_horizon_for_tuples(Relation rel,
175 ItemPointerData *items,
176 int nitems);
178 /* in heap/pruneheap.c */
179 extern void heap_page_prune_opt(Relation relation, Buffer buffer);
180 extern int heap_page_prune(Relation relation, Buffer buffer,
181 TransactionId OldestXmin,
182 bool report_stats, TransactionId *latestRemovedXid);
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);
189 /* in heap/syncscan.c */
190 extern void ss_report_location(Relation rel, BlockNumber location);
191 extern BlockNumber ss_get_location(Relation rel, BlockNumber relnblocks);
192 extern void SyncScanShmemInit(void);
193 extern Size SyncScanShmemSize(void);
195 /* in heap/vacuumlazy.c */
196 struct VacuumParams;
197 extern void heap_vacuum_rel(Relation onerel,
198 struct VacuumParams *params, BufferAccessStrategy bstrategy);
200 /* in heap/heapam_visibility.c */
201 extern bool HeapTupleSatisfiesVisibility(HeapTuple stup, Snapshot snapshot,
202 Buffer buffer);
203 extern TM_Result HeapTupleSatisfiesUpdate(HeapTuple stup, CommandId curcid,
204 Buffer buffer);
205 extern HTSV_Result HeapTupleSatisfiesVacuum(HeapTuple stup, TransactionId OldestXmin,
206 Buffer buffer);
207 extern void HeapTupleSetHintBits(HeapTupleHeader tuple, Buffer buffer,
208 uint16 infomask, TransactionId xid);
209 extern bool HeapTupleHeaderIsOnlyLocked(HeapTupleHeader tuple);
210 extern bool XidInMVCCSnapshot(TransactionId xid, Snapshot snapshot);
211 extern bool HeapTupleIsSurelyDead(HeapTuple htup, TransactionId OldestXmin);
214 * To avoid leaking too much knowledge about reorderbuffer implementation
215 * details this is implemented in reorderbuffer.c not heapam_visibility.c
217 struct HTAB;
218 extern bool ResolveCminCmaxDuringDecoding(struct HTAB *tuplecid_data,
219 Snapshot snapshot,
220 HeapTuple htup,
221 Buffer buffer,
222 CommandId *cmin, CommandId *cmax);
224 #endif /* HEAPAM_H */