spgxlog.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. /*-------------------------------------------------------------------------
  2. *
  3. * spgxlog.h
  4. * xlog declarations for SP-GiST access method.
  5. *
  6. * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
  7. * Portions Copyright (c) 1994, Regents of the University of California
  8. *
  9. * src/include/access/spgxlog.h
  10. *
  11. *-------------------------------------------------------------------------
  12. */
  13. #ifndef SPGXLOG_H
  14. #define SPGXLOG_H
  15. #include "access/xlogreader.h"
  16. #include "lib/stringinfo.h"
  17. #include "storage/off.h"
  18. /* XLOG record types for SPGiST */
  19. /* #define XLOG_SPGIST_CREATE_INDEX 0x00 */ /* not used anymore */
  20. #define XLOG_SPGIST_ADD_LEAF 0x10
  21. #define XLOG_SPGIST_MOVE_LEAFS 0x20
  22. #define XLOG_SPGIST_ADD_NODE 0x30
  23. #define XLOG_SPGIST_SPLIT_TUPLE 0x40
  24. #define XLOG_SPGIST_PICKSPLIT 0x50
  25. #define XLOG_SPGIST_VACUUM_LEAF 0x60
  26. #define XLOG_SPGIST_VACUUM_ROOT 0x70
  27. #define XLOG_SPGIST_VACUUM_REDIRECT 0x80
  28. /*
  29. * Some redo functions need an SpGistState, although only a few of its fields
  30. * need to be valid. spgxlogState carries the required info in xlog records.
  31. * (See fillFakeState in spgxlog.c for more comments.)
  32. */
  33. typedef struct spgxlogState
  34. {
  35. TransactionId myXid;
  36. bool isBuild;
  37. } spgxlogState;
  38. /*
  39. * Backup Blk 0: destination page for leaf tuple
  40. * Backup Blk 1: parent page (if any)
  41. */
  42. typedef struct spgxlogAddLeaf
  43. {
  44. bool newPage; /* init dest page? */
  45. bool storesNulls; /* page is in the nulls tree? */
  46. OffsetNumber offnumLeaf; /* offset where leaf tuple gets placed */
  47. OffsetNumber offnumHeadLeaf; /* offset of head tuple in chain, if any */
  48. OffsetNumber offnumParent; /* where the parent downlink is, if any */
  49. uint16 nodeI;
  50. /* new leaf tuple follows (unaligned!) */
  51. } spgxlogAddLeaf;
  52. /*
  53. * Backup Blk 0: source leaf page
  54. * Backup Blk 1: destination leaf page
  55. * Backup Blk 2: parent page
  56. */
  57. typedef struct spgxlogMoveLeafs
  58. {
  59. uint16 nMoves; /* number of tuples moved from source page */
  60. bool newPage; /* init dest page? */
  61. bool replaceDead; /* are we replacing a DEAD source tuple? */
  62. bool storesNulls; /* pages are in the nulls tree? */
  63. /* where the parent downlink is */
  64. OffsetNumber offnumParent;
  65. uint16 nodeI;
  66. spgxlogState stateSrc;
  67. /*----------
  68. * data follows:
  69. * array of deleted tuple numbers, length nMoves
  70. * array of inserted tuple numbers, length nMoves + 1 or 1
  71. * list of leaf tuples, length nMoves + 1 or 1 (unaligned!)
  72. *
  73. * Note: if replaceDead is true then there is only one inserted tuple
  74. * number and only one leaf tuple in the data, because we are not copying
  75. * the dead tuple from the source
  76. *----------
  77. */
  78. OffsetNumber offsets[FLEXIBLE_ARRAY_MEMBER];
  79. } spgxlogMoveLeafs;
  80. #define SizeOfSpgxlogMoveLeafs offsetof(spgxlogMoveLeafs, offsets)
  81. /*
  82. * Backup Blk 0: original page
  83. * Backup Blk 1: where new tuple goes, if not same place
  84. * Backup Blk 2: where parent downlink is, if updated and different from
  85. * the old and new
  86. */
  87. typedef struct spgxlogAddNode
  88. {
  89. /*
  90. * Offset of the original inner tuple, in the original page (on backup
  91. * block 0).
  92. */
  93. OffsetNumber offnum;
  94. /*
  95. * Offset of the new tuple, on the new page (on backup block 1). Invalid,
  96. * if we overwrote the old tuple in the original page).
  97. */
  98. OffsetNumber offnumNew;
  99. bool newPage; /* init new page? */
  100. /*----
  101. * Where is the parent downlink? parentBlk indicates which page it's on,
  102. * and offnumParent is the offset within the page. The possible values for
  103. * parentBlk are:
  104. *
  105. * 0: parent == original page
  106. * 1: parent == new page
  107. * 2: parent == different page (blk ref 2)
  108. * -1: parent not updated
  109. *----
  110. */
  111. int8 parentBlk;
  112. OffsetNumber offnumParent; /* offset within the parent page */
  113. uint16 nodeI;
  114. spgxlogState stateSrc;
  115. /*
  116. * updated inner tuple follows (unaligned!)
  117. */
  118. } spgxlogAddNode;
  119. /*
  120. * Backup Blk 0: where the prefix tuple goes
  121. * Backup Blk 1: where the postfix tuple goes (if different page)
  122. */
  123. typedef struct spgxlogSplitTuple
  124. {
  125. /* where the prefix tuple goes */
  126. OffsetNumber offnumPrefix;
  127. /* where the postfix tuple goes */
  128. OffsetNumber offnumPostfix;
  129. bool newPage; /* need to init that page? */
  130. bool postfixBlkSame; /* was postfix tuple put on same page as
  131. * prefix? */
  132. /*
  133. * new prefix inner tuple follows, then new postfix inner tuple (both are
  134. * unaligned!)
  135. */
  136. } spgxlogSplitTuple;
  137. /*
  138. * Buffer references in the rdata array are:
  139. * Backup Blk 0: Src page (only if not root)
  140. * Backup Blk 1: Dest page (if used)
  141. * Backup Blk 2: Inner page
  142. * Backup Blk 3: Parent page (if any, and different from Inner)
  143. */
  144. typedef struct spgxlogPickSplit
  145. {
  146. bool isRootSplit;
  147. uint16 nDelete; /* n to delete from Src */
  148. uint16 nInsert; /* n to insert on Src and/or Dest */
  149. bool initSrc; /* re-init the Src page? */
  150. bool initDest; /* re-init the Dest page? */
  151. /* where to put new inner tuple */
  152. OffsetNumber offnumInner;
  153. bool initInner; /* re-init the Inner page? */
  154. bool storesNulls; /* pages are in the nulls tree? */
  155. /* where the parent downlink is, if any */
  156. bool innerIsParent; /* is parent the same as inner page? */
  157. OffsetNumber offnumParent;
  158. uint16 nodeI;
  159. spgxlogState stateSrc;
  160. /*----------
  161. * data follows:
  162. * array of deleted tuple numbers, length nDelete
  163. * array of inserted tuple numbers, length nInsert
  164. * array of page selector bytes for inserted tuples, length nInsert
  165. * new inner tuple (unaligned!)
  166. * list of leaf tuples, length nInsert (unaligned!)
  167. *----------
  168. */
  169. OffsetNumber offsets[FLEXIBLE_ARRAY_MEMBER];
  170. } spgxlogPickSplit;
  171. #define SizeOfSpgxlogPickSplit offsetof(spgxlogPickSplit, offsets)
  172. typedef struct spgxlogVacuumLeaf
  173. {
  174. uint16 nDead; /* number of tuples to become DEAD */
  175. uint16 nPlaceholder; /* number of tuples to become PLACEHOLDER */
  176. uint16 nMove; /* number of tuples to move */
  177. uint16 nChain; /* number of tuples to re-chain */
  178. spgxlogState stateSrc;
  179. /*----------
  180. * data follows:
  181. * tuple numbers to become DEAD
  182. * tuple numbers to become PLACEHOLDER
  183. * tuple numbers to move from (and replace with PLACEHOLDER)
  184. * tuple numbers to move to (replacing what is there)
  185. * tuple numbers to update nextOffset links of
  186. * tuple numbers to insert in nextOffset links
  187. *----------
  188. */
  189. OffsetNumber offsets[FLEXIBLE_ARRAY_MEMBER];
  190. } spgxlogVacuumLeaf;
  191. #define SizeOfSpgxlogVacuumLeaf offsetof(spgxlogVacuumLeaf, offsets)
  192. typedef struct spgxlogVacuumRoot
  193. {
  194. /* vacuum a root page when it is also a leaf */
  195. uint16 nDelete; /* number of tuples to delete */
  196. spgxlogState stateSrc;
  197. /* offsets of tuples to delete follow */
  198. OffsetNumber offsets[FLEXIBLE_ARRAY_MEMBER];
  199. } spgxlogVacuumRoot;
  200. #define SizeOfSpgxlogVacuumRoot offsetof(spgxlogVacuumRoot, offsets)
  201. typedef struct spgxlogVacuumRedirect
  202. {
  203. uint16 nToPlaceholder; /* number of redirects to make placeholders */
  204. OffsetNumber firstPlaceholder; /* first placeholder tuple to remove */
  205. TransactionId newestRedirectXid; /* newest XID of removed redirects */
  206. /* offsets of redirect tuples to make placeholders follow */
  207. OffsetNumber offsets[FLEXIBLE_ARRAY_MEMBER];
  208. } spgxlogVacuumRedirect;
  209. #define SizeOfSpgxlogVacuumRedirect offsetof(spgxlogVacuumRedirect, offsets)
  210. extern void spg_redo(XLogReaderState *record);
  211. extern void spg_desc(StringInfo buf, XLogReaderState *record);
  212. extern const char *spg_identify(uint8 info);
  213. extern void spg_xlog_startup(void);
  214. extern void spg_xlog_cleanup(void);
  215. extern void spg_mask(char *pagedata, BlockNumber blkno);
  216. #endif /* SPGXLOG_H */