heapam.h 7.7 KB

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