3 * Declarations for dealing with BRIN-specific tuples.
5 * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
6 * Portions Copyright (c) 1994, Regents of the University of California
9 * src/include/access/brin_tuple.h
14 #include "access/brin_internal.h"
15 #include "access/tupdesc.h"
19 * A BRIN index stores one index tuple per page range. Each index tuple
20 * has one BrinValues struct for each indexed column; in turn, each BrinValues
21 * has (besides the null flags) an array of Datum whose size is determined by
24 typedef struct BrinValues
26 AttrNumber bv_attno; /* index attribute number */
27 bool bv_hasnulls; /* are there any nulls in the page range? */
28 bool bv_allnulls; /* are all values nulls in the page range? */
29 Datum *bv_values; /* current accumulated values */
33 * This struct is used to represent an in-memory index tuple. The values can
34 * only be meaningfully decoded with an appropriate BrinDesc.
36 typedef struct BrinMemTuple
38 bool bt_placeholder; /* this is a placeholder tuple */
39 BlockNumber bt_blkno; /* heap blkno that the tuple is for */
40 MemoryContext bt_context; /* memcxt holding the bt_columns values */
41 BrinValues bt_columns[FLEXIBLE_ARRAY_MEMBER];
45 * An on-disk BRIN tuple. This is possibly followed by a nulls bitmask, with
46 * room for 2 null bits (two bits for each indexed column); an opclass-defined
47 * number of Datum values for each column follow.
49 typedef struct BrinTuple
51 /* heap block number that the tuple is for */
55 * bt_info is laid out in the following fashion:
57 * 7th (high) bit: has nulls
58 * 6th bit: is placeholder tuple
60 * 4-0 bit: offset of data
66 #define SizeOfBrinTuple (offsetof(BrinTuple, bt_info) + sizeof(uint8))
69 * bt_info manipulation macros
71 #define BRIN_OFFSET_MASK 0x1F
72 /* bit 0x20 is not used at present */
73 #define BRIN_PLACEHOLDER_MASK 0x40
74 #define BRIN_NULLS_MASK 0x80
76 #define BrinTupleDataOffset(tup) ((Size) (((BrinTuple *) (tup))->bt_info & BRIN_OFFSET_MASK))
77 #define BrinTupleHasNulls(tup) (((((BrinTuple *) (tup))->bt_info & BRIN_NULLS_MASK)) != 0)
78 #define BrinTupleIsPlaceholder(tup) (((((BrinTuple *) (tup))->bt_info & BRIN_PLACEHOLDER_MASK)) != 0)
81 extern BrinTuple *brin_form_tuple(BrinDesc *brdesc, BlockNumber blkno,
82 BrinMemTuple *tuple, Size *size);
83 extern BrinTuple *brin_form_placeholder_tuple(BrinDesc *brdesc,
84 BlockNumber blkno, Size *size);
85 extern void brin_free_tuple(BrinTuple *tuple);
86 extern BrinTuple *brin_copy_tuple(BrinTuple *tuple, Size len);
87 extern bool brin_tuples_equal(const BrinTuple *a, Size alen,
88 const BrinTuple *b, Size blen);
90 extern BrinMemTuple *brin_new_memtuple(BrinDesc *brdesc);
91 extern void brin_memtuple_initialize(BrinMemTuple *dtuple,
93 extern BrinMemTuple *brin_deform_tuple(BrinDesc *brdesc,
96 #endif /* BRIN_TUPLE_H */