2
0

brin_xlog.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*-------------------------------------------------------------------------
  2. *
  3. * brin_xlog.h
  4. * POSTGRES BRIN access XLOG 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/brin_xlog.h
  11. *
  12. *-------------------------------------------------------------------------
  13. */
  14. #ifndef BRIN_XLOG_H
  15. #define BRIN_XLOG_H
  16. #include "access/xlogreader.h"
  17. #include "lib/stringinfo.h"
  18. #include "storage/bufpage.h"
  19. #include "storage/itemptr.h"
  20. #include "storage/relfilenode.h"
  21. #include "utils/relcache.h"
  22. /*
  23. * WAL record definitions for BRIN's WAL operations
  24. *
  25. * XLOG allows to store some information in high 4 bits of log
  26. * record xl_info field.
  27. */
  28. #define XLOG_BRIN_CREATE_INDEX 0x00
  29. #define XLOG_BRIN_INSERT 0x10
  30. #define XLOG_BRIN_UPDATE 0x20
  31. #define XLOG_BRIN_SAMEPAGE_UPDATE 0x30
  32. #define XLOG_BRIN_REVMAP_EXTEND 0x40
  33. #define XLOG_BRIN_DESUMMARIZE 0x50
  34. #define XLOG_BRIN_OPMASK 0x70
  35. /*
  36. * When we insert the first item on a new page, we restore the entire page in
  37. * redo.
  38. */
  39. #define XLOG_BRIN_INIT_PAGE 0x80
  40. /*
  41. * This is what we need to know about a BRIN index create.
  42. *
  43. * Backup block 0: metapage
  44. */
  45. typedef struct xl_brin_createidx
  46. {
  47. BlockNumber pagesPerRange;
  48. uint16 version;
  49. } xl_brin_createidx;
  50. #define SizeOfBrinCreateIdx (offsetof(xl_brin_createidx, version) + sizeof(uint16))
  51. /*
  52. * This is what we need to know about a BRIN tuple insert
  53. *
  54. * Backup block 0: main page, block data is the new BrinTuple.
  55. * Backup block 1: revmap page
  56. */
  57. typedef struct xl_brin_insert
  58. {
  59. BlockNumber heapBlk;
  60. /* extra information needed to update the revmap */
  61. BlockNumber pagesPerRange;
  62. /* offset number in the main page to insert the tuple to. */
  63. OffsetNumber offnum;
  64. } xl_brin_insert;
  65. #define SizeOfBrinInsert (offsetof(xl_brin_insert, offnum) + sizeof(OffsetNumber))
  66. /*
  67. * A cross-page update is the same as an insert, but also stores information
  68. * about the old tuple.
  69. *
  70. * Like in xl_brin_insert:
  71. * Backup block 0: new page, block data includes the new BrinTuple.
  72. * Backup block 1: revmap page
  73. *
  74. * And in addition:
  75. * Backup block 2: old page
  76. */
  77. typedef struct xl_brin_update
  78. {
  79. /* offset number of old tuple on old page */
  80. OffsetNumber oldOffnum;
  81. xl_brin_insert insert;
  82. } xl_brin_update;
  83. #define SizeOfBrinUpdate (offsetof(xl_brin_update, insert) + SizeOfBrinInsert)
  84. /*
  85. * This is what we need to know about a BRIN tuple samepage update
  86. *
  87. * Backup block 0: updated page, with new BrinTuple as block data
  88. */
  89. typedef struct xl_brin_samepage_update
  90. {
  91. OffsetNumber offnum;
  92. } xl_brin_samepage_update;
  93. #define SizeOfBrinSamepageUpdate (sizeof(OffsetNumber))
  94. /*
  95. * This is what we need to know about a revmap extension
  96. *
  97. * Backup block 0: metapage
  98. * Backup block 1: new revmap page
  99. */
  100. typedef struct xl_brin_revmap_extend
  101. {
  102. /*
  103. * XXX: This is actually redundant - the block number is stored as part of
  104. * backup block 1.
  105. */
  106. BlockNumber targetBlk;
  107. } xl_brin_revmap_extend;
  108. #define SizeOfBrinRevmapExtend (offsetof(xl_brin_revmap_extend, targetBlk) + \
  109. sizeof(BlockNumber))
  110. /*
  111. * This is what we need to know about a range de-summarization
  112. *
  113. * Backup block 0: revmap page
  114. * Backup block 1: regular page
  115. */
  116. typedef struct xl_brin_desummarize
  117. {
  118. BlockNumber pagesPerRange;
  119. /* page number location to set to invalid */
  120. BlockNumber heapBlk;
  121. /* offset of item to delete in regular index page */
  122. OffsetNumber regOffset;
  123. } xl_brin_desummarize;
  124. #define SizeOfBrinDesummarize (offsetof(xl_brin_desummarize, regOffset) + \
  125. sizeof(OffsetNumber))
  126. extern void brin_redo(XLogReaderState *record);
  127. extern void brin_desc(StringInfo buf, XLogReaderState *record);
  128. extern const char *brin_identify(uint8 info);
  129. extern void brin_mask(char *pagedata, BlockNumber blkno);
  130. #endif /* BRIN_XLOG_H */