heapam.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /*-------------------------------------------------------------------------
  2. *
  3. * heapam.h
  4. * POSTGRES heap access method definitions.
  5. *
  6. *
  7. * Portions Copyright (c) 1996-2022, 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. #include "access/relation.h" /* for backward compatibility */
  17. #include "access/relscan.h"
  18. #include "access/sdir.h"
  19. #include "access/skey.h"
  20. #include "access/table.h" /* for backward compatibility */
  21. #include "access/tableam.h"
  22. #include "nodes/lockoptions.h"
  23. #include "nodes/primnodes.h"
  24. #include "storage/bufpage.h"
  25. #include "storage/dsm.h"
  26. #include "storage/lockdefs.h"
  27. #include "storage/shm_toc.h"
  28. #include "utils/relcache.h"
  29. #include "utils/snapshot.h"
  30. /* "options" flag bits for heap_insert */
  31. #define HEAP_INSERT_SKIP_FSM TABLE_INSERT_SKIP_FSM
  32. #define HEAP_INSERT_FROZEN TABLE_INSERT_FROZEN
  33. #define HEAP_INSERT_NO_LOGICAL TABLE_INSERT_NO_LOGICAL
  34. #define HEAP_INSERT_SPECULATIVE 0x0010
  35. typedef struct BulkInsertStateData *BulkInsertState;
  36. struct TupleTableSlot;
  37. #define MaxLockTupleMode LockTupleExclusive
  38. /*
  39. * Descriptor for heap table scans.
  40. */
  41. typedef struct HeapScanDescData
  42. {
  43. TableScanDescData rs_base; /* AM independent part of the descriptor */
  44. /* state set up at initscan time */
  45. BlockNumber rs_nblocks; /* total number of blocks in rel */
  46. BlockNumber rs_startblock; /* block # to start at */
  47. BlockNumber rs_numblocks; /* max number of blocks to scan */
  48. /* rs_numblocks is usually InvalidBlockNumber, meaning "scan whole rel" */
  49. /* scan current state */
  50. bool rs_inited; /* false = scan not init'd yet */
  51. BlockNumber rs_cblock; /* current block # in scan, if any */
  52. Buffer rs_cbuf; /* current buffer in scan, if any */
  53. /* NB: if rs_cbuf is not InvalidBuffer, we hold a pin on that buffer */
  54. /* rs_numblocks is usually InvalidBlockNumber, meaning "scan whole rel" */
  55. BufferAccessStrategy rs_strategy; /* access strategy for reads */
  56. HeapTupleData rs_ctup; /* current tuple in scan, if any */
  57. /*
  58. * For parallel scans to store page allocation data. NULL when not
  59. * performing a parallel scan.
  60. */
  61. ParallelBlockTableScanWorkerData *rs_parallelworkerdata;
  62. /* these fields only used in page-at-a-time mode and for bitmap scans */
  63. int rs_cindex; /* current tuple's index in vistuples */
  64. int rs_ntuples; /* number of visible tuples on page */
  65. OffsetNumber rs_vistuples[MaxHeapTuplesPerPage]; /* their offsets */
  66. } HeapScanDescData;
  67. typedef struct HeapScanDescData *HeapScanDesc;
  68. /*
  69. * Descriptor for fetches from heap via an index.
  70. */
  71. typedef struct IndexFetchHeapData
  72. {
  73. IndexFetchTableData xs_base; /* AM independent part of the descriptor */
  74. Buffer xs_cbuf; /* current heap buffer in scan, if any */
  75. /* NB: if xs_cbuf is not InvalidBuffer, we hold a pin on that buffer */
  76. } IndexFetchHeapData;
  77. /* Result codes for HeapTupleSatisfiesVacuum */
  78. typedef enum
  79. {
  80. HEAPTUPLE_DEAD, /* tuple is dead and deletable */
  81. HEAPTUPLE_LIVE, /* tuple is live (committed, no deleter) */
  82. HEAPTUPLE_RECENTLY_DEAD, /* tuple is dead, but not deletable yet */
  83. HEAPTUPLE_INSERT_IN_PROGRESS, /* inserting xact is still in progress */
  84. HEAPTUPLE_DELETE_IN_PROGRESS /* deleting xact is still in progress */
  85. } HTSV_Result;
  86. /* ----------------
  87. * function prototypes for heap access method
  88. *
  89. * heap_create, heap_create_with_catalog, and heap_drop_with_catalog
  90. * are declared in catalog/heap.h
  91. * ----------------
  92. */
  93. /*
  94. * HeapScanIsValid
  95. * True iff the heap scan is valid.
  96. */
  97. #define HeapScanIsValid(scan) PointerIsValid(scan)
  98. extern TableScanDesc heap_beginscan(Relation relation, Snapshot snapshot,
  99. int nkeys, ScanKey key,
  100. ParallelTableScanDesc parallel_scan,
  101. uint32 flags);
  102. extern void heap_setscanlimits(TableScanDesc scan, BlockNumber startBlk,
  103. BlockNumber numBlks);
  104. extern void heapgetpage(TableScanDesc scan, BlockNumber page);
  105. extern void heap_rescan(TableScanDesc scan, ScanKey key, bool set_params,
  106. bool allow_strat, bool allow_sync, bool allow_pagemode);
  107. extern void heap_endscan(TableScanDesc scan);
  108. extern HeapTuple heap_getnext(TableScanDesc scan, ScanDirection direction);
  109. extern bool heap_getnextslot(TableScanDesc sscan,
  110. ScanDirection direction, struct TupleTableSlot *slot);
  111. extern void heap_set_tidrange(TableScanDesc sscan, ItemPointer mintid,
  112. ItemPointer maxtid);
  113. extern bool heap_getnextslot_tidrange(TableScanDesc sscan,
  114. ScanDirection direction,
  115. TupleTableSlot *slot);
  116. extern bool heap_fetch(Relation relation, Snapshot snapshot,
  117. HeapTuple tuple, Buffer *userbuf, bool keep_buf);
  118. extern bool heap_hot_search_buffer(ItemPointer tid, Relation relation,
  119. Buffer buffer, Snapshot snapshot, HeapTuple heapTuple,
  120. bool *all_dead, bool first_call);
  121. extern void heap_get_latest_tid(TableScanDesc scan, ItemPointer tid);
  122. extern BulkInsertState GetBulkInsertState(void);
  123. extern void FreeBulkInsertState(BulkInsertState);
  124. extern void ReleaseBulkInsertStatePin(BulkInsertState bistate);
  125. extern void heap_insert(Relation relation, HeapTuple tup, CommandId cid,
  126. int options, BulkInsertState bistate);
  127. extern void heap_multi_insert(Relation relation, struct TupleTableSlot **slots,
  128. int ntuples, CommandId cid, int options,
  129. BulkInsertState bistate);
  130. extern TM_Result heap_delete(Relation relation, ItemPointer tid,
  131. CommandId cid, Snapshot crosscheck, bool wait,
  132. struct TM_FailureData *tmfd, bool changingPart);
  133. extern void heap_finish_speculative(Relation relation, ItemPointer tid);
  134. extern void heap_abort_speculative(Relation relation, ItemPointer tid);
  135. extern TM_Result heap_update(Relation relation, ItemPointer otid,
  136. HeapTuple newtup,
  137. CommandId cid, Snapshot crosscheck, bool wait,
  138. struct TM_FailureData *tmfd, LockTupleMode *lockmode);
  139. extern TM_Result heap_lock_tuple(Relation relation, HeapTuple tuple,
  140. CommandId cid, LockTupleMode mode, LockWaitPolicy wait_policy,
  141. bool follow_update,
  142. Buffer *buffer, struct TM_FailureData *tmfd);
  143. extern void heap_inplace_update(Relation relation, HeapTuple tuple);
  144. extern bool heap_freeze_tuple(HeapTupleHeader tuple,
  145. TransactionId relfrozenxid, TransactionId relminmxid,
  146. TransactionId cutoff_xid, TransactionId cutoff_multi);
  147. extern bool heap_tuple_would_freeze(HeapTupleHeader tuple, TransactionId cutoff_xid,
  148. MultiXactId cutoff_multi,
  149. TransactionId *relfrozenxid_out,
  150. MultiXactId *relminmxid_out);
  151. extern bool heap_tuple_needs_eventual_freeze(HeapTupleHeader tuple);
  152. extern void simple_heap_insert(Relation relation, HeapTuple tup);
  153. extern void simple_heap_delete(Relation relation, ItemPointer tid);
  154. extern void simple_heap_update(Relation relation, ItemPointer otid,
  155. HeapTuple tup);
  156. extern TransactionId heap_index_delete_tuples(Relation rel,
  157. TM_IndexDeleteOp *delstate);
  158. /* in heap/pruneheap.c */
  159. struct GlobalVisState;
  160. extern void heap_page_prune_opt(Relation relation, Buffer buffer);
  161. extern int heap_page_prune(Relation relation, Buffer buffer,
  162. struct GlobalVisState *vistest,
  163. TransactionId old_snap_xmin,
  164. TimestampTz old_snap_ts_ts,
  165. int *nnewlpdead,
  166. OffsetNumber *off_loc);
  167. extern void heap_page_prune_execute(Buffer buffer,
  168. OffsetNumber *redirected, int nredirected,
  169. OffsetNumber *nowdead, int ndead,
  170. OffsetNumber *nowunused, int nunused);
  171. extern void heap_get_root_tuples(Page page, OffsetNumber *root_offsets);
  172. /* in heap/vacuumlazy.c */
  173. struct VacuumParams;
  174. extern void heap_vacuum_rel(Relation rel,
  175. struct VacuumParams *params, BufferAccessStrategy bstrategy);
  176. /* in heap/heapam_visibility.c */
  177. extern bool HeapTupleSatisfiesVisibility(HeapTuple stup, Snapshot snapshot,
  178. Buffer buffer);
  179. extern TM_Result HeapTupleSatisfiesUpdate(HeapTuple stup, CommandId curcid,
  180. Buffer buffer);
  181. extern HTSV_Result HeapTupleSatisfiesVacuum(HeapTuple stup, TransactionId OldestXmin,
  182. Buffer buffer);
  183. extern HTSV_Result HeapTupleSatisfiesVacuumHorizon(HeapTuple stup, Buffer buffer,
  184. TransactionId *dead_after);
  185. extern void HeapTupleSetHintBits(HeapTupleHeader tuple, Buffer buffer,
  186. uint16 infomask, TransactionId xid);
  187. extern bool HeapTupleHeaderIsOnlyLocked(HeapTupleHeader tuple);
  188. extern bool XidInMVCCSnapshot(TransactionId xid, Snapshot snapshot);
  189. extern bool HeapTupleIsSurelyDead(HeapTuple htup,
  190. struct GlobalVisState *vistest);
  191. /*
  192. * To avoid leaking too much knowledge about reorderbuffer implementation
  193. * details this is implemented in reorderbuffer.c not heapam_visibility.c
  194. */
  195. struct HTAB;
  196. extern bool ResolveCminCmaxDuringDecoding(struct HTAB *tuplecid_data,
  197. Snapshot snapshot,
  198. HeapTuple htup,
  199. Buffer buffer,
  200. CommandId *cmin, CommandId *cmax);
  201. extern void HeapCheckForSerializableConflictOut(bool valid, Relation relation, HeapTuple tuple,
  202. Buffer buffer, Snapshot snapshot);
  203. #endif /* HEAPAM_H */