brin_tuple.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * brin_tuple.h
  3. * Declarations for dealing with BRIN-specific tuples.
  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_tuple.h
  10. */
  11. #ifndef BRIN_TUPLE_H
  12. #define BRIN_TUPLE_H
  13. #include "access/brin_internal.h"
  14. #include "access/tupdesc.h"
  15. /*
  16. * The BRIN opclasses may register serialization callback, in case the on-disk
  17. * and in-memory representations differ (e.g. for performance reasons).
  18. */
  19. typedef void (*brin_serialize_callback_type) (BrinDesc *bdesc, Datum src, Datum *dst);
  20. /*
  21. * A BRIN index stores one index tuple per page range. Each index tuple
  22. * has one BrinValues struct for each indexed column; in turn, each BrinValues
  23. * has (besides the null flags) an array of Datum whose size is determined by
  24. * the opclass.
  25. */
  26. typedef struct BrinValues
  27. {
  28. AttrNumber bv_attno; /* index attribute number */
  29. bool bv_hasnulls; /* are there any nulls in the page range? */
  30. bool bv_allnulls; /* are all values nulls in the page range? */
  31. Datum *bv_values; /* current accumulated values */
  32. Datum bv_mem_value; /* expanded accumulated values */
  33. MemoryContext bv_context;
  34. brin_serialize_callback_type bv_serialize;
  35. } BrinValues;
  36. /*
  37. * This struct is used to represent an in-memory index tuple. The values can
  38. * only be meaningfully decoded with an appropriate BrinDesc.
  39. */
  40. typedef struct BrinMemTuple
  41. {
  42. bool bt_placeholder; /* this is a placeholder tuple */
  43. bool bt_empty_range; /* range represents no tuples */
  44. BlockNumber bt_blkno; /* heap blkno that the tuple is for */
  45. MemoryContext bt_context; /* memcxt holding the bt_columns values */
  46. /* output arrays for brin_deform_tuple: */
  47. Datum *bt_values; /* values array */
  48. bool *bt_allnulls; /* allnulls array */
  49. bool *bt_hasnulls; /* hasnulls array */
  50. /* not an output array, but must be last */
  51. BrinValues bt_columns[FLEXIBLE_ARRAY_MEMBER];
  52. } BrinMemTuple;
  53. /*
  54. * An on-disk BRIN tuple. This is possibly followed by a nulls bitmask, with
  55. * room for 2 null bits (two bits for each indexed column); an opclass-defined
  56. * number of Datum values for each column follow.
  57. */
  58. typedef struct BrinTuple
  59. {
  60. /* heap block number that the tuple is for */
  61. BlockNumber bt_blkno;
  62. /* ---------------
  63. * bt_info is laid out in the following fashion:
  64. *
  65. * 7th (high) bit: has nulls
  66. * 6th bit: is placeholder tuple
  67. * 5th bit: range is empty
  68. * 4-0 bit: offset of data
  69. * ---------------
  70. */
  71. uint8 bt_info;
  72. } BrinTuple;
  73. #define SizeOfBrinTuple (offsetof(BrinTuple, bt_info) + sizeof(uint8))
  74. /*
  75. * bt_info manipulation macros
  76. */
  77. #define BRIN_OFFSET_MASK 0x1F
  78. #define BRIN_EMPTY_RANGE_MASK 0x20
  79. #define BRIN_PLACEHOLDER_MASK 0x40
  80. #define BRIN_NULLS_MASK 0x80
  81. #define BrinTupleDataOffset(tup) ((Size) (((BrinTuple *) (tup))->bt_info & BRIN_OFFSET_MASK))
  82. #define BrinTupleHasNulls(tup) (((((BrinTuple *) (tup))->bt_info & BRIN_NULLS_MASK)) != 0)
  83. #define BrinTupleIsPlaceholder(tup) (((((BrinTuple *) (tup))->bt_info & BRIN_PLACEHOLDER_MASK)) != 0)
  84. #define BrinTupleIsEmptyRange(tup) (((((BrinTuple *) (tup))->bt_info & BRIN_EMPTY_RANGE_MASK)) != 0)
  85. extern BrinTuple *brin_form_tuple(BrinDesc *brdesc, BlockNumber blkno,
  86. BrinMemTuple *tuple, Size *size);
  87. extern BrinTuple *brin_form_placeholder_tuple(BrinDesc *brdesc,
  88. BlockNumber blkno, Size *size);
  89. extern void brin_free_tuple(BrinTuple *tuple);
  90. extern BrinTuple *brin_copy_tuple(BrinTuple *tuple, Size len,
  91. BrinTuple *dest, Size *destsz);
  92. extern bool brin_tuples_equal(const BrinTuple *a, Size alen,
  93. const BrinTuple *b, Size blen);
  94. extern BrinMemTuple *brin_new_memtuple(BrinDesc *brdesc);
  95. extern BrinMemTuple *brin_memtuple_initialize(BrinMemTuple *dtuple,
  96. BrinDesc *brdesc);
  97. extern BrinMemTuple *brin_deform_tuple(BrinDesc *brdesc,
  98. BrinTuple *tuple, BrinMemTuple *dMemtuple);
  99. #endif /* BRIN_TUPLE_H */