brin_page.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * brin_page.h
  3. * Prototypes and definitions for BRIN page layouts
  4. *
  5. * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
  6. * Portions Copyright (c) 1994, Regents of the University of California
  7. *
  8. * IDENTIFICATION
  9. * src/include/access/brin_page.h
  10. *
  11. * NOTES
  12. *
  13. * These structs should really be private to specific BRIN files, but it's
  14. * useful to have them here so that they can be used by pageinspect and similar
  15. * tools.
  16. */
  17. #ifndef BRIN_PAGE_H
  18. #define BRIN_PAGE_H
  19. #include "storage/block.h"
  20. #include "storage/itemptr.h"
  21. /*
  22. * Special area of BRIN pages.
  23. *
  24. * We define it in this odd way so that it always occupies the last
  25. * MAXALIGN-sized element of each page.
  26. */
  27. typedef struct BrinSpecialSpace
  28. {
  29. uint16 vector[MAXALIGN(1) / sizeof(uint16)];
  30. } BrinSpecialSpace;
  31. /*
  32. * Make the page type be the last half-word in the page, for consumption by
  33. * pg_filedump and similar utilities. We don't really care much about the
  34. * position of the "flags" half-word, but it's simpler to apply a consistent
  35. * rule to both.
  36. *
  37. * See comments above GinPageOpaqueData.
  38. */
  39. #define BrinPageType(page) \
  40. (((BrinSpecialSpace *) \
  41. PageGetSpecialPointer(page))->vector[MAXALIGN(1) / sizeof(uint16) - 1])
  42. #define BrinPageFlags(page) \
  43. (((BrinSpecialSpace *) \
  44. PageGetSpecialPointer(page))->vector[MAXALIGN(1) / sizeof(uint16) - 2])
  45. /* special space on all BRIN pages stores a "type" identifier */
  46. #define BRIN_PAGETYPE_META 0xF091
  47. #define BRIN_PAGETYPE_REVMAP 0xF092
  48. #define BRIN_PAGETYPE_REGULAR 0xF093
  49. #define BRIN_IS_META_PAGE(page) (BrinPageType(page) == BRIN_PAGETYPE_META)
  50. #define BRIN_IS_REVMAP_PAGE(page) (BrinPageType(page) == BRIN_PAGETYPE_REVMAP)
  51. #define BRIN_IS_REGULAR_PAGE(page) (BrinPageType(page) == BRIN_PAGETYPE_REGULAR)
  52. /* flags for BrinSpecialSpace */
  53. #define BRIN_EVACUATE_PAGE (1 << 0)
  54. /* Metapage definitions */
  55. typedef struct BrinMetaPageData
  56. {
  57. uint32 brinMagic;
  58. uint32 brinVersion;
  59. BlockNumber pagesPerRange;
  60. BlockNumber lastRevmapPage;
  61. } BrinMetaPageData;
  62. #define BRIN_CURRENT_VERSION 1
  63. #define BRIN_META_MAGIC 0xA8109CFA
  64. #define BRIN_METAPAGE_BLKNO 0
  65. /* Definitions for revmap pages */
  66. typedef struct RevmapContents
  67. {
  68. /*
  69. * This array will fill all available space on the page. It should be
  70. * declared [FLEXIBLE_ARRAY_MEMBER], but for some reason you can't do that
  71. * in an otherwise-empty struct.
  72. */
  73. ItemPointerData rm_tids[1];
  74. } RevmapContents;
  75. #define REVMAP_CONTENT_SIZE \
  76. (BLCKSZ - MAXALIGN(SizeOfPageHeaderData) - \
  77. offsetof(RevmapContents, rm_tids) - \
  78. MAXALIGN(sizeof(BrinSpecialSpace)))
  79. /* max num of items in the array */
  80. #define REVMAP_PAGE_MAXITEMS \
  81. (REVMAP_CONTENT_SIZE / sizeof(ItemPointerData))
  82. #endif /* BRIN_PAGE_H */