gooderp18绿色标准版
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

281 linhas
8.0KB

  1. /*-------------------------------------------------------------------------
  2. *
  3. * hash_xlog.h
  4. * header file for Postgres hash AM implementation
  5. *
  6. *
  7. * Portions Copyright (c) 1996-2019, 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 a HASH index create.
  50. *
  51. * Backup block 0: metapage
  52. */
  53. typedef struct xl_hash_createidx
  54. {
  55. double num_tuples;
  56. RegProcedure procid;
  57. uint16 ffactor;
  58. } xl_hash_createidx;
  59. #define SizeOfHashCreateIdx (offsetof(xl_hash_createidx, ffactor) + sizeof(uint16))
  60. /*
  61. * This is what we need to know about simple (without split) insert.
  62. *
  63. * This data record is used for XLOG_HASH_INSERT
  64. *
  65. * Backup Blk 0: original page (data contains the inserted tuple)
  66. * Backup Blk 1: metapage (HashMetaPageData)
  67. */
  68. typedef struct xl_hash_insert
  69. {
  70. OffsetNumber offnum;
  71. } xl_hash_insert;
  72. #define SizeOfHashInsert (offsetof(xl_hash_insert, offnum) + sizeof(OffsetNumber))
  73. /*
  74. * This is what we need to know about addition of overflow page.
  75. *
  76. * This data record is used for XLOG_HASH_ADD_OVFL_PAGE
  77. *
  78. * Backup Blk 0: newly allocated overflow page
  79. * Backup Blk 1: page before new overflow page in the bucket chain
  80. * Backup Blk 2: bitmap page
  81. * Backup Blk 3: new bitmap page
  82. * Backup Blk 4: metapage
  83. */
  84. typedef struct xl_hash_add_ovfl_page
  85. {
  86. uint16 bmsize;
  87. bool bmpage_found;
  88. } xl_hash_add_ovfl_page;
  89. #define SizeOfHashAddOvflPage \
  90. (offsetof(xl_hash_add_ovfl_page, bmpage_found) + sizeof(bool))
  91. /*
  92. * This is what we need to know about allocating a page for split.
  93. *
  94. * This data record is used for XLOG_HASH_SPLIT_ALLOCATE_PAGE
  95. *
  96. * Backup Blk 0: page for old bucket
  97. * Backup Blk 1: page for new bucket
  98. * Backup Blk 2: metapage
  99. */
  100. typedef struct xl_hash_split_allocate_page
  101. {
  102. uint32 new_bucket;
  103. uint16 old_bucket_flag;
  104. uint16 new_bucket_flag;
  105. uint8 flags;
  106. } xl_hash_split_allocate_page;
  107. #define SizeOfHashSplitAllocPage \
  108. (offsetof(xl_hash_split_allocate_page, flags) + sizeof(uint8))
  109. /*
  110. * This is what we need to know about completing the split operation.
  111. *
  112. * This data record is used for XLOG_HASH_SPLIT_COMPLETE
  113. *
  114. * Backup Blk 0: page for old bucket
  115. * Backup Blk 1: page for new bucket
  116. */
  117. typedef struct xl_hash_split_complete
  118. {
  119. uint16 old_bucket_flag;
  120. uint16 new_bucket_flag;
  121. } xl_hash_split_complete;
  122. #define SizeOfHashSplitComplete \
  123. (offsetof(xl_hash_split_complete, new_bucket_flag) + sizeof(uint16))
  124. /*
  125. * This is what we need to know about move page contents required during
  126. * squeeze operation.
  127. *
  128. * This data record is used for XLOG_HASH_MOVE_PAGE_CONTENTS
  129. *
  130. * Backup Blk 0: bucket page
  131. * Backup Blk 1: page containing moved tuples
  132. * Backup Blk 2: page from which tuples will be removed
  133. */
  134. typedef struct xl_hash_move_page_contents
  135. {
  136. uint16 ntups;
  137. bool is_prim_bucket_same_wrt; /* true if the page to which
  138. * tuples are moved is same as
  139. * primary bucket page */
  140. } xl_hash_move_page_contents;
  141. #define SizeOfHashMovePageContents \
  142. (offsetof(xl_hash_move_page_contents, is_prim_bucket_same_wrt) + sizeof(bool))
  143. /*
  144. * This is what we need to know about the squeeze page operation.
  145. *
  146. * This data record is used for XLOG_HASH_SQUEEZE_PAGE
  147. *
  148. * Backup Blk 0: page containing tuples moved from freed overflow page
  149. * Backup Blk 1: freed overflow page
  150. * Backup Blk 2: page previous to the freed overflow page
  151. * Backup Blk 3: page next to the freed overflow page
  152. * Backup Blk 4: bitmap page containing info of freed overflow page
  153. * Backup Blk 5: meta page
  154. */
  155. typedef struct xl_hash_squeeze_page
  156. {
  157. BlockNumber prevblkno;
  158. BlockNumber nextblkno;
  159. uint16 ntups;
  160. bool is_prim_bucket_same_wrt; /* true if the page to which
  161. * tuples are moved is same as
  162. * primary bucket page */
  163. bool is_prev_bucket_same_wrt; /* true if the page to which
  164. * tuples are moved is the page
  165. * previous to the freed overflow
  166. * page */
  167. } xl_hash_squeeze_page;
  168. #define SizeOfHashSqueezePage \
  169. (offsetof(xl_hash_squeeze_page, is_prev_bucket_same_wrt) + sizeof(bool))
  170. /*
  171. * This is what we need to know about the deletion of index tuples from a page.
  172. *
  173. * This data record is used for XLOG_HASH_DELETE
  174. *
  175. * Backup Blk 0: primary bucket page
  176. * Backup Blk 1: page from which tuples are deleted
  177. */
  178. typedef struct xl_hash_delete
  179. {
  180. bool clear_dead_marking; /* true if this operation clears
  181. * LH_PAGE_HAS_DEAD_TUPLES flag */
  182. bool is_primary_bucket_page; /* true if the operation is for
  183. * primary bucket page */
  184. } xl_hash_delete;
  185. #define SizeOfHashDelete (offsetof(xl_hash_delete, is_primary_bucket_page) + sizeof(bool))
  186. /*
  187. * This is what we need for metapage update operation.
  188. *
  189. * This data record is used for XLOG_HASH_UPDATE_META_PAGE
  190. *
  191. * Backup Blk 0: meta page
  192. */
  193. typedef struct xl_hash_update_meta_page
  194. {
  195. double ntuples;
  196. } xl_hash_update_meta_page;
  197. #define SizeOfHashUpdateMetaPage \
  198. (offsetof(xl_hash_update_meta_page, ntuples) + sizeof(double))
  199. /*
  200. * This is what we need to initialize metapage.
  201. *
  202. * This data record is used for XLOG_HASH_INIT_META_PAGE
  203. *
  204. * Backup Blk 0: meta page
  205. */
  206. typedef struct xl_hash_init_meta_page
  207. {
  208. double num_tuples;
  209. RegProcedure procid;
  210. uint16 ffactor;
  211. } xl_hash_init_meta_page;
  212. #define SizeOfHashInitMetaPage \
  213. (offsetof(xl_hash_init_meta_page, ffactor) + sizeof(uint16))
  214. /*
  215. * This is what we need to initialize bitmap page.
  216. *
  217. * This data record is used for XLOG_HASH_INIT_BITMAP_PAGE
  218. *
  219. * Backup Blk 0: bitmap page
  220. * Backup Blk 1: meta page
  221. */
  222. typedef struct xl_hash_init_bitmap_page
  223. {
  224. uint16 bmsize;
  225. } xl_hash_init_bitmap_page;
  226. #define SizeOfHashInitBitmapPage \
  227. (offsetof(xl_hash_init_bitmap_page, bmsize) + sizeof(uint16))
  228. /*
  229. * This is what we need for index tuple deletion and to
  230. * update the meta page.
  231. *
  232. * This data record is used for XLOG_HASH_VACUUM_ONE_PAGE
  233. *
  234. * Backup Blk 0: bucket page
  235. * Backup Blk 1: meta page
  236. */
  237. typedef struct xl_hash_vacuum_one_page
  238. {
  239. TransactionId latestRemovedXid;
  240. int ntuples;
  241. /* TARGET OFFSET NUMBERS FOLLOW AT THE END */
  242. } xl_hash_vacuum_one_page;
  243. #define SizeOfHashVacuumOnePage \
  244. (offsetof(xl_hash_vacuum_one_page, ntuples) + sizeof(int))
  245. extern void hash_redo(XLogReaderState *record);
  246. extern void hash_desc(StringInfo buf, XLogReaderState *record);
  247. extern const char *hash_identify(uint8 info);
  248. extern void hash_mask(char *pagedata, BlockNumber blkno);
  249. #endif /* HASH_XLOG_H */
上海开阖软件有限公司 沪ICP备12045867号-1