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 void(* brin_serialize_callback_type) (BrinDesc *bdesc, Datum src, Datum *dst)
 
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 87 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 84 of file brin_tuple.h.

Referenced by brin_form_tuple().

◆ BRIN_PLACEHOLDER_MASK

#define BRIN_PLACEHOLDER_MASK   0x40

Definition at line 86 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 89 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 90 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 91 of file brin_tuple.h.

Referenced by brin_deform_tuple().

◆ SizeOfBrinTuple

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

Definition at line 79 of file brin_tuple.h.

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

Typedef Documentation

◆ brin_serialize_callback_type

typedef void(* brin_serialize_callback_type) (BrinDesc *bdesc, Datum src, Datum *dst)

Definition at line 21 of file brin_tuple.h.

◆ 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 444 of file brin_tuple.c.

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

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

445 {
446  if (!destsz || *destsz == 0)
447  dest = palloc(len);
448  else if (len > *destsz)
449  {
450  dest = repalloc(dest, len);
451  *destsz = len;
452  }
453 
454  memcpy(dest, tuple, len);
455 
456  return dest;
457 }
void * repalloc(void *pointer, Size size)
Definition: mcxt.c:1182
void * palloc(Size size)
Definition: mcxt.c:1062

◆ brin_deform_tuple()

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

Definition at line 547 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_context, BrinValues::bv_hasnulls, BrinValues::bv_mem_value, BrinValues::bv_serialize, BrinValues::bv_values, datumCopy(), i, MemoryContextSwitchTo(), TupleDescData::natts, BrinOpcInfo::oi_nstored, BrinOpcInfo::oi_typcache, PointerGetDatum, SizeOfBrinTuple, TypeCacheEntry::typbyval, TypeCacheEntry::typlen, and values.

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

548 {
549  BrinMemTuple *dtup;
550  Datum *values;
551  bool *allnulls;
552  bool *hasnulls;
553  char *tp;
554  bits8 *nullbits;
555  int keyno;
556  int valueno;
557  MemoryContext oldcxt;
558 
559  dtup = dMemtuple ? brin_memtuple_initialize(dMemtuple, brdesc) :
560  brin_new_memtuple(brdesc);
561 
562  if (BrinTupleIsPlaceholder(tuple))
563  dtup->bt_placeholder = true;
564  dtup->bt_blkno = tuple->bt_blkno;
565 
566  values = dtup->bt_values;
567  allnulls = dtup->bt_allnulls;
568  hasnulls = dtup->bt_hasnulls;
569 
570  tp = (char *) tuple + BrinTupleDataOffset(tuple);
571 
572  if (BrinTupleHasNulls(tuple))
573  nullbits = (bits8 *) ((char *) tuple + SizeOfBrinTuple);
574  else
575  nullbits = NULL;
576  brin_deconstruct_tuple(brdesc,
577  tp, nullbits, BrinTupleHasNulls(tuple),
578  values, allnulls, hasnulls);
579 
580  /*
581  * Iterate to assign each of the values to the corresponding item in the
582  * values array of each column. The copies occur in the tuple's context.
583  */
584  oldcxt = MemoryContextSwitchTo(dtup->bt_context);
585  for (valueno = 0, keyno = 0; keyno < brdesc->bd_tupdesc->natts; keyno++)
586  {
587  int i;
588 
589  if (allnulls[keyno])
590  {
591  valueno += brdesc->bd_info[keyno]->oi_nstored;
592  continue;
593  }
594 
595  /*
596  * We would like to skip datumCopy'ing the values datum in some cases,
597  * caller permitting ...
598  */
599  for (i = 0; i < brdesc->bd_info[keyno]->oi_nstored; i++)
600  dtup->bt_columns[keyno].bv_values[i] =
601  datumCopy(values[valueno++],
602  brdesc->bd_info[keyno]->oi_typcache[i]->typbyval,
603  brdesc->bd_info[keyno]->oi_typcache[i]->typlen);
604 
605  dtup->bt_columns[keyno].bv_hasnulls = hasnulls[keyno];
606  dtup->bt_columns[keyno].bv_allnulls = false;
607 
608  dtup->bt_columns[keyno].bv_mem_value = PointerGetDatum(NULL);
609  dtup->bt_columns[keyno].bv_serialize = NULL;
610  dtup->bt_columns[keyno].bv_context = dtup->bt_context;
611  }
612 
613  MemoryContextSwitchTo(oldcxt);
614 
615  return dtup;
616 }
#define BrinTupleIsPlaceholder(tup)
Definition: brin_tuple.h:91
#define SizeOfBrinTuple
Definition: brin_tuple.h:79
#define BrinTupleHasNulls(tup)
Definition: brin_tuple.h:90
#define PointerGetDatum(X)
Definition: postgres.h:600
BlockNumber bt_blkno
Definition: brin_tuple.h:47
bool bv_allnulls
Definition: brin_tuple.h:33
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
BrinMemTuple * brin_new_memtuple(BrinDesc *brdesc)
Definition: brin_tuple.c:480
int16 typlen
Definition: typcache.h:39
bool typbyval
Definition: typcache.h:40
Datum * bt_values
Definition: brin_tuple.h:50
bool bt_placeholder
Definition: brin_tuple.h:46
bool bv_hasnulls
Definition: brin_tuple.h:32
TypeCacheEntry * oi_typcache[FLEXIBLE_ARRAY_MEMBER]
Definition: brin_internal.h:37
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:634
BrinValues bt_columns[FLEXIBLE_ARRAY_MEMBER]
Definition: brin_tuple.h:54
TupleDesc bd_tupdesc
Definition: brin_internal.h:53
bool * bt_hasnulls
Definition: brin_tuple.h:52
Datum datumCopy(Datum value, bool typByVal, int typLen)
Definition: datum.c:131
uint8 bits8
Definition: c.h:448
uintptr_t Datum
Definition: postgres.h:411
brin_serialize_callback_type bv_serialize
Definition: brin_tuple.h:37
BrinOpcInfo * bd_info[FLEXIBLE_ARRAY_MEMBER]
Definition: brin_internal.h:62
BlockNumber bt_blkno
Definition: brin_tuple.h:65
bool * bt_allnulls
Definition: brin_tuple.h:51
Datum bv_mem_value
Definition: brin_tuple.h:35
static Datum values[MAXATTR]
Definition: bootstrap.c:166
#define BrinTupleDataOffset(tup)
Definition: brin_tuple.h:89
int i
MemoryContext bv_context
Definition: brin_tuple.h:36
Datum * bv_values
Definition: brin_tuple.h:34
BrinMemTuple * brin_memtuple_initialize(BrinMemTuple *dtuple, BrinDesc *brdesc)
Definition: brin_tuple.c:507
MemoryContext bt_context
Definition: brin_tuple.h:48

◆ brin_form_placeholder_tuple()

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

Definition at line 386 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().

387 {
388  Size len;
389  Size hoff;
390  BrinTuple *rettuple;
391  int keyno;
392  bits8 *bitP;
393  int bitmask;
394 
395  /* compute total space needed: always add nulls */
396  len = SizeOfBrinTuple;
397  len += BITMAPLEN(brdesc->bd_tupdesc->natts * 2);
398  len = hoff = MAXALIGN(len);
399 
400  rettuple = palloc0(len);
401  rettuple->bt_blkno = blkno;
402  rettuple->bt_info = hoff;
404 
405  bitP = ((bits8 *) ((char *) rettuple + SizeOfBrinTuple)) - 1;
406  bitmask = HIGHBIT;
407  /* set allnulls true for all attributes */
408  for (keyno = 0; keyno < brdesc->bd_tupdesc->natts; keyno++)
409  {
410  if (bitmask != HIGHBIT)
411  bitmask <<= 1;
412  else
413  {
414  bitP += 1;
415  *bitP = 0x0;
416  bitmask = 1;
417  }
418 
419  *bitP |= bitmask;
420  }
421  /* no need to set hasnulls */
422 
423  *size = len;
424  return rettuple;
425 }
#define SizeOfBrinTuple
Definition: brin_tuple.h:79
#define BITMAPLEN(NATTS)
Definition: htup_details.h:546
#define BRIN_NULLS_MASK
Definition: brin_tuple.h:87
TupleDesc bd_tupdesc
Definition: brin_internal.h:53
#define HIGHBIT
Definition: c.h:1155
#define BRIN_PLACEHOLDER_MASK
Definition: brin_tuple.h:86
uint8 bits8
Definition: c.h:448
void * palloc0(Size size)
Definition: mcxt.c:1093
BlockNumber bt_blkno
Definition: brin_tuple.h:65
size_t Size
Definition: c.h:540
#define MAXALIGN(LEN)
Definition: c.h:757
uint8 bt_info
Definition: brin_tuple.h:76

◆ brin_form_tuple()

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

Definition at line 99 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_mem_value, BrinValues::bv_serialize, BrinValues::bv_values, CompressionMethodIsValid, DatumGetPointer, detoast_external_attr(), GetDefaultToastCompression(), heap_compute_data_size(), heap_fill_tuple(), HIGHBIT, i, MAXALIGN, TupleDescData::natts, BrinOpcInfo::oi_nstored, BrinOpcInfo::oi_typcache, palloc(), palloc0(), pfree(), PointerGetDatum, SizeOfBrinTuple, toast_compress_datum(), TOAST_INDEX_TARGET, TupleDescAttr, TypeCacheEntry::type_id, TypeCacheEntry::typlen, TypeCacheEntry::typstorage, value, values, VARATT_IS_EXTENDED, VARATT_IS_EXTERNAL, and VARSIZE.

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

101 {
102  Datum *values;
103  bool *nulls;
104  bool anynulls = false;
105  BrinTuple *rettuple;
106  int keyno;
107  int idxattno;
108  uint16 phony_infomask = 0;
109  bits8 *phony_nullbitmap;
110  Size len,
111  hoff,
112  data_len;
113  int i;
114 
115 #ifdef TOAST_INDEX_HACK
116  Datum *untoasted_values;
117  int nuntoasted = 0;
118 #endif
119 
120  Assert(brdesc->bd_totalstored > 0);
121 
122  values = (Datum *) palloc(sizeof(Datum) * brdesc->bd_totalstored);
123  nulls = (bool *) palloc0(sizeof(bool) * brdesc->bd_totalstored);
124  phony_nullbitmap = (bits8 *)
125  palloc(sizeof(bits8) * BITMAPLEN(brdesc->bd_totalstored));
126 
127 #ifdef TOAST_INDEX_HACK
128  untoasted_values = (Datum *) palloc(sizeof(Datum) * brdesc->bd_totalstored);
129 #endif
130 
131  /*
132  * Set up the values/nulls arrays for heap_fill_tuple
133  */
134  idxattno = 0;
135  for (keyno = 0; keyno < brdesc->bd_tupdesc->natts; keyno++)
136  {
137  int datumno;
138 
139  /*
140  * "allnulls" is set when there's no nonnull value in any row in the
141  * column; when this happens, there is no data to store. Thus set the
142  * nullable bits for all data elements of this column and we're done.
143  */
144  if (tuple->bt_columns[keyno].bv_allnulls)
145  {
146  for (datumno = 0;
147  datumno < brdesc->bd_info[keyno]->oi_nstored;
148  datumno++)
149  nulls[idxattno++] = true;
150  anynulls = true;
151  continue;
152  }
153 
154  /*
155  * The "hasnulls" bit is set when there are some null values in the
156  * data. We still need to store a real value, but the presence of
157  * this means we need a null bitmap.
158  */
159  if (tuple->bt_columns[keyno].bv_hasnulls)
160  anynulls = true;
161 
162  /* If needed, serialize the values before forming the on-disk tuple. */
163  if (tuple->bt_columns[keyno].bv_serialize)
164  {
165  tuple->bt_columns[keyno].bv_serialize(brdesc,
166  tuple->bt_columns[keyno].bv_mem_value,
167  tuple->bt_columns[keyno].bv_values);
168  }
169 
170  /*
171  * Now obtain the values of each stored datum. Note that some values
172  * might be toasted, and we cannot rely on the original heap values
173  * sticking around forever, so we must detoast them. Also try to
174  * compress them.
175  */
176  for (datumno = 0;
177  datumno < brdesc->bd_info[keyno]->oi_nstored;
178  datumno++)
179  {
180  Datum value = tuple->bt_columns[keyno].bv_values[datumno];
181 
182 #ifdef TOAST_INDEX_HACK
183 
184  /* We must look at the stored type, not at the index descriptor. */
185  TypeCacheEntry *atttype = brdesc->bd_info[keyno]->oi_typcache[datumno];
186 
187  /* Do we need to free the value at the end? */
188  bool free_value = false;
189 
190  /* For non-varlena types we don't need to do anything special */
191  if (atttype->typlen != -1)
192  {
193  values[idxattno++] = value;
194  continue;
195  }
196 
197  /*
198  * Do nothing if value is not of varlena type. We don't need to
199  * care about NULL values here, thanks to bv_allnulls above.
200  *
201  * If value is stored EXTERNAL, must fetch it so we are not
202  * depending on outside storage.
203  *
204  * XXX Is this actually true? Could it be that the summary is NULL
205  * even for range with non-NULL data? E.g. degenerate bloom filter
206  * may be thrown away, etc.
207  */
209  {
211  DatumGetPointer(value)));
212  free_value = true;
213  }
214 
215  /*
216  * If value is above size target, and is of a compressible
217  * datatype, try to compress it in-line.
218  */
219  if (!VARATT_IS_EXTENDED(DatumGetPointer(value)) &&
221  (atttype->typstorage == TYPSTORAGE_EXTENDED ||
222  atttype->typstorage == TYPSTORAGE_MAIN))
223  {
224  Datum cvalue;
225  char compression;
227  keyno);
228 
229  /*
230  * If the BRIN summary and indexed attribute use the same data
231  * type and it has a valid compression method, we can use the
232  * same compression method. Otherwise we have to use the
233  * default method.
234  */
235  if (att->atttypid == atttype->type_id &&
236  CompressionMethodIsValid(att->attcompression))
237  compression = att->attcompression;
238  else
239  compression = GetDefaultToastCompression();
240 
241  cvalue = toast_compress_datum(value, compression);
242 
243  if (DatumGetPointer(cvalue) != NULL)
244  {
245  /* successful compression */
246  if (free_value)
247  pfree(DatumGetPointer(value));
248 
249  value = cvalue;
250  free_value = true;
251  }
252  }
253 
254  /*
255  * If we untoasted / compressed the value, we need to free it
256  * after forming the index tuple.
257  */
258  if (free_value)
259  untoasted_values[nuntoasted++] = value;
260 
261 #endif
262 
263  values[idxattno++] = value;
264  }
265  }
266 
267  /* Assert we did not overrun temp arrays */
268  Assert(idxattno <= brdesc->bd_totalstored);
269 
270  /* compute total space needed */
271  len = SizeOfBrinTuple;
272  if (anynulls)
273  {
274  /*
275  * We need a double-length bitmap on an on-disk BRIN index tuple; the
276  * first half stores the "allnulls" bits, the second stores
277  * "hasnulls".
278  */
279  len += BITMAPLEN(brdesc->bd_tupdesc->natts * 2);
280  }
281 
282  len = hoff = MAXALIGN(len);
283 
284  data_len = heap_compute_data_size(brtuple_disk_tupdesc(brdesc),
285  values, nulls);
286  len += data_len;
287 
288  len = MAXALIGN(len);
289 
290  rettuple = palloc0(len);
291  rettuple->bt_blkno = blkno;
292  rettuple->bt_info = hoff;
293 
294  /* Assert that hoff fits in the space available */
295  Assert((rettuple->bt_info & BRIN_OFFSET_MASK) == hoff);
296 
297  /*
298  * The infomask and null bitmap as computed by heap_fill_tuple are useless
299  * to us. However, that function will not accept a null infomask; and we
300  * need to pass a valid null bitmap so that it will correctly skip
301  * outputting null attributes in the data area.
302  */
304  values,
305  nulls,
306  (char *) rettuple + hoff,
307  data_len,
308  &phony_infomask,
309  phony_nullbitmap);
310 
311  /* done with these */
312  pfree(values);
313  pfree(nulls);
314  pfree(phony_nullbitmap);
315 
316 #ifdef TOAST_INDEX_HACK
317  for (i = 0; i < nuntoasted; i++)
318  pfree(DatumGetPointer(untoasted_values[i]));
319 #endif
320 
321  /*
322  * Now fill in the real null bitmasks. allnulls first.
323  */
324  if (anynulls)
325  {
326  bits8 *bitP;
327  int bitmask;
328 
329  rettuple->bt_info |= BRIN_NULLS_MASK;
330 
331  /*
332  * Note that we reverse the sense of null bits in this module: we
333  * store a 1 for a null attribute rather than a 0. So we must reverse
334  * the sense of the att_isnull test in brin_deconstruct_tuple as well.
335  */
336  bitP = ((bits8 *) ((char *) rettuple + SizeOfBrinTuple)) - 1;
337  bitmask = HIGHBIT;
338  for (keyno = 0; keyno < brdesc->bd_tupdesc->natts; keyno++)
339  {
340  if (bitmask != HIGHBIT)
341  bitmask <<= 1;
342  else
343  {
344  bitP += 1;
345  *bitP = 0x0;
346  bitmask = 1;
347  }
348 
349  if (!tuple->bt_columns[keyno].bv_allnulls)
350  continue;
351 
352  *bitP |= bitmask;
353  }
354  /* hasnulls bits follow */
355  for (keyno = 0; keyno < brdesc->bd_tupdesc->natts; keyno++)
356  {
357  if (bitmask != HIGHBIT)
358  bitmask <<= 1;
359  else
360  {
361  bitP += 1;
362  *bitP = 0x0;
363  bitmask = 1;
364  }
365 
366  if (!tuple->bt_columns[keyno].bv_hasnulls)
367  continue;
368 
369  *bitP |= bitmask;
370  }
371  }
372 
373  if (tuple->bt_placeholder)
374  rettuple->bt_info |= BRIN_PLACEHOLDER_MASK;
375 
376  *size = len;
377  return rettuple;
378 }
#define BRIN_OFFSET_MASK
Definition: brin_tuple.h:84
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:79
Datum toast_compress_datum(Datum value, char cmethod)
static struct @142 value
#define CompressionMethodIsValid(cm)
#define VARSIZE(PTR)
Definition: postgres.h:316
#define PointerGetDatum(X)
Definition: postgres.h:600
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
struct varlena * detoast_external_attr(struct varlena *attr)
Definition: detoast.c:45
bool bv_allnulls
Definition: brin_tuple.h:33
#define BITMAPLEN(NATTS)
Definition: htup_details.h:546
int16 typlen
Definition: typcache.h:39
#define VARATT_IS_EXTERNAL(PTR)
Definition: postgres.h:326
static char GetDefaultToastCompression(void)
unsigned short uint16
Definition: c.h:440
void pfree(void *pointer)
Definition: mcxt.c:1169
static TupleDesc brtuple_disk_tupdesc(BrinDesc *brdesc)
Definition: brin_tuple.c:61
bool bt_placeholder
Definition: brin_tuple.h:46
#define TOAST_INDEX_TARGET
Definition: heaptoast.h:68
bool bv_hasnulls
Definition: brin_tuple.h:32
TypeCacheEntry * oi_typcache[FLEXIBLE_ARRAY_MEMBER]
Definition: brin_internal.h:37
uint16 oi_nstored
Definition: brin_internal.h:28
int bd_totalstored
Definition: brin_internal.h:59
BrinValues bt_columns[FLEXIBLE_ARRAY_MEMBER]
Definition: brin_tuple.h:54
#define BRIN_NULLS_MASK
Definition: brin_tuple.h:87
char typstorage
Definition: typcache.h:42
TupleDesc bd_tupdesc
Definition: brin_internal.h:53
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:203
#define HIGHBIT
Definition: c.h:1155
#define BRIN_PLACEHOLDER_MASK
Definition: brin_tuple.h:86
uint8 bits8
Definition: c.h:448
void * palloc0(Size size)
Definition: mcxt.c:1093
uintptr_t Datum
Definition: postgres.h:411
brin_serialize_callback_type bv_serialize
Definition: brin_tuple.h:37
BrinOpcInfo * bd_info[FLEXIBLE_ARRAY_MEMBER]
Definition: brin_internal.h:62
BlockNumber bt_blkno
Definition: brin_tuple.h:65
#define Assert(condition)
Definition: c.h:804
Datum bv_mem_value
Definition: brin_tuple.h:35
size_t Size
Definition: c.h:540
#define MAXALIGN(LEN)
Definition: c.h:757
Size heap_compute_data_size(TupleDesc tupleDesc, Datum *values, bool *isnull)
Definition: heaptuple.c:119
#define VARATT_IS_EXTENDED(PTR)
Definition: postgres.h:340
#define DatumGetPointer(X)
Definition: postgres.h:593
static Datum values[MAXATTR]
Definition: bootstrap.c:166
uint8 bt_info
Definition: brin_tuple.h:76
void * palloc(Size size)
Definition: mcxt.c:1062
int i
Definition: c.h:621
Datum * bv_values
Definition: brin_tuple.h:34

◆ brin_free_tuple()

void brin_free_tuple ( BrinTuple tuple)

Definition at line 431 of file brin_tuple.c.

References pfree().

Referenced by summarize_range().

432 {
433  pfree(tuple);
434 }
void pfree(void *pointer)
Definition: mcxt.c:1169

◆ brin_memtuple_initialize()

BrinMemTuple* brin_memtuple_initialize ( BrinMemTuple dtuple,
BrinDesc brdesc 
)

Definition at line 507 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_context, BrinValues::bv_hasnulls, BrinValues::bv_mem_value, BrinValues::bv_serialize, BrinValues::bv_values, i, MAXALIGN, MemoryContextReset(), TupleDescData::natts, BrinOpcInfo::oi_nstored, and PointerGetDatum.

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

508 {
509  int i;
510  char *currdatum;
511 
513 
514  currdatum = (char *) dtuple +
515  MAXALIGN(sizeof(BrinMemTuple) +
516  sizeof(BrinValues) * brdesc->bd_tupdesc->natts);
517  for (i = 0; i < brdesc->bd_tupdesc->natts; i++)
518  {
519  dtuple->bt_columns[i].bv_attno = i + 1;
520  dtuple->bt_columns[i].bv_allnulls = true;
521  dtuple->bt_columns[i].bv_hasnulls = false;
522  dtuple->bt_columns[i].bv_values = (Datum *) currdatum;
523 
524  dtuple->bt_columns[i].bv_mem_value = PointerGetDatum(NULL);
525  dtuple->bt_columns[i].bv_serialize = NULL;
526  dtuple->bt_columns[i].bv_context = dtuple->bt_context;
527 
528  currdatum += sizeof(Datum) * brdesc->bd_info[i]->oi_nstored;
529  }
530 
531  return dtuple;
532 }
struct BrinValues BrinValues
#define PointerGetDatum(X)
Definition: postgres.h:600
bool bv_allnulls
Definition: brin_tuple.h:33
void MemoryContextReset(MemoryContext context)
Definition: mcxt.c:143
bool bv_hasnulls
Definition: brin_tuple.h:32
AttrNumber bv_attno
Definition: brin_tuple.h:31
uint16 oi_nstored
Definition: brin_internal.h:28
BrinValues bt_columns[FLEXIBLE_ARRAY_MEMBER]
Definition: brin_tuple.h:54
TupleDesc bd_tupdesc
Definition: brin_internal.h:53
uintptr_t Datum
Definition: postgres.h:411
brin_serialize_callback_type bv_serialize
Definition: brin_tuple.h:37
BrinOpcInfo * bd_info[FLEXIBLE_ARRAY_MEMBER]
Definition: brin_internal.h:62
Datum bv_mem_value
Definition: brin_tuple.h:35
#define MAXALIGN(LEN)
Definition: c.h:757
int i
MemoryContext bv_context
Definition: brin_tuple.h:36
Datum * bv_values
Definition: brin_tuple.h:34
MemoryContext bt_context
Definition: brin_tuple.h:48

◆ brin_new_memtuple()

BrinMemTuple* brin_new_memtuple ( BrinDesc brdesc)

Definition at line 480 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().

481 {
482  BrinMemTuple *dtup;
483  long basesize;
484 
485  basesize = MAXALIGN(sizeof(BrinMemTuple) +
486  sizeof(BrinValues) * brdesc->bd_tupdesc->natts);
487  dtup = palloc0(basesize + sizeof(Datum) * brdesc->bd_totalstored);
488 
489  dtup->bt_values = palloc(sizeof(Datum) * brdesc->bd_totalstored);
490  dtup->bt_allnulls = palloc(sizeof(bool) * brdesc->bd_tupdesc->natts);
491  dtup->bt_hasnulls = palloc(sizeof(bool) * brdesc->bd_tupdesc->natts);
492 
494  "brin dtuple",
496 
497  brin_memtuple_initialize(dtup, brdesc);
498 
499  return dtup;
500 }
#define AllocSetContextCreate
Definition: memutils.h:173
Datum * bt_values
Definition: brin_tuple.h:50
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:195
int bd_totalstored
Definition: brin_internal.h:59
TupleDesc bd_tupdesc
Definition: brin_internal.h:53
bool * bt_hasnulls
Definition: brin_tuple.h:52
MemoryContext CurrentMemoryContext
Definition: mcxt.c:42
void * palloc0(Size size)
Definition: mcxt.c:1093
uintptr_t Datum
Definition: postgres.h:411
bool * bt_allnulls
Definition: brin_tuple.h:51
#define MAXALIGN(LEN)
Definition: c.h:757
void * palloc(Size size)
Definition: mcxt.c:1062
BrinMemTuple * brin_memtuple_initialize(BrinMemTuple *dtuple, BrinDesc *brdesc)
Definition: brin_tuple.c:507
MemoryContext bt_context
Definition: brin_tuple.h:48

◆ brin_tuples_equal()

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

Definition at line 463 of file brin_tuple.c.

Referenced by brin_doupdate().

464 {
465  if (alen != blen)
466  return false;
467  if (memcmp(a, b, alen) != 0)
468  return false;
469  return true;
470 }