PostgreSQL Source Code  git master
brin_tuple.h File Reference
Include dependency graph for brin_tuple.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  BrinValues
 
struct  BrinMemTuple
 
struct  BrinTuple
 

Macros

#define SizeOfBrinTuple   (offsetof(BrinTuple, bt_info) + sizeof(uint8))
 
#define BRIN_OFFSET_MASK   0x1F
 
#define BRIN_PLACEHOLDER_MASK   0x40
 
#define BRIN_NULLS_MASK   0x80
 
#define BrinTupleDataOffset(tup)   ((Size) (((BrinTuple *) (tup))->bt_info & BRIN_OFFSET_MASK))
 
#define BrinTupleHasNulls(tup)   (((((BrinTuple *) (tup))->bt_info & BRIN_NULLS_MASK)) != 0)
 
#define BrinTupleIsPlaceholder(tup)   (((((BrinTuple *) (tup))->bt_info & BRIN_PLACEHOLDER_MASK)) != 0)
 

Typedefs

typedef struct BrinValues BrinValues
 
typedef struct BrinMemTuple BrinMemTuple
 
typedef struct BrinTuple BrinTuple
 

Functions

BrinTuplebrin_form_tuple (BrinDesc *brdesc, BlockNumber blkno, BrinMemTuple *tuple, Size *size)
 
BrinTuplebrin_form_placeholder_tuple (BrinDesc *brdesc, BlockNumber blkno, Size *size)
 
void brin_free_tuple (BrinTuple *tuple)
 
BrinTuplebrin_copy_tuple (BrinTuple *tuple, Size len, BrinTuple *dest, Size *destsz)
 
bool brin_tuples_equal (const BrinTuple *a, Size alen, const BrinTuple *b, Size blen)
 
BrinMemTuplebrin_new_memtuple (BrinDesc *brdesc)
 
BrinMemTuplebrin_memtuple_initialize (BrinMemTuple *dtuple, BrinDesc *brdesc)
 
BrinMemTuplebrin_deform_tuple (BrinDesc *brdesc, BrinTuple *tuple, BrinMemTuple *dMemtuple)
 

Macro Definition Documentation

◆ BRIN_NULLS_MASK

#define BRIN_NULLS_MASK   0x80

Definition at line 79 of file brin_tuple.h.

Referenced by brin_form_placeholder_tuple(), and brin_form_tuple().

◆ BRIN_OFFSET_MASK

#define BRIN_OFFSET_MASK   0x1F

Definition at line 76 of file brin_tuple.h.

Referenced by brin_form_tuple().

◆ BRIN_PLACEHOLDER_MASK

#define BRIN_PLACEHOLDER_MASK   0x40

Definition at line 78 of file brin_tuple.h.

Referenced by brin_form_placeholder_tuple(), and brin_form_tuple().

◆ BrinTupleDataOffset

#define BrinTupleDataOffset (   tup)    ((Size) (((BrinTuple *) (tup))->bt_info & BRIN_OFFSET_MASK))

Definition at line 81 of file brin_tuple.h.

Referenced by brin_deform_tuple().

◆ BrinTupleHasNulls

#define BrinTupleHasNulls (   tup)    (((((BrinTuple *) (tup))->bt_info & BRIN_NULLS_MASK)) != 0)

Definition at line 82 of file brin_tuple.h.

Referenced by brin_deform_tuple().

◆ BrinTupleIsPlaceholder

#define BrinTupleIsPlaceholder (   tup)    (((((BrinTuple *) (tup))->bt_info & BRIN_PLACEHOLDER_MASK)) != 0)

Definition at line 83 of file brin_tuple.h.

Referenced by brin_deform_tuple().

◆ SizeOfBrinTuple

#define SizeOfBrinTuple   (offsetof(BrinTuple, bt_info) + sizeof(uint8))

Definition at line 71 of file brin_tuple.h.

Referenced by brin_deform_tuple(), brin_form_placeholder_tuple(), and brin_form_tuple().

Typedef Documentation

◆ BrinMemTuple

typedef struct BrinMemTuple BrinMemTuple

◆ BrinTuple

typedef struct BrinTuple BrinTuple

◆ BrinValues

typedef struct BrinValues BrinValues

Function Documentation

◆ brin_copy_tuple()

BrinTuple* brin_copy_tuple ( BrinTuple tuple,
Size  len,
BrinTuple dest,
Size destsz 
)

Definition at line 319 of file brin_tuple.c.

References generate_unaccent_rules::dest, palloc(), and repalloc().

Referenced by brin_evacuate_page(), bringetbitmap(), brininsert(), and summarize_range().

320 {
321  if (!destsz || *destsz == 0)
322  dest = palloc(len);
323  else if (len > *destsz)
324  {
325  dest = repalloc(dest, len);
326  *destsz = len;
327  }
328 
329  memcpy(dest, tuple, len);
330 
331  return dest;
332 }
void * repalloc(void *pointer, Size size)
Definition: mcxt.c:1070
void * palloc(Size size)
Definition: mcxt.c:950

◆ brin_deform_tuple()

BrinMemTuple* brin_deform_tuple ( BrinDesc brdesc,
BrinTuple tuple,
BrinMemTuple dMemtuple 
)

Definition at line 420 of file brin_tuple.c.

References BrinDesc::bd_info, BrinDesc::bd_tupdesc, brin_deconstruct_tuple(), brin_memtuple_initialize(), brin_new_memtuple(), BrinTupleDataOffset, BrinTupleHasNulls, BrinTupleIsPlaceholder, BrinMemTuple::bt_allnulls, BrinMemTuple::bt_blkno, BrinTuple::bt_blkno, BrinMemTuple::bt_columns, BrinMemTuple::bt_context, BrinMemTuple::bt_hasnulls, BrinMemTuple::bt_placeholder, BrinMemTuple::bt_values, BrinValues::bv_allnulls, BrinValues::bv_hasnulls, BrinValues::bv_values, datumCopy(), i, MemoryContextSwitchTo(), TupleDescData::natts, BrinOpcInfo::oi_nstored, BrinOpcInfo::oi_typcache, SizeOfBrinTuple, TypeCacheEntry::typbyval, TypeCacheEntry::typlen, and values.

Referenced by brin_page_items(), bringetbitmap(), brininsert(), and union_tuples().

421 {
422  BrinMemTuple *dtup;
423  Datum *values;
424  bool *allnulls;
425  bool *hasnulls;
426  char *tp;
427  bits8 *nullbits;
428  int keyno;
429  int valueno;
430  MemoryContext oldcxt;
431 
432  dtup = dMemtuple ? brin_memtuple_initialize(dMemtuple, brdesc) :
433  brin_new_memtuple(brdesc);
434 
435  if (BrinTupleIsPlaceholder(tuple))
436  dtup->bt_placeholder = true;
437  dtup->bt_blkno = tuple->bt_blkno;
438 
439  values = dtup->bt_values;
440  allnulls = dtup->bt_allnulls;
441  hasnulls = dtup->bt_hasnulls;
442 
443  tp = (char *) tuple + BrinTupleDataOffset(tuple);
444 
445  if (BrinTupleHasNulls(tuple))
446  nullbits = (bits8 *) ((char *) tuple + SizeOfBrinTuple);
447  else
448  nullbits = NULL;
449  brin_deconstruct_tuple(brdesc,
450  tp, nullbits, BrinTupleHasNulls(tuple),
451  values, allnulls, hasnulls);
452 
453  /*
454  * Iterate to assign each of the values to the corresponding item in the
455  * values array of each column. The copies occur in the tuple's context.
456  */
457  oldcxt = MemoryContextSwitchTo(dtup->bt_context);
458  for (valueno = 0, keyno = 0; keyno < brdesc->bd_tupdesc->natts; keyno++)
459  {
460  int i;
461 
462  if (allnulls[keyno])
463  {
464  valueno += brdesc->bd_info[keyno]->oi_nstored;
465  continue;
466  }
467 
468  /*
469  * We would like to skip datumCopy'ing the values datum in some cases,
470  * caller permitting ...
471  */
472  for (i = 0; i < brdesc->bd_info[keyno]->oi_nstored; i++)
473  dtup->bt_columns[keyno].bv_values[i] =
474  datumCopy(values[valueno++],
475  brdesc->bd_info[keyno]->oi_typcache[i]->typbyval,
476  brdesc->bd_info[keyno]->oi_typcache[i]->typlen);
477 
478  dtup->bt_columns[keyno].bv_hasnulls = hasnulls[keyno];
479  dtup->bt_columns[keyno].bv_allnulls = false;
480  }
481 
482  MemoryContextSwitchTo(oldcxt);
483 
484  return dtup;
485 }
#define BrinTupleIsPlaceholder(tup)
Definition: brin_tuple.h:83
#define SizeOfBrinTuple
Definition: brin_tuple.h:71
#define BrinTupleHasNulls(tup)
Definition: brin_tuple.h:82
BlockNumber bt_blkno
Definition: brin_tuple.h:39
bool bv_allnulls
Definition: brin_tuple.h:28
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
BrinMemTuple * brin_new_memtuple(BrinDesc *brdesc)
Definition: brin_tuple.c:355
int16 typlen
Definition: typcache.h:39
bool typbyval
Definition: typcache.h:40
Datum * bt_values
Definition: brin_tuple.h:42
bool bt_placeholder
Definition: brin_tuple.h:38
bool bv_hasnulls
Definition: brin_tuple.h:27
TypeCacheEntry * oi_typcache[FLEXIBLE_ARRAY_MEMBER]
Definition: brin_internal.h:34
uint16 oi_nstored
Definition: brin_internal.h:28
static void brin_deconstruct_tuple(BrinDesc *brdesc, char *tp, bits8 *nullbits, bool nulls, Datum *values, bool *allnulls, bool *hasnulls)
Definition: brin_tuple.c:503
BrinValues bt_columns[FLEXIBLE_ARRAY_MEMBER]
Definition: brin_tuple.h:46
TupleDesc bd_tupdesc
Definition: brin_internal.h:50
bool * bt_hasnulls
Definition: brin_tuple.h:44
Datum datumCopy(Datum value, bool typByVal, int typLen)
Definition: datum.c:131
uint8 bits8
Definition: c.h:381
uintptr_t Datum
Definition: postgres.h:367
BrinOpcInfo * bd_info[FLEXIBLE_ARRAY_MEMBER]
Definition: brin_internal.h:59
BlockNumber bt_blkno
Definition: brin_tuple.h:57
bool * bt_allnulls
Definition: brin_tuple.h:43
static Datum values[MAXATTR]
Definition: bootstrap.c:165
#define BrinTupleDataOffset(tup)
Definition: brin_tuple.h:81
int i
Datum * bv_values
Definition: brin_tuple.h:29
BrinMemTuple * brin_memtuple_initialize(BrinMemTuple *dtuple, BrinDesc *brdesc)
Definition: brin_tuple.c:382
MemoryContext bt_context
Definition: brin_tuple.h:40

◆ brin_form_placeholder_tuple()

BrinTuple* brin_form_placeholder_tuple ( BrinDesc brdesc,
BlockNumber  blkno,
Size size 
)

Definition at line 261 of file brin_tuple.c.

References BrinDesc::bd_tupdesc, BITMAPLEN, BRIN_NULLS_MASK, BRIN_PLACEHOLDER_MASK, BrinTuple::bt_blkno, BrinTuple::bt_info, HIGHBIT, MAXALIGN, TupleDescData::natts, palloc0(), and SizeOfBrinTuple.

Referenced by summarize_range().

262 {
263  Size len;
264  Size hoff;
265  BrinTuple *rettuple;
266  int keyno;
267  bits8 *bitP;
268  int bitmask;
269 
270  /* compute total space needed: always add nulls */
271  len = SizeOfBrinTuple;
272  len += BITMAPLEN(brdesc->bd_tupdesc->natts * 2);
273  len = hoff = MAXALIGN(len);
274 
275  rettuple = palloc0(len);
276  rettuple->bt_blkno = blkno;
277  rettuple->bt_info = hoff;
279 
280  bitP = ((bits8 *) ((char *) rettuple + SizeOfBrinTuple)) - 1;
281  bitmask = HIGHBIT;
282  /* set allnulls true for all attributes */
283  for (keyno = 0; keyno < brdesc->bd_tupdesc->natts; keyno++)
284  {
285  if (bitmask != HIGHBIT)
286  bitmask <<= 1;
287  else
288  {
289  bitP += 1;
290  *bitP = 0x0;
291  bitmask = 1;
292  }
293 
294  *bitP |= bitmask;
295  }
296  /* no need to set hasnulls */
297 
298  *size = len;
299  return rettuple;
300 }
#define SizeOfBrinTuple
Definition: brin_tuple.h:71
#define BITMAPLEN(NATTS)
Definition: htup_details.h:547
#define BRIN_NULLS_MASK
Definition: brin_tuple.h:79
TupleDesc bd_tupdesc
Definition: brin_internal.h:50
#define HIGHBIT
Definition: c.h:1096
#define BRIN_PLACEHOLDER_MASK
Definition: brin_tuple.h:78
uint8 bits8
Definition: c.h:381
void * palloc0(Size size)
Definition: mcxt.c:981
BlockNumber bt_blkno
Definition: brin_tuple.h:57
size_t Size
Definition: c.h:473
#define MAXALIGN(LEN)
Definition: c.h:698
uint8 bt_info
Definition: brin_tuple.h:68

◆ brin_form_tuple()

BrinTuple* brin_form_tuple ( BrinDesc brdesc,
BlockNumber  blkno,
BrinMemTuple tuple,
Size size 
)

Definition at line 88 of file brin_tuple.c.

References Assert, BrinDesc::bd_info, BrinDesc::bd_totalstored, BrinDesc::bd_tupdesc, BITMAPLEN, BRIN_NULLS_MASK, BRIN_OFFSET_MASK, BRIN_PLACEHOLDER_MASK, brtuple_disk_tupdesc(), BrinTuple::bt_blkno, BrinMemTuple::bt_columns, BrinTuple::bt_info, BrinMemTuple::bt_placeholder, BrinValues::bv_allnulls, BrinValues::bv_hasnulls, BrinValues::bv_values, heap_compute_data_size(), heap_fill_tuple(), HIGHBIT, MAXALIGN, TupleDescData::natts, BrinOpcInfo::oi_nstored, palloc(), palloc0(), pfree(), SizeOfBrinTuple, and values.

Referenced by brininsert(), form_and_insert_tuple(), and summarize_range().

90 {
91  Datum *values;
92  bool *nulls;
93  bool anynulls = false;
94  BrinTuple *rettuple;
95  int keyno;
96  int idxattno;
97  uint16 phony_infomask = 0;
98  bits8 *phony_nullbitmap;
99  Size len,
100  hoff,
101  data_len;
102 
103  Assert(brdesc->bd_totalstored > 0);
104 
105  values = (Datum *) palloc(sizeof(Datum) * brdesc->bd_totalstored);
106  nulls = (bool *) palloc0(sizeof(bool) * brdesc->bd_totalstored);
107  phony_nullbitmap = (bits8 *)
108  palloc(sizeof(bits8) * BITMAPLEN(brdesc->bd_totalstored));
109 
110  /*
111  * Set up the values/nulls arrays for heap_fill_tuple
112  */
113  idxattno = 0;
114  for (keyno = 0; keyno < brdesc->bd_tupdesc->natts; keyno++)
115  {
116  int datumno;
117 
118  /*
119  * "allnulls" is set when there's no nonnull value in any row in the
120  * column; when this happens, there is no data to store. Thus set the
121  * nullable bits for all data elements of this column and we're done.
122  */
123  if (tuple->bt_columns[keyno].bv_allnulls)
124  {
125  for (datumno = 0;
126  datumno < brdesc->bd_info[keyno]->oi_nstored;
127  datumno++)
128  nulls[idxattno++] = true;
129  anynulls = true;
130  continue;
131  }
132 
133  /*
134  * The "hasnulls" bit is set when there are some null values in the
135  * data. We still need to store a real value, but the presence of
136  * this means we need a null bitmap.
137  */
138  if (tuple->bt_columns[keyno].bv_hasnulls)
139  anynulls = true;
140 
141  for (datumno = 0;
142  datumno < brdesc->bd_info[keyno]->oi_nstored;
143  datumno++)
144  values[idxattno++] = tuple->bt_columns[keyno].bv_values[datumno];
145  }
146 
147  /* Assert we did not overrun temp arrays */
148  Assert(idxattno <= brdesc->bd_totalstored);
149 
150  /* compute total space needed */
151  len = SizeOfBrinTuple;
152  if (anynulls)
153  {
154  /*
155  * We need a double-length bitmap on an on-disk BRIN index tuple; the
156  * first half stores the "allnulls" bits, the second stores
157  * "hasnulls".
158  */
159  len += BITMAPLEN(brdesc->bd_tupdesc->natts * 2);
160  }
161 
162  len = hoff = MAXALIGN(len);
163 
164  data_len = heap_compute_data_size(brtuple_disk_tupdesc(brdesc),
165  values, nulls);
166  len += data_len;
167 
168  len = MAXALIGN(len);
169 
170  rettuple = palloc0(len);
171  rettuple->bt_blkno = blkno;
172  rettuple->bt_info = hoff;
173 
174  /* Assert that hoff fits in the space available */
175  Assert((rettuple->bt_info & BRIN_OFFSET_MASK) == hoff);
176 
177  /*
178  * The infomask and null bitmap as computed by heap_fill_tuple are useless
179  * to us. However, that function will not accept a null infomask; and we
180  * need to pass a valid null bitmap so that it will correctly skip
181  * outputting null attributes in the data area.
182  */
184  values,
185  nulls,
186  (char *) rettuple + hoff,
187  data_len,
188  &phony_infomask,
189  phony_nullbitmap);
190 
191  /* done with these */
192  pfree(values);
193  pfree(nulls);
194  pfree(phony_nullbitmap);
195 
196  /*
197  * Now fill in the real null bitmasks. allnulls first.
198  */
199  if (anynulls)
200  {
201  bits8 *bitP;
202  int bitmask;
203 
204  rettuple->bt_info |= BRIN_NULLS_MASK;
205 
206  /*
207  * Note that we reverse the sense of null bits in this module: we
208  * store a 1 for a null attribute rather than a 0. So we must reverse
209  * the sense of the att_isnull test in brin_deconstruct_tuple as well.
210  */
211  bitP = ((bits8 *) ((char *) rettuple + SizeOfBrinTuple)) - 1;
212  bitmask = HIGHBIT;
213  for (keyno = 0; keyno < brdesc->bd_tupdesc->natts; keyno++)
214  {
215  if (bitmask != HIGHBIT)
216  bitmask <<= 1;
217  else
218  {
219  bitP += 1;
220  *bitP = 0x0;
221  bitmask = 1;
222  }
223 
224  if (!tuple->bt_columns[keyno].bv_allnulls)
225  continue;
226 
227  *bitP |= bitmask;
228  }
229  /* hasnulls bits follow */
230  for (keyno = 0; keyno < brdesc->bd_tupdesc->natts; keyno++)
231  {
232  if (bitmask != HIGHBIT)
233  bitmask <<= 1;
234  else
235  {
236  bitP += 1;
237  *bitP = 0x0;
238  bitmask = 1;
239  }
240 
241  if (!tuple->bt_columns[keyno].bv_hasnulls)
242  continue;
243 
244  *bitP |= bitmask;
245  }
246  }
247 
248  if (tuple->bt_placeholder)
249  rettuple->bt_info |= BRIN_PLACEHOLDER_MASK;
250 
251  *size = len;
252  return rettuple;
253 }
#define BRIN_OFFSET_MASK
Definition: brin_tuple.h:76
void heap_fill_tuple(TupleDesc tupleDesc, Datum *values, bool *isnull, char *data, Size data_size, uint16 *infomask, bits8 *bit)
Definition: heaptuple.c:304
#define SizeOfBrinTuple
Definition: brin_tuple.h:71
bool bv_allnulls
Definition: brin_tuple.h:28
#define BITMAPLEN(NATTS)
Definition: htup_details.h:547
unsigned short uint16
Definition: c.h:373
void pfree(void *pointer)
Definition: mcxt.c:1057
static TupleDesc brtuple_disk_tupdesc(BrinDesc *brdesc)
Definition: brin_tuple.c:50
bool bt_placeholder
Definition: brin_tuple.h:38
bool bv_hasnulls
Definition: brin_tuple.h:27
uint16 oi_nstored
Definition: brin_internal.h:28
int bd_totalstored
Definition: brin_internal.h:56
BrinValues bt_columns[FLEXIBLE_ARRAY_MEMBER]
Definition: brin_tuple.h:46
#define BRIN_NULLS_MASK
Definition: brin_tuple.h:79
TupleDesc bd_tupdesc
Definition: brin_internal.h:50
#define HIGHBIT
Definition: c.h:1096
#define BRIN_PLACEHOLDER_MASK
Definition: brin_tuple.h:78
uint8 bits8
Definition: c.h:381
void * palloc0(Size size)
Definition: mcxt.c:981
uintptr_t Datum
Definition: postgres.h:367
BrinOpcInfo * bd_info[FLEXIBLE_ARRAY_MEMBER]
Definition: brin_internal.h:59
BlockNumber bt_blkno
Definition: brin_tuple.h:57
#define Assert(condition)
Definition: c.h:745
size_t Size
Definition: c.h:473
#define MAXALIGN(LEN)
Definition: c.h:698
Size heap_compute_data_size(TupleDesc tupleDesc, Datum *values, bool *isnull)
Definition: heaptuple.c:119
static Datum values[MAXATTR]
Definition: bootstrap.c:165
uint8 bt_info
Definition: brin_tuple.h:68
void * palloc(Size size)
Definition: mcxt.c:950
Datum * bv_values
Definition: brin_tuple.h:29

◆ brin_free_tuple()

void brin_free_tuple ( BrinTuple tuple)

Definition at line 306 of file brin_tuple.c.

References pfree().

Referenced by summarize_range().

307 {
308  pfree(tuple);
309 }
void pfree(void *pointer)
Definition: mcxt.c:1057

◆ brin_memtuple_initialize()

BrinMemTuple* brin_memtuple_initialize ( BrinMemTuple dtuple,
BrinDesc brdesc 
)

Definition at line 382 of file brin_tuple.c.

References BrinDesc::bd_info, BrinDesc::bd_tupdesc, BrinMemTuple::bt_columns, BrinMemTuple::bt_context, BrinValues::bv_allnulls, BrinValues::bv_attno, BrinValues::bv_hasnulls, BrinValues::bv_values, i, MAXALIGN, MemoryContextReset(), TupleDescData::natts, and BrinOpcInfo::oi_nstored.

Referenced by brin_deform_tuple(), brin_new_memtuple(), brinbuildCallback(), brinsummarize(), and initialize_brin_buildstate().

383 {
384  int i;
385  char *currdatum;
386 
388 
389  currdatum = (char *) dtuple +
390  MAXALIGN(sizeof(BrinMemTuple) +
391  sizeof(BrinValues) * brdesc->bd_tupdesc->natts);
392  for (i = 0; i < brdesc->bd_tupdesc->natts; i++)
393  {
394  dtuple->bt_columns[i].bv_allnulls = true;
395  dtuple->bt_columns[i].bv_hasnulls = false;
396 
397  dtuple->bt_columns[i].bv_attno = i + 1;
398  dtuple->bt_columns[i].bv_allnulls = true;
399  dtuple->bt_columns[i].bv_hasnulls = false;
400  dtuple->bt_columns[i].bv_values = (Datum *) currdatum;
401  currdatum += sizeof(Datum) * brdesc->bd_info[i]->oi_nstored;
402  }
403 
404  return dtuple;
405 }
struct BrinValues BrinValues
bool bv_allnulls
Definition: brin_tuple.h:28
void MemoryContextReset(MemoryContext context)
Definition: mcxt.c:137
bool bv_hasnulls
Definition: brin_tuple.h:27
AttrNumber bv_attno
Definition: brin_tuple.h:26
uint16 oi_nstored
Definition: brin_internal.h:28
BrinValues bt_columns[FLEXIBLE_ARRAY_MEMBER]
Definition: brin_tuple.h:46
TupleDesc bd_tupdesc
Definition: brin_internal.h:50
uintptr_t Datum
Definition: postgres.h:367
BrinOpcInfo * bd_info[FLEXIBLE_ARRAY_MEMBER]
Definition: brin_internal.h:59
#define MAXALIGN(LEN)
Definition: c.h:698
int i
Datum * bv_values
Definition: brin_tuple.h:29
MemoryContext bt_context
Definition: brin_tuple.h:40

◆ brin_new_memtuple()

BrinMemTuple* brin_new_memtuple ( BrinDesc brdesc)

Definition at line 355 of file brin_tuple.c.

References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, BrinDesc::bd_totalstored, BrinDesc::bd_tupdesc, brin_memtuple_initialize(), BrinMemTuple::bt_allnulls, BrinMemTuple::bt_context, BrinMemTuple::bt_hasnulls, BrinMemTuple::bt_values, CurrentMemoryContext, MAXALIGN, TupleDescData::natts, palloc(), and palloc0().

Referenced by brin_deform_tuple(), bringetbitmap(), and initialize_brin_buildstate().

356 {
357  BrinMemTuple *dtup;
358  long basesize;
359 
360  basesize = MAXALIGN(sizeof(BrinMemTuple) +
361  sizeof(BrinValues) * brdesc->bd_tupdesc->natts);
362  dtup = palloc0(basesize + sizeof(Datum) * brdesc->bd_totalstored);
363 
364  dtup->bt_values = palloc(sizeof(Datum) * brdesc->bd_totalstored);
365  dtup->bt_allnulls = palloc(sizeof(bool) * brdesc->bd_tupdesc->natts);
366  dtup->bt_hasnulls = palloc(sizeof(bool) * brdesc->bd_tupdesc->natts);
367 
369  "brin dtuple",
371 
372  brin_memtuple_initialize(dtup, brdesc);
373 
374  return dtup;
375 }
#define AllocSetContextCreate
Definition: memutils.h:170
Datum * bt_values
Definition: brin_tuple.h:42
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:192
int bd_totalstored
Definition: brin_internal.h:56
TupleDesc bd_tupdesc
Definition: brin_internal.h:50
bool * bt_hasnulls
Definition: brin_tuple.h:44
MemoryContext CurrentMemoryContext
Definition: mcxt.c:38
void * palloc0(Size size)
Definition: mcxt.c:981
uintptr_t Datum
Definition: postgres.h:367
bool * bt_allnulls
Definition: brin_tuple.h:43
#define MAXALIGN(LEN)
Definition: c.h:698
void * palloc(Size size)
Definition: mcxt.c:950
BrinMemTuple * brin_memtuple_initialize(BrinMemTuple *dtuple, BrinDesc *brdesc)
Definition: brin_tuple.c:382
MemoryContext bt_context
Definition: brin_tuple.h:40

◆ brin_tuples_equal()

bool brin_tuples_equal ( const BrinTuple a,
Size  alen,
const BrinTuple b,
Size  blen 
)

Definition at line 338 of file brin_tuple.c.

Referenced by brin_doupdate().

339 {
340  if (alen != blen)
341  return false;
342  if (memcmp(a, b, alen) != 0)
343  return false;
344  return true;
345 }