PostgreSQL Source Code  git master
brin_tuple.c File Reference
#include "postgres.h"
#include "access/brin_tuple.h"
#include "access/detoast.h"
#include "access/heaptoast.h"
#include "access/htup_details.h"
#include "access/toast_internals.h"
#include "access/tupdesc.h"
#include "access/tupmacs.h"
#include "utils/datum.h"
#include "utils/memutils.h"
Include dependency graph for brin_tuple.c:

Go to the source code of this file.

Macros

#define TOAST_INDEX_HACK
 

Functions

static void brin_deconstruct_tuple (BrinDesc *brdesc, char *tp, bits8 *nullbits, bool nulls, Datum *values, bool *allnulls, bool *hasnulls)
 
static TupleDesc brtuple_disk_tupdesc (BrinDesc *brdesc)
 
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

◆ TOAST_INDEX_HACK

#define TOAST_INDEX_HACK

Definition at line 49 of file brin_tuple.c.

Function Documentation

◆ brin_copy_tuple()

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

Definition at line 419 of file brin_tuple.c.

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

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

420 {
421  if (!destsz || *destsz == 0)
422  dest = palloc(len);
423  else if (len > *destsz)
424  {
425  dest = repalloc(dest, len);
426  *destsz = len;
427  }
428 
429  memcpy(dest, tuple, len);
430 
431  return dest;
432 }
void * repalloc(void *pointer, Size size)
Definition: mcxt.c:1070
void * palloc(Size size)
Definition: mcxt.c:950

◆ brin_deconstruct_tuple()

static void brin_deconstruct_tuple ( BrinDesc brdesc,
char *  tp,
bits8 nullbits,
bool  nulls,
Datum values,
bool allnulls,
bool hasnulls 
)
inlinestatic

Definition at line 600 of file brin_tuple.c.

References att_addlength_pointer, att_align_nominal, att_align_pointer, att_isnull, attnum, BrinDesc::bd_info, BrinDesc::bd_tupdesc, brtuple_disk_tupdesc(), fetchatt, TupleDescData::natts, BrinOpcInfo::oi_nstored, and TupleDescAttr.

Referenced by brin_deform_tuple().

603 {
604  int attnum;
605  int stored;
606  TupleDesc diskdsc;
607  long off;
608 
609  /*
610  * First iterate to natts to obtain both null flags for each attribute.
611  * Note that we reverse the sense of the att_isnull test, because we store
612  * 1 for a null value (rather than a 1 for a not null value as is the
613  * att_isnull convention used elsewhere.) See brin_form_tuple.
614  */
615  for (attnum = 0; attnum < brdesc->bd_tupdesc->natts; attnum++)
616  {
617  /*
618  * the "all nulls" bit means that all values in the page range for
619  * this column are nulls. Therefore there are no values in the tuple
620  * data area.
621  */
622  allnulls[attnum] = nulls && !att_isnull(attnum, nullbits);
623 
624  /*
625  * the "has nulls" bit means that some tuples have nulls, but others
626  * have not-null values. Therefore we know the tuple contains data
627  * for this column.
628  *
629  * The hasnulls bits follow the allnulls bits in the same bitmask.
630  */
631  hasnulls[attnum] =
632  nulls && !att_isnull(brdesc->bd_tupdesc->natts + attnum, nullbits);
633  }
634 
635  /*
636  * Iterate to obtain each attribute's stored values. Note that since we
637  * may reuse attribute entries for more than one column, we cannot cache
638  * offsets here.
639  */
640  diskdsc = brtuple_disk_tupdesc(brdesc);
641  stored = 0;
642  off = 0;
643  for (attnum = 0; attnum < brdesc->bd_tupdesc->natts; attnum++)
644  {
645  int datumno;
646 
647  if (allnulls[attnum])
648  {
649  stored += brdesc->bd_info[attnum]->oi_nstored;
650  continue;
651  }
652 
653  for (datumno = 0;
654  datumno < brdesc->bd_info[attnum]->oi_nstored;
655  datumno++)
656  {
657  Form_pg_attribute thisatt = TupleDescAttr(diskdsc, stored);
658 
659  if (thisatt->attlen == -1)
660  {
661  off = att_align_pointer(off, thisatt->attalign, -1,
662  tp + off);
663  }
664  else
665  {
666  /* not varlena, so safe to use att_align_nominal */
667  off = att_align_nominal(off, thisatt->attalign);
668  }
669 
670  values[stored++] = fetchatt(thisatt, tp + off);
671 
672  off = att_addlength_pointer(off, thisatt->attlen, tp + off);
673  }
674  }
675 }
#define att_align_nominal(cur_offset, attalign)
Definition: tupmacs.h:148
#define att_isnull(ATT, BITS)
Definition: tupmacs.h:25
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
#define fetchatt(A, T)
Definition: tupmacs.h:41
static TupleDesc brtuple_disk_tupdesc(BrinDesc *brdesc)
Definition: brin_tuple.c:61
uint16 oi_nstored
Definition: brin_internal.h:28
TupleDesc bd_tupdesc
Definition: brin_internal.h:50
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:193
#define att_addlength_pointer(cur_offset, attlen, attptr)
Definition: tupmacs.h:176
#define att_align_pointer(cur_offset, attalign, attlen, attptr)
Definition: tupmacs.h:126
BrinOpcInfo * bd_info[FLEXIBLE_ARRAY_MEMBER]
Definition: brin_internal.h:59
int16 attnum
Definition: pg_attribute.h:79
static Datum values[MAXATTR]
Definition: bootstrap.c:165

◆ brin_deform_tuple()

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

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

518 {
519  BrinMemTuple *dtup;
520  Datum *values;
521  bool *allnulls;
522  bool *hasnulls;
523  char *tp;
524  bits8 *nullbits;
525  int keyno;
526  int valueno;
527  MemoryContext oldcxt;
528 
529  dtup = dMemtuple ? brin_memtuple_initialize(dMemtuple, brdesc) :
530  brin_new_memtuple(brdesc);
531 
532  if (BrinTupleIsPlaceholder(tuple))
533  dtup->bt_placeholder = true;
534  dtup->bt_blkno = tuple->bt_blkno;
535 
536  values = dtup->bt_values;
537  allnulls = dtup->bt_allnulls;
538  hasnulls = dtup->bt_hasnulls;
539 
540  tp = (char *) tuple + BrinTupleDataOffset(tuple);
541 
542  if (BrinTupleHasNulls(tuple))
543  nullbits = (bits8 *) ((char *) tuple + SizeOfBrinTuple);
544  else
545  nullbits = NULL;
546  brin_deconstruct_tuple(brdesc,
547  tp, nullbits, BrinTupleHasNulls(tuple),
548  values, allnulls, hasnulls);
549 
550  /*
551  * Iterate to assign each of the values to the corresponding item in the
552  * values array of each column. The copies occur in the tuple's context.
553  */
554  oldcxt = MemoryContextSwitchTo(dtup->bt_context);
555  for (valueno = 0, keyno = 0; keyno < brdesc->bd_tupdesc->natts; keyno++)
556  {
557  int i;
558 
559  if (allnulls[keyno])
560  {
561  valueno += brdesc->bd_info[keyno]->oi_nstored;
562  continue;
563  }
564 
565  /*
566  * We would like to skip datumCopy'ing the values datum in some cases,
567  * caller permitting ...
568  */
569  for (i = 0; i < brdesc->bd_info[keyno]->oi_nstored; i++)
570  dtup->bt_columns[keyno].bv_values[i] =
571  datumCopy(values[valueno++],
572  brdesc->bd_info[keyno]->oi_typcache[i]->typbyval,
573  brdesc->bd_info[keyno]->oi_typcache[i]->typlen);
574 
575  dtup->bt_columns[keyno].bv_hasnulls = hasnulls[keyno];
576  dtup->bt_columns[keyno].bv_allnulls = false;
577  }
578 
579  MemoryContextSwitchTo(oldcxt);
580 
581  return dtup;
582 }
#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:455
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:600
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:436
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:482
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 361 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().

362 {
363  Size len;
364  Size hoff;
365  BrinTuple *rettuple;
366  int keyno;
367  bits8 *bitP;
368  int bitmask;
369 
370  /* compute total space needed: always add nulls */
371  len = SizeOfBrinTuple;
372  len += BITMAPLEN(brdesc->bd_tupdesc->natts * 2);
373  len = hoff = MAXALIGN(len);
374 
375  rettuple = palloc0(len);
376  rettuple->bt_blkno = blkno;
377  rettuple->bt_info = hoff;
379 
380  bitP = ((bits8 *) ((char *) rettuple + SizeOfBrinTuple)) - 1;
381  bitmask = HIGHBIT;
382  /* set allnulls true for all attributes */
383  for (keyno = 0; keyno < brdesc->bd_tupdesc->natts; keyno++)
384  {
385  if (bitmask != HIGHBIT)
386  bitmask <<= 1;
387  else
388  {
389  bitP += 1;
390  *bitP = 0x0;
391  bitmask = 1;
392  }
393 
394  *bitP |= bitmask;
395  }
396  /* no need to set hasnulls */
397 
398  *size = len;
399  return rettuple;
400 }
#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:1151
#define BRIN_PLACEHOLDER_MASK
Definition: brin_tuple.h:78
uint8 bits8
Definition: c.h:436
void * palloc0(Size size)
Definition: mcxt.c:981
BlockNumber bt_blkno
Definition: brin_tuple.h:57
size_t Size
Definition: c.h:528
#define MAXALIGN(LEN)
Definition: c.h:753
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 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_values, DatumGetPointer, detoast_external_attr(), 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, 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  /*
163  * Now obtain the values of each stored datum. Note that some values
164  * might be toasted, and we cannot rely on the original heap values
165  * sticking around forever, so we must detoast them. Also try to
166  * compress them.
167  */
168  for (datumno = 0;
169  datumno < brdesc->bd_info[keyno]->oi_nstored;
170  datumno++)
171  {
172  Datum value = tuple->bt_columns[keyno].bv_values[datumno];
173 
174 #ifdef TOAST_INDEX_HACK
175 
176  /* We must look at the stored type, not at the index descriptor. */
177  TypeCacheEntry *atttype = brdesc->bd_info[keyno]->oi_typcache[datumno];
178 
179  /* Do we need to free the value at the end? */
180  bool free_value = false;
181 
182  /* For non-varlena types we don't need to do anything special */
183  if (atttype->typlen != -1)
184  {
185  values[idxattno++] = value;
186  continue;
187  }
188 
189  /*
190  * Do nothing if value is not of varlena type. We don't need to
191  * care about NULL values here, thanks to bv_allnulls above.
192  *
193  * If value is stored EXTERNAL, must fetch it so we are not
194  * depending on outside storage.
195  *
196  * XXX Is this actually true? Could it be that the summary is
197  * NULL even for range with non-NULL data? E.g. degenerate bloom
198  * filter may be thrown away, etc.
199  */
201  {
203  DatumGetPointer(value)));
204  free_value = true;
205  }
206 
207  /*
208  * If value is above size target, and is of a compressible datatype,
209  * try to compress it in-line.
210  */
211  if (!VARATT_IS_EXTENDED(DatumGetPointer(value)) &&
213  (atttype->typstorage == TYPSTORAGE_EXTENDED ||
214  atttype->typstorage == TYPSTORAGE_MAIN))
215  {
216  Datum cvalue = toast_compress_datum(value);
217 
218  if (DatumGetPointer(cvalue) != NULL)
219  {
220  /* successful compression */
221  if (free_value)
222  pfree(DatumGetPointer(value));
223 
224  value = cvalue;
225  free_value = true;
226  }
227  }
228 
229  /*
230  * If we untoasted / compressed the value, we need to free it
231  * after forming the index tuple.
232  */
233  if (free_value)
234  untoasted_values[nuntoasted++] = value;
235 
236 #endif
237 
238  values[idxattno++] = value;
239  }
240  }
241 
242  /* Assert we did not overrun temp arrays */
243  Assert(idxattno <= brdesc->bd_totalstored);
244 
245  /* compute total space needed */
246  len = SizeOfBrinTuple;
247  if (anynulls)
248  {
249  /*
250  * We need a double-length bitmap on an on-disk BRIN index tuple; the
251  * first half stores the "allnulls" bits, the second stores
252  * "hasnulls".
253  */
254  len += BITMAPLEN(brdesc->bd_tupdesc->natts * 2);
255  }
256 
257  len = hoff = MAXALIGN(len);
258 
259  data_len = heap_compute_data_size(brtuple_disk_tupdesc(brdesc),
260  values, nulls);
261  len += data_len;
262 
263  len = MAXALIGN(len);
264 
265  rettuple = palloc0(len);
266  rettuple->bt_blkno = blkno;
267  rettuple->bt_info = hoff;
268 
269  /* Assert that hoff fits in the space available */
270  Assert((rettuple->bt_info & BRIN_OFFSET_MASK) == hoff);
271 
272  /*
273  * The infomask and null bitmap as computed by heap_fill_tuple are useless
274  * to us. However, that function will not accept a null infomask; and we
275  * need to pass a valid null bitmap so that it will correctly skip
276  * outputting null attributes in the data area.
277  */
279  values,
280  nulls,
281  (char *) rettuple + hoff,
282  data_len,
283  &phony_infomask,
284  phony_nullbitmap);
285 
286  /* done with these */
287  pfree(values);
288  pfree(nulls);
289  pfree(phony_nullbitmap);
290 
291 #ifdef TOAST_INDEX_HACK
292  for (i = 0; i < nuntoasted; i++)
293  pfree(DatumGetPointer(untoasted_values[i]));
294 #endif
295 
296  /*
297  * Now fill in the real null bitmasks. allnulls first.
298  */
299  if (anynulls)
300  {
301  bits8 *bitP;
302  int bitmask;
303 
304  rettuple->bt_info |= BRIN_NULLS_MASK;
305 
306  /*
307  * Note that we reverse the sense of null bits in this module: we
308  * store a 1 for a null attribute rather than a 0. So we must reverse
309  * the sense of the att_isnull test in brin_deconstruct_tuple as well.
310  */
311  bitP = ((bits8 *) ((char *) rettuple + SizeOfBrinTuple)) - 1;
312  bitmask = HIGHBIT;
313  for (keyno = 0; keyno < brdesc->bd_tupdesc->natts; keyno++)
314  {
315  if (bitmask != HIGHBIT)
316  bitmask <<= 1;
317  else
318  {
319  bitP += 1;
320  *bitP = 0x0;
321  bitmask = 1;
322  }
323 
324  if (!tuple->bt_columns[keyno].bv_allnulls)
325  continue;
326 
327  *bitP |= bitmask;
328  }
329  /* hasnulls bits follow */
330  for (keyno = 0; keyno < brdesc->bd_tupdesc->natts; keyno++)
331  {
332  if (bitmask != HIGHBIT)
333  bitmask <<= 1;
334  else
335  {
336  bitP += 1;
337  *bitP = 0x0;
338  bitmask = 1;
339  }
340 
341  if (!tuple->bt_columns[keyno].bv_hasnulls)
342  continue;
343 
344  *bitP |= bitmask;
345  }
346  }
347 
348  if (tuple->bt_placeholder)
349  rettuple->bt_info |= BRIN_PLACEHOLDER_MASK;
350 
351  *size = len;
352  return rettuple;
353 }
#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
#define VARSIZE(PTR)
Definition: postgres.h:303
#define PointerGetDatum(X)
Definition: postgres.h:556
struct varlena * detoast_external_attr(struct varlena *attr)
Definition: detoast.c:44
bool bv_allnulls
Definition: brin_tuple.h:28
#define BITMAPLEN(NATTS)
Definition: htup_details.h:547
int16 typlen
Definition: typcache.h:39
#define VARATT_IS_EXTERNAL(PTR)
Definition: postgres.h:313
unsigned short uint16
Definition: c.h:428
void pfree(void *pointer)
Definition: mcxt.c:1057
static TupleDesc brtuple_disk_tupdesc(BrinDesc *brdesc)
Definition: brin_tuple.c:61
bool bt_placeholder
Definition: brin_tuple.h:38
#define TOAST_INDEX_TARGET
Definition: heaptoast.h:68
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
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
char typstorage
Definition: typcache.h:42
TupleDesc bd_tupdesc
Definition: brin_internal.h:50
#define HIGHBIT
Definition: c.h:1151
#define BRIN_PLACEHOLDER_MASK
Definition: brin_tuple.h:78
uint8 bits8
Definition: c.h:436
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
static struct @143 value
BlockNumber bt_blkno
Definition: brin_tuple.h:57
#define Assert(condition)
Definition: c.h:800
size_t Size
Definition: c.h:528
#define MAXALIGN(LEN)
Definition: c.h:753
Size heap_compute_data_size(TupleDesc tupleDesc, Datum *values, bool *isnull)
Definition: heaptuple.c:119
#define VARATT_IS_EXTENDED(PTR)
Definition: postgres.h:327
#define DatumGetPointer(X)
Definition: postgres.h:549
static Datum values[MAXATTR]
Definition: bootstrap.c:165
uint8 bt_info
Definition: brin_tuple.h:68
Datum toast_compress_datum(Datum value)
void * palloc(Size size)
Definition: mcxt.c:950
int i
Definition: c.h:617
Datum * bv_values
Definition: brin_tuple.h:29

◆ brin_free_tuple()

void brin_free_tuple ( BrinTuple tuple)

Definition at line 406 of file brin_tuple.c.

References pfree().

Referenced by summarize_range().

407 {
408  pfree(tuple);
409 }
void pfree(void *pointer)
Definition: mcxt.c:1057

◆ brin_memtuple_initialize()

BrinMemTuple* brin_memtuple_initialize ( BrinMemTuple dtuple,
BrinDesc brdesc 
)

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

483 {
484  int i;
485  char *currdatum;
486 
488 
489  currdatum = (char *) dtuple +
490  MAXALIGN(sizeof(BrinMemTuple) +
491  sizeof(BrinValues) * brdesc->bd_tupdesc->natts);
492  for (i = 0; i < brdesc->bd_tupdesc->natts; i++)
493  {
494  dtuple->bt_columns[i].bv_attno = i + 1;
495  dtuple->bt_columns[i].bv_allnulls = true;
496  dtuple->bt_columns[i].bv_hasnulls = false;
497  dtuple->bt_columns[i].bv_values = (Datum *) currdatum;
498  currdatum += sizeof(Datum) * brdesc->bd_info[i]->oi_nstored;
499  }
500 
501  return dtuple;
502 }
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:753
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 455 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().

456 {
457  BrinMemTuple *dtup;
458  long basesize;
459 
460  basesize = MAXALIGN(sizeof(BrinMemTuple) +
461  sizeof(BrinValues) * brdesc->bd_tupdesc->natts);
462  dtup = palloc0(basesize + sizeof(Datum) * brdesc->bd_totalstored);
463 
464  dtup->bt_values = palloc(sizeof(Datum) * brdesc->bd_totalstored);
465  dtup->bt_allnulls = palloc(sizeof(bool) * brdesc->bd_tupdesc->natts);
466  dtup->bt_hasnulls = palloc(sizeof(bool) * brdesc->bd_tupdesc->natts);
467 
469  "brin dtuple",
471 
472  brin_memtuple_initialize(dtup, brdesc);
473 
474  return dtup;
475 }
#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:753
void * palloc(Size size)
Definition: mcxt.c:950
BrinMemTuple * brin_memtuple_initialize(BrinMemTuple *dtuple, BrinDesc *brdesc)
Definition: brin_tuple.c:482
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 438 of file brin_tuple.c.

Referenced by brin_doupdate().

439 {
440  if (alen != blen)
441  return false;
442  if (memcmp(a, b, alen) != 0)
443  return false;
444  return true;
445 }

◆ brtuple_disk_tupdesc()

static TupleDesc brtuple_disk_tupdesc ( BrinDesc brdesc)
static

Definition at line 61 of file brin_tuple.c.

References BrinDesc::bd_context, BrinDesc::bd_disktdesc, BrinDesc::bd_info, BrinDesc::bd_totalstored, BrinDesc::bd_tupdesc, CreateTemplateTupleDesc(), i, MemoryContextSwitchTo(), TupleDescData::natts, BrinOpcInfo::oi_nstored, BrinOpcInfo::oi_typcache, TupleDescInitEntry(), and TypeCacheEntry::type_id.

Referenced by brin_deconstruct_tuple(), and brin_form_tuple().

62 {
63  /* We cache these in the BrinDesc */
64  if (brdesc->bd_disktdesc == NULL)
65  {
66  int i;
67  int j;
68  AttrNumber attno = 1;
69  TupleDesc tupdesc;
70  MemoryContext oldcxt;
71 
72  /* make sure it's in the bdesc's context */
73  oldcxt = MemoryContextSwitchTo(brdesc->bd_context);
74 
75  tupdesc = CreateTemplateTupleDesc(brdesc->bd_totalstored);
76 
77  for (i = 0; i < brdesc->bd_tupdesc->natts; i++)
78  {
79  for (j = 0; j < brdesc->bd_info[i]->oi_nstored; j++)
80  TupleDescInitEntry(tupdesc, attno++, NULL,
81  brdesc->bd_info[i]->oi_typcache[j]->type_id,
82  -1, 0);
83  }
84 
85  MemoryContextSwitchTo(oldcxt);
86 
87  brdesc->bd_disktdesc = tupdesc;
88  }
89 
90  return brdesc->bd_disktdesc;
91 }
TupleDesc CreateTemplateTupleDesc(int natts)
Definition: tupdesc.c:44
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
TypeCacheEntry * oi_typcache[FLEXIBLE_ARRAY_MEMBER]
Definition: brin_internal.h:34
uint16 oi_nstored
Definition: brin_internal.h:28
int bd_totalstored
Definition: brin_internal.h:56
TupleDesc bd_tupdesc
Definition: brin_internal.h:50
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Definition: tupdesc.c:603
BrinOpcInfo * bd_info[FLEXIBLE_ARRAY_MEMBER]
Definition: brin_internal.h:59
MemoryContext bd_context
Definition: brin_internal.h:44
TupleDesc bd_disktdesc
Definition: brin_internal.h:53
int i
int16 AttrNumber
Definition: attnum.h:21