hash_xlog.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. /*-------------------------------------------------------------------------
  2. *
  3. * hash_xlog.h
  4. * header file for Postgres hash AM implementation
  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/hash_xlog.h
  11. *
  12. *-------------------------------------------------------------------------
  13. */
  14. #ifndef HASH_XLOG_H
  15. #define HASH_XLOG_H
  16. #include "access/xlogreader.h"
  17. #include "lib/stringinfo.h"
  18. #include "storage/off.h"
  19. /* Number of buffers required for XLOG_HASH_SQUEEZE_PAGE operation */
  20. #define HASH_XLOG_FREE_OVFL_BUFS 6
  21. /*
  22. * XLOG records for hash operations
  23. */
  24. #define XLOG_HASH_INIT_META_PAGE 0x00 /* initialize the meta page */
  25. #define XLOG_HASH_INIT_BITMAP_PAGE 0x10 /* initialize the bitmap page */
  26. #define XLOG_HASH_INSERT 0x20 /* add index tuple without split */
  27. #define XLOG_HASH_ADD_OVFL_PAGE 0x30 /* add overflow page */
  28. #define XLOG_HASH_SPLIT_ALLOCATE_PAGE 0x40 /* allocate new page for split */
  29. #define XLOG_HASH_SPLIT_PAGE 0x50 /* split page */
  30. #define XLOG_HASH_SPLIT_COMPLETE 0x60 /* completion of split operation */
  31. #define XLOG_HASH_MOVE_PAGE_CONTENTS 0x70 /* remove tuples from one page
  32. * and add to another page */
  33. #define XLOG_HASH_SQUEEZE_PAGE 0x80 /* add tuples to one of the previous
  34. * pages in chain and free the ovfl
  35. * page */
  36. #define XLOG_HASH_DELETE 0x90 /* delete index tuples from a page */
  37. #define XLOG_HASH_SPLIT_CLEANUP 0xA0 /* clear split-cleanup flag in primary
  38. * bucket page after deleting tuples
  39. * that are moved due to split */
  40. #define XLOG_HASH_UPDATE_META_PAGE 0xB0 /* update meta page after vacuum */
  41. #define XLOG_HASH_VACUUM_ONE_PAGE 0xC0 /* remove dead tuples from index
  42. * page */
  43. /*
  44. * xl_hash_split_allocate_page flag values, 8 bits are available.
  45. */
  46. #define XLH_SPLIT_META_UPDATE_MASKS (1<<0)
  47. #define XLH_SPLIT_META_UPDATE_SPLITPOINT (1<<1)
  48. /*
  49. * This is what we need to know about simple (without split) insert.
  50. *
  51. * This data record is used for XLOG_HASH_INSERT
  52. *
  53. * Backup Blk 0: original page (data contains the inserted tuple)
  54. * Backup Blk 1: metapage (HashMetaPageData)
  55. */
  56. typedef struct xl_hash_insert
  57. {
  58. OffsetNumber offnum;
  59. } xl_hash_insert;
  60. #define SizeOfHashInsert (offsetof(xl_hash_insert, offnum) + sizeof(OffsetNumber))
  61. /*
  62. * This is what we need to know about addition of overflow page.
  63. *
  64. * This data record is used for XLOG_HASH_ADD_OVFL_PAGE
  65. *
  66. * Backup Blk 0: newly allocated overflow page
  67. * Backup Blk 1: page before new overflow page in the bucket chain
  68. * Backup Blk 2: bitmap page
  69. * Backup Blk 3: new bitmap page
  70. * Backup Blk 4: metapage
  71. */
  72. typedef struct xl_hash_add_ovfl_page
  73. {
  74. uint16 bmsize;
  75. bool bmpage_found;
  76. } xl_hash_add_ovfl_page;
  77. #define SizeOfHashAddOvflPage \
  78. (offsetof(xl_hash_add_ovfl_page, bmpage_found) + sizeof(bool))
  79. /*
  80. * This is what we need to know about allocating a page for split.
  81. *
  82. * This data record is used for XLOG_HASH_SPLIT_ALLOCATE_PAGE
  83. *
  84. * Backup Blk 0: page for old bucket
  85. * Backup Blk 1: page for new bucket
  86. * Backup Blk 2: metapage
  87. */
  88. typedef struct xl_hash_split_allocate_page
  89. {
  90. uint32 new_bucket;
  91. uint16 old_bucket_flag;
  92. uint16 new_bucket_flag;
  93. uint8 flags;
  94. } xl_hash_split_allocate_page;
  95. #define SizeOfHashSplitAllocPage \
  96. (offsetof(xl_hash_split_allocate_page, flags) + sizeof(uint8))
  97. /*
  98. * This is what we need to know about completing the split operation.
  99. *
  100. * This data record is used for XLOG_HASH_SPLIT_COMPLETE
  101. *
  102. * Backup Blk 0: page for old bucket
  103. * Backup Blk 1: page for new bucket
  104. */
  105. typedef struct xl_hash_split_complete
  106. {
  107. uint16 old_bucket_flag;
  108. uint16 new_bucket_flag;
  109. } xl_hash_split_complete;
  110. #define SizeOfHashSplitComplete \
  111. (offsetof(xl_hash_split_complete, new_bucket_flag) + sizeof(uint16))
  112. /*
  113. * This is what we need to know about move page contents required during
  114. * squeeze operation.
  115. *
  116. * This data record is used for XLOG_HASH_MOVE_PAGE_CONTENTS
  117. *
  118. * Backup Blk 0: bucket page
  119. * Backup Blk 1: page containing moved tuples
  120. * Backup Blk 2: page from which tuples will be removed
  121. */
  122. typedef struct xl_hash_move_page_contents
  123. {
  124. uint16 ntups;
  125. bool is_prim_bucket_same_wrt; /* true if the page to which
  126. * tuples are moved is same as
  127. * primary bucket page */
  128. } xl_hash_move_page_contents;
  129. #define SizeOfHashMovePageContents \
  130. (offsetof(xl_hash_move_page_contents, is_prim_bucket_same_wrt) + sizeof(bool))
  131. /*
  132. * This is what we need to know about the squeeze page operation.
  133. *
  134. * This data record is used for XLOG_HASH_SQUEEZE_PAGE
  135. *
  136. * Backup Blk 0: page containing tuples moved from freed overflow page
  137. * Backup Blk 1: freed overflow page
  138. * Backup Blk 2: page previous to the freed overflow page
  139. * Backup Blk 3: page next to the freed overflow page
  140. * Backup Blk 4: bitmap page containing info of freed overflow page
  141. * Backup Blk 5: meta page
  142. */
  143. typedef struct xl_hash_squeeze_page
  144. {
  145. BlockNumber prevblkno;
  146. BlockNumber nextblkno;
  147. uint16 ntups;
  148. bool is_prim_bucket_same_wrt; /* true if the page to which
  149. * tuples are moved is same as
  150. * primary bucket page */
  151. bool is_prev_bucket_same_wrt; /* true if the page to which
  152. * tuples are moved is the page
  153. * previous to the freed overflow
  154. * page */
  155. } xl_hash_squeeze_page;
  156. #define SizeOfHashSqueezePage \
  157. (offsetof(xl_hash_squeeze_page, is_prev_bucket_same_wrt) + sizeof(bool))
  158. /*
  159. * This is what we need to know about the deletion of index tuples from a page.
  160. *
  161. * This data record is used for XLOG_HASH_DELETE
  162. *
  163. * Backup Blk 0: primary bucket page
  164. * Backup Blk 1: page from which tuples are deleted
  165. */
  166. typedef struct xl_hash_delete
  167. {
  168. bool clear_dead_marking; /* true if this operation clears
  169. * LH_PAGE_HAS_DEAD_TUPLES flag */
  170. bool is_primary_bucket_page; /* true if the operation is for
  171. * primary bucket page */
  172. } xl_hash_delete;
  173. #define SizeOfHashDelete (offsetof(xl_hash_delete, is_primary_bucket_page) + sizeof(bool))
  174. /*
  175. * This is what we need for metapage update operation.
  176. *
  177. * This data record is used for XLOG_HASH_UPDATE_META_PAGE
  178. *
  179. * Backup Blk 0: meta page
  180. */
  181. typedef struct xl_hash_update_meta_page
  182. {
  183. double ntuples;
  184. } xl_hash_update_meta_page;
  185. #define SizeOfHashUpdateMetaPage \
  186. (offsetof(xl_hash_update_meta_page, ntuples) + sizeof(double))
  187. /*
  188. * This is what we need to initialize metapage.
  189. *
  190. * This data record is used for XLOG_HASH_INIT_META_PAGE
  191. *
  192. * Backup Blk 0: meta page
  193. */
  194. typedef struct xl_hash_init_meta_page
  195. {
  196. double num_tuples;
  197. RegProcedure procid;
  198. uint16 ffactor;
  199. } xl_hash_init_meta_page;
  200. #define SizeOfHashInitMetaPage \
  201. (offsetof(xl_hash_init_meta_page, ffactor) + sizeof(uint16))
  202. /*
  203. * This is what we need to initialize bitmap page.
  204. *
  205. * This data record is used for XLOG_HASH_INIT_BITMAP_PAGE
  206. *
  207. * Backup Blk 0: bitmap page
  208. * Backup Blk 1: meta page
  209. */
  210. typedef struct xl_hash_init_bitmap_page
  211. {
  212. uint16 bmsize;
  213. } xl_hash_init_bitmap_page;
  214. #define SizeOfHashInitBitmapPage \
  215. (offsetof(xl_hash_init_bitmap_page, bmsize) + sizeof(uint16))
  216. /*
  217. * This is what we need for index tuple deletion and to
  218. * update the meta page.
  219. *
  220. * This data record is used for XLOG_HASH_VACUUM_ONE_PAGE
  221. *
  222. * Backup Blk 0: bucket page
  223. * Backup Blk 1: meta page
  224. */
  225. typedef struct xl_hash_vacuum_one_page
  226. {
  227. TransactionId latestRemovedXid;
  228. int ntuples;
  229. /* TARGET OFFSET NUMBERS FOLLOW AT THE END */
  230. } xl_hash_vacuum_one_page;
  231. #define SizeOfHashVacuumOnePage \
  232. (offsetof(xl_hash_vacuum_one_page, ntuples) + sizeof(int))
  233. extern void hash_redo(XLogReaderState *record);
  234. extern void hash_desc(StringInfo buf, XLogReaderState *record);
  235. extern const char *hash_identify(uint8 info);
  236. extern void hash_mask(char *pagedata, BlockNumber blkno);
  237. #endif /* HASH_XLOG_H */