PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
brin_tuple.h
Go to the documentation of this file.
1 /*
2  * brin_tuple.h
3  * Declarations for dealing with BRIN-specific tuples.
4  *
5  * Portions Copyright (c) 1996-2017, 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 
14 #include "access/brin_internal.h"
15 #include "access/tupdesc.h"
16 
17 
18 /*
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
22  * the opclass.
23  */
24 typedef struct BrinValues
25 {
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 */
30 } BrinValues;
31 
32 /*
33  * This struct is used to represent an in-memory index tuple. The values can
34  * only be meaningfully decoded with an appropriate BrinDesc.
35  */
36 typedef struct BrinMemTuple
37 {
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  /* output arrays for brin_deform_tuple: */
42  Datum *bt_values; /* values array */
43  bool *bt_allnulls; /* allnulls array */
44  bool *bt_hasnulls; /* hasnulls array */
45  /* not an output array, but must be last */
46  BrinValues bt_columns[FLEXIBLE_ARRAY_MEMBER];
47 } BrinMemTuple;
48 
49 /*
50  * An on-disk BRIN tuple. This is possibly followed by a nulls bitmask, with
51  * room for 2 null bits (two bits for each indexed column); an opclass-defined
52  * number of Datum values for each column follow.
53  */
54 typedef struct BrinTuple
55 {
56  /* heap block number that the tuple is for */
58 
59  /* ---------------
60  * bt_info is laid out in the following fashion:
61  *
62  * 7th (high) bit: has nulls
63  * 6th bit: is placeholder tuple
64  * 5th bit: unused
65  * 4-0 bit: offset of data
66  * ---------------
67  */
69 } BrinTuple;
70 
71 #define SizeOfBrinTuple (offsetof(BrinTuple, bt_info) + sizeof(uint8))
72 
73 /*
74  * bt_info manipulation macros
75  */
76 #define BRIN_OFFSET_MASK 0x1F
77 /* bit 0x20 is not used at present */
78 #define BRIN_PLACEHOLDER_MASK 0x40
79 #define BRIN_NULLS_MASK 0x80
80 
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 
85 
86 extern BrinTuple *brin_form_tuple(BrinDesc *brdesc, BlockNumber blkno,
87  BrinMemTuple *tuple, Size *size);
89  BlockNumber blkno, Size *size);
90 extern void brin_free_tuple(BrinTuple *tuple);
91 extern BrinTuple *brin_copy_tuple(BrinTuple *tuple, Size len,
92  BrinTuple *dest, Size *destsz);
93 extern bool brin_tuples_equal(const BrinTuple *a, Size alen,
94  const BrinTuple *b, Size blen);
95 
96 extern BrinMemTuple *brin_new_memtuple(BrinDesc *brdesc);
98  BrinDesc *brdesc);
100  BrinTuple *tuple, BrinMemTuple *dMemtuple);
101 
102 #endif /* BRIN_TUPLE_H */
struct BrinValues BrinValues
BrinMemTuple * brin_memtuple_initialize(BrinMemTuple *dtuple, BrinDesc *brdesc)
Definition: brin_tuple.c:384
BlockNumber bt_blkno
Definition: brin_tuple.h:39
bool bv_allnulls
Definition: brin_tuple.h:28
unsigned char uint8
Definition: c.h:256
struct BrinMemTuple BrinMemTuple
BrinMemTuple * brin_deform_tuple(BrinDesc *brdesc, BrinTuple *tuple, BrinMemTuple *dMemtuple)
Definition: brin_tuple.c:422
uint32 BlockNumber
Definition: block.h:31
Datum * bt_values
Definition: brin_tuple.h:42
bool bt_placeholder
Definition: brin_tuple.h:38
bool bv_hasnulls
Definition: brin_tuple.h:27
BrinMemTuple * brin_new_memtuple(BrinDesc *brdesc)
Definition: brin_tuple.c:357
AttrNumber bv_attno
Definition: brin_tuple.h:26
BrinValues bt_columns[FLEXIBLE_ARRAY_MEMBER]
Definition: brin_tuple.h:46
bool * bt_hasnulls
Definition: brin_tuple.h:44
uintptr_t Datum
Definition: postgres.h:372
BlockNumber bt_blkno
Definition: brin_tuple.h:57
bool * bt_allnulls
Definition: brin_tuple.h:43
size_t Size
Definition: c.h:350
uint8 bt_info
Definition: brin_tuple.h:68
void brin_free_tuple(BrinTuple *tuple)
Definition: brin_tuple.c:308
struct BrinTuple BrinTuple
BrinTuple * brin_copy_tuple(BrinTuple *tuple, Size len, BrinTuple *dest, Size *destsz)
Definition: brin_tuple.c:321
bool brin_tuples_equal(const BrinTuple *a, Size alen, const BrinTuple *b, Size blen)
Definition: brin_tuple.c:340
BrinTuple * brin_form_placeholder_tuple(BrinDesc *brdesc, BlockNumber blkno, Size *size)
Definition: brin_tuple.c:263
BrinTuple * brin_form_tuple(BrinDesc *brdesc, BlockNumber blkno, BrinMemTuple *tuple, Size *size)
Definition: brin_tuple.c:89
Datum * bv_values
Definition: brin_tuple.h:29
int16 AttrNumber
Definition: attnum.h:21
MemoryContext bt_context
Definition: brin_tuple.h:40