PostgreSQL Source Code  git master
toast_internals.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * toast_internals.c
4  * Functions for internal use by the TOAST system.
5  *
6  * Copyright (c) 2000-2021, PostgreSQL Global Development Group
7  *
8  * IDENTIFICATION
9  * src/backend/access/common/toast_internals.c
10  *
11  *-------------------------------------------------------------------------
12  */
13 
14 #include "postgres.h"
15 
16 #include "access/detoast.h"
17 #include "access/genam.h"
18 #include "access/heapam.h"
19 #include "access/heaptoast.h"
20 #include "access/table.h"
21 #include "access/toast_internals.h"
22 #include "access/xact.h"
23 #include "catalog/catalog.h"
24 #include "common/pg_lzcompress.h"
25 #include "miscadmin.h"
26 #include "utils/fmgroids.h"
27 #include "utils/rel.h"
28 #include "utils/snapmgr.h"
29 
30 static bool toastrel_valueid_exists(Relation toastrel, Oid valueid);
31 static bool toastid_valueid_exists(Oid toastrelid, Oid valueid);
32 
33 /* ----------
34  * toast_compress_datum -
35  *
36  * Create a compressed version of a varlena datum
37  *
38  * If we fail (ie, compressed result is actually bigger than original)
39  * then return NULL. We must not use compressed data if it'd expand
40  * the tuple!
41  *
42  * We use VAR{SIZE,DATA}_ANY so we can handle short varlenas here without
43  * copying them. But we can't handle external or compressed datums.
44  * ----------
45  */
46 Datum
48 {
49  struct varlena *tmp = NULL;
50  int32 valsize;
52 
55 
57 
58  valsize = VARSIZE_ANY_EXHDR(DatumGetPointer(value));
59 
60  /*
61  * Call appropriate compression routine for the compression method.
62  */
63  switch (cmethod)
64  {
66  tmp = pglz_compress_datum((const struct varlena *) value);
68  break;
70  tmp = lz4_compress_datum((const struct varlena *) value);
72  break;
73  default:
74  elog(ERROR, "invalid compression method %c", cmethod);
75  }
76 
77  if (tmp == NULL)
78  return PointerGetDatum(NULL);
79 
80  /*
81  * We recheck the actual size even if compression reports success, because
82  * it might be satisfied with having saved as little as one byte in the
83  * compressed data --- which could turn into a net loss once you consider
84  * header and alignment padding. Worst case, the compressed format might
85  * require three padding bytes (plus header, which is included in
86  * VARSIZE(tmp)), whereas the uncompressed format would take only one
87  * header byte and no padding if the value is short enough. So we insist
88  * on a savings of more than 2 bytes to ensure we have a gain.
89  */
90  if (VARSIZE(tmp) < valsize - 2)
91  {
92  /* successful compression */
95  return PointerGetDatum(tmp);
96  }
97  else
98  {
99  /* incompressible data */
100  pfree(tmp);
101  return PointerGetDatum(NULL);
102  }
103 }
104 
105 /* ----------
106  * toast_save_datum -
107  *
108  * Save one single datum into the secondary relation and return
109  * a Datum reference for it.
110  *
111  * rel: the main relation we're working with (not the toast rel!)
112  * value: datum to be pushed to toast storage
113  * oldexternal: if not NULL, toast pointer previously representing the datum
114  * options: options to be passed to heap_insert() for toast rows
115  * ----------
116  */
117 Datum
119  struct varlena *oldexternal, int options)
120 {
121  Relation toastrel;
122  Relation *toastidxs;
123  HeapTuple toasttup;
124  TupleDesc toasttupDesc;
125  Datum t_values[3];
126  bool t_isnull[3];
127  CommandId mycid = GetCurrentCommandId(true);
128  struct varlena *result;
129  struct varatt_external toast_pointer;
130  union
131  {
132  struct varlena hdr;
133  /* this is to make the union big enough for a chunk: */
134  char data[TOAST_MAX_CHUNK_SIZE + VARHDRSZ];
135  /* ensure union is aligned well enough: */
136  int32 align_it;
137  } chunk_data;
138  int32 chunk_size;
139  int32 chunk_seq = 0;
140  char *data_p;
141  int32 data_todo;
142  Pointer dval = DatumGetPointer(value);
143  int num_indexes;
144  int validIndex;
145 
146  Assert(!VARATT_IS_EXTERNAL(value));
147 
148  /*
149  * Open the toast relation and its indexes. We can use the index to check
150  * uniqueness of the OID we assign to the toasted item, even though it has
151  * additional columns besides OID.
152  */
153  toastrel = table_open(rel->rd_rel->reltoastrelid, RowExclusiveLock);
154  toasttupDesc = toastrel->rd_att;
155 
156  /* Open all the toast indexes and look for the valid one */
157  validIndex = toast_open_indexes(toastrel,
159  &toastidxs,
160  &num_indexes);
161 
162  /*
163  * Get the data pointer and length, and compute va_rawsize and va_extinfo.
164  *
165  * va_rawsize is the size of the equivalent fully uncompressed datum, so
166  * we have to adjust for short headers.
167  *
168  * va_extinfo stored the actual size of the data payload in the toast
169  * records and the compression method in first 2 bits if data is
170  * compressed.
171  */
172  if (VARATT_IS_SHORT(dval))
173  {
174  data_p = VARDATA_SHORT(dval);
175  data_todo = VARSIZE_SHORT(dval) - VARHDRSZ_SHORT;
176  toast_pointer.va_rawsize = data_todo + VARHDRSZ; /* as if not short */
177  toast_pointer.va_extinfo = data_todo;
178  }
179  else if (VARATT_IS_COMPRESSED(dval))
180  {
181  data_p = VARDATA(dval);
182  data_todo = VARSIZE(dval) - VARHDRSZ;
183  /* rawsize in a compressed datum is just the size of the payload */
184  toast_pointer.va_rawsize = VARDATA_COMPRESSED_GET_EXTSIZE(dval) + VARHDRSZ;
185 
186  /* set external size and compression method */
187  VARATT_EXTERNAL_SET_SIZE_AND_COMPRESS_METHOD(toast_pointer, data_todo,
189  /* Assert that the numbers look like it's compressed */
190  Assert(VARATT_EXTERNAL_IS_COMPRESSED(toast_pointer));
191  }
192  else
193  {
194  data_p = VARDATA(dval);
195  data_todo = VARSIZE(dval) - VARHDRSZ;
196  toast_pointer.va_rawsize = VARSIZE(dval);
197  toast_pointer.va_extinfo = data_todo;
198  }
199 
200  /*
201  * Insert the correct table OID into the result TOAST pointer.
202  *
203  * Normally this is the actual OID of the target toast table, but during
204  * table-rewriting operations such as CLUSTER, we have to insert the OID
205  * of the table's real permanent toast table instead. rd_toastoid is set
206  * if we have to substitute such an OID.
207  */
208  if (OidIsValid(rel->rd_toastoid))
209  toast_pointer.va_toastrelid = rel->rd_toastoid;
210  else
211  toast_pointer.va_toastrelid = RelationGetRelid(toastrel);
212 
213  /*
214  * Choose an OID to use as the value ID for this toast value.
215  *
216  * Normally we just choose an unused OID within the toast table. But
217  * during table-rewriting operations where we are preserving an existing
218  * toast table OID, we want to preserve toast value OIDs too. So, if
219  * rd_toastoid is set and we had a prior external value from that same
220  * toast table, re-use its value ID. If we didn't have a prior external
221  * value (which is a corner case, but possible if the table's attstorage
222  * options have been changed), we have to pick a value ID that doesn't
223  * conflict with either new or existing toast value OIDs.
224  */
225  if (!OidIsValid(rel->rd_toastoid))
226  {
227  /* normal case: just choose an unused OID */
228  toast_pointer.va_valueid =
229  GetNewOidWithIndex(toastrel,
230  RelationGetRelid(toastidxs[validIndex]),
231  (AttrNumber) 1);
232  }
233  else
234  {
235  /* rewrite case: check to see if value was in old toast table */
236  toast_pointer.va_valueid = InvalidOid;
237  if (oldexternal != NULL)
238  {
239  struct varatt_external old_toast_pointer;
240 
241  Assert(VARATT_IS_EXTERNAL_ONDISK(oldexternal));
242  /* Must copy to access aligned fields */
243  VARATT_EXTERNAL_GET_POINTER(old_toast_pointer, oldexternal);
244  if (old_toast_pointer.va_toastrelid == rel->rd_toastoid)
245  {
246  /* This value came from the old toast table; reuse its OID */
247  toast_pointer.va_valueid = old_toast_pointer.va_valueid;
248 
249  /*
250  * There is a corner case here: the table rewrite might have
251  * to copy both live and recently-dead versions of a row, and
252  * those versions could easily reference the same toast value.
253  * When we copy the second or later version of such a row,
254  * reusing the OID will mean we select an OID that's already
255  * in the new toast table. Check for that, and if so, just
256  * fall through without writing the data again.
257  *
258  * While annoying and ugly-looking, this is a good thing
259  * because it ensures that we wind up with only one copy of
260  * the toast value when there is only one copy in the old
261  * toast table. Before we detected this case, we'd have made
262  * multiple copies, wasting space; and what's worse, the
263  * copies belonging to already-deleted heap tuples would not
264  * be reclaimed by VACUUM.
265  */
266  if (toastrel_valueid_exists(toastrel,
267  toast_pointer.va_valueid))
268  {
269  /* Match, so short-circuit the data storage loop below */
270  data_todo = 0;
271  }
272  }
273  }
274  if (toast_pointer.va_valueid == InvalidOid)
275  {
276  /*
277  * new value; must choose an OID that doesn't conflict in either
278  * old or new toast table
279  */
280  do
281  {
282  toast_pointer.va_valueid =
283  GetNewOidWithIndex(toastrel,
284  RelationGetRelid(toastidxs[validIndex]),
285  (AttrNumber) 1);
286  } while (toastid_valueid_exists(rel->rd_toastoid,
287  toast_pointer.va_valueid));
288  }
289  }
290 
291  /*
292  * Initialize constant parts of the tuple data
293  */
294  t_values[0] = ObjectIdGetDatum(toast_pointer.va_valueid);
295  t_values[2] = PointerGetDatum(&chunk_data);
296  t_isnull[0] = false;
297  t_isnull[1] = false;
298  t_isnull[2] = false;
299 
300  /*
301  * Split up the item into chunks
302  */
303  while (data_todo > 0)
304  {
305  int i;
306 
308 
309  /*
310  * Calculate the size of this chunk
311  */
312  chunk_size = Min(TOAST_MAX_CHUNK_SIZE, data_todo);
313 
314  /*
315  * Build a tuple and store it
316  */
317  t_values[1] = Int32GetDatum(chunk_seq++);
318  SET_VARSIZE(&chunk_data, chunk_size + VARHDRSZ);
319  memcpy(VARDATA(&chunk_data), data_p, chunk_size);
320  toasttup = heap_form_tuple(toasttupDesc, t_values, t_isnull);
321 
322  heap_insert(toastrel, toasttup, mycid, options, NULL);
323 
324  /*
325  * Create the index entry. We cheat a little here by not using
326  * FormIndexDatum: this relies on the knowledge that the index columns
327  * are the same as the initial columns of the table for all the
328  * indexes. We also cheat by not providing an IndexInfo: this is okay
329  * for now because btree doesn't need one, but we might have to be
330  * more honest someday.
331  *
332  * Note also that there had better not be any user-created index on
333  * the TOAST table, since we don't bother to update anything else.
334  */
335  for (i = 0; i < num_indexes; i++)
336  {
337  /* Only index relations marked as ready can be updated */
338  if (toastidxs[i]->rd_index->indisready)
339  index_insert(toastidxs[i], t_values, t_isnull,
340  &(toasttup->t_self),
341  toastrel,
342  toastidxs[i]->rd_index->indisunique ?
344  false, NULL);
345  }
346 
347  /*
348  * Free memory
349  */
350  heap_freetuple(toasttup);
351 
352  /*
353  * Move on to next chunk
354  */
355  data_todo -= chunk_size;
356  data_p += chunk_size;
357  }
358 
359  /*
360  * Done - close toast relation and its indexes
361  */
362  toast_close_indexes(toastidxs, num_indexes, RowExclusiveLock);
363  table_close(toastrel, RowExclusiveLock);
364 
365  /*
366  * Create the TOAST pointer value that we'll return
367  */
368  result = (struct varlena *) palloc(TOAST_POINTER_SIZE);
370  memcpy(VARDATA_EXTERNAL(result), &toast_pointer, sizeof(toast_pointer));
371 
372  return PointerGetDatum(result);
373 }
374 
375 /* ----------
376  * toast_delete_datum -
377  *
378  * Delete a single external stored value.
379  * ----------
380  */
381 void
382 toast_delete_datum(Relation rel, Datum value, bool is_speculative)
383 {
384  struct varlena *attr = (struct varlena *) DatumGetPointer(value);
385  struct varatt_external toast_pointer;
386  Relation toastrel;
387  Relation *toastidxs;
388  ScanKeyData toastkey;
389  SysScanDesc toastscan;
390  HeapTuple toasttup;
391  int num_indexes;
392  int validIndex;
393  SnapshotData SnapshotToast;
394 
395  if (!VARATT_IS_EXTERNAL_ONDISK(attr))
396  return;
397 
398  /* Must copy to access aligned fields */
399  VARATT_EXTERNAL_GET_POINTER(toast_pointer, attr);
400 
401  /*
402  * Open the toast relation and its indexes
403  */
404  toastrel = table_open(toast_pointer.va_toastrelid, RowExclusiveLock);
405 
406  /* Fetch valid relation used for process */
407  validIndex = toast_open_indexes(toastrel,
409  &toastidxs,
410  &num_indexes);
411 
412  /*
413  * Setup a scan key to find chunks with matching va_valueid
414  */
415  ScanKeyInit(&toastkey,
416  (AttrNumber) 1,
417  BTEqualStrategyNumber, F_OIDEQ,
418  ObjectIdGetDatum(toast_pointer.va_valueid));
419 
420  /*
421  * Find all the chunks. (We don't actually care whether we see them in
422  * sequence or not, but since we've already locked the index we might as
423  * well use systable_beginscan_ordered.)
424  */
425  init_toast_snapshot(&SnapshotToast);
426  toastscan = systable_beginscan_ordered(toastrel, toastidxs[validIndex],
427  &SnapshotToast, 1, &toastkey);
428  while ((toasttup = systable_getnext_ordered(toastscan, ForwardScanDirection)) != NULL)
429  {
430  /*
431  * Have a chunk, delete it
432  */
433  if (is_speculative)
434  heap_abort_speculative(toastrel, &toasttup->t_self);
435  else
436  simple_heap_delete(toastrel, &toasttup->t_self);
437  }
438 
439  /*
440  * End scan and close relations
441  */
442  systable_endscan_ordered(toastscan);
443  toast_close_indexes(toastidxs, num_indexes, RowExclusiveLock);
444  table_close(toastrel, RowExclusiveLock);
445 }
446 
447 /* ----------
448  * toastrel_valueid_exists -
449  *
450  * Test whether a toast value with the given ID exists in the toast relation.
451  * For safety, we consider a value to exist if there are either live or dead
452  * toast rows with that ID; see notes for GetNewOidWithIndex().
453  * ----------
454  */
455 static bool
457 {
458  bool result = false;
459  ScanKeyData toastkey;
460  SysScanDesc toastscan;
461  int num_indexes;
462  int validIndex;
463  Relation *toastidxs;
464 
465  /* Fetch a valid index relation */
466  validIndex = toast_open_indexes(toastrel,
468  &toastidxs,
469  &num_indexes);
470 
471  /*
472  * Setup a scan key to find chunks with matching va_valueid
473  */
474  ScanKeyInit(&toastkey,
475  (AttrNumber) 1,
476  BTEqualStrategyNumber, F_OIDEQ,
477  ObjectIdGetDatum(valueid));
478 
479  /*
480  * Is there any such chunk?
481  */
482  toastscan = systable_beginscan(toastrel,
483  RelationGetRelid(toastidxs[validIndex]),
484  true, SnapshotAny, 1, &toastkey);
485 
486  if (systable_getnext(toastscan) != NULL)
487  result = true;
488 
489  systable_endscan(toastscan);
490 
491  /* Clean up */
492  toast_close_indexes(toastidxs, num_indexes, RowExclusiveLock);
493 
494  return result;
495 }
496 
497 /* ----------
498  * toastid_valueid_exists -
499  *
500  * As above, but work from toast rel's OID not an open relation
501  * ----------
502  */
503 static bool
504 toastid_valueid_exists(Oid toastrelid, Oid valueid)
505 {
506  bool result;
507  Relation toastrel;
508 
509  toastrel = table_open(toastrelid, AccessShareLock);
510 
511  result = toastrel_valueid_exists(toastrel, valueid);
512 
513  table_close(toastrel, AccessShareLock);
514 
515  return result;
516 }
517 
518 /* ----------
519  * toast_get_valid_index
520  *
521  * Get OID of valid index associated to given toast relation. A toast
522  * relation can have only one valid index at the same time.
523  */
524 Oid
526 {
527  int num_indexes;
528  int validIndex;
529  Oid validIndexOid;
530  Relation *toastidxs;
531  Relation toastrel;
532 
533  /* Open the toast relation */
534  toastrel = table_open(toastoid, lock);
535 
536  /* Look for the valid index of the toast relation */
537  validIndex = toast_open_indexes(toastrel,
538  lock,
539  &toastidxs,
540  &num_indexes);
541  validIndexOid = RelationGetRelid(toastidxs[validIndex]);
542 
543  /* Close the toast relation and all its indexes */
544  toast_close_indexes(toastidxs, num_indexes, NoLock);
545  table_close(toastrel, NoLock);
546 
547  return validIndexOid;
548 }
549 
550 /* ----------
551  * toast_open_indexes
552  *
553  * Get an array of the indexes associated to the given toast relation
554  * and return as well the position of the valid index used by the toast
555  * relation in this array. It is the responsibility of the caller of this
556  * function to close the indexes as well as free them.
557  */
558 int
560  LOCKMODE lock,
561  Relation **toastidxs,
562  int *num_indexes)
563 {
564  int i = 0;
565  int res = 0;
566  bool found = false;
567  List *indexlist;
568  ListCell *lc;
569 
570  /* Get index list of the toast relation */
571  indexlist = RelationGetIndexList(toastrel);
572  Assert(indexlist != NIL);
573 
574  *num_indexes = list_length(indexlist);
575 
576  /* Open all the index relations */
577  *toastidxs = (Relation *) palloc(*num_indexes * sizeof(Relation));
578  foreach(lc, indexlist)
579  (*toastidxs)[i++] = index_open(lfirst_oid(lc), lock);
580 
581  /* Fetch the first valid index in list */
582  for (i = 0; i < *num_indexes; i++)
583  {
584  Relation toastidx = (*toastidxs)[i];
585 
586  if (toastidx->rd_index->indisvalid)
587  {
588  res = i;
589  found = true;
590  break;
591  }
592  }
593 
594  /*
595  * Free index list, not necessary anymore as relations are opened and a
596  * valid index has been found.
597  */
598  list_free(indexlist);
599 
600  /*
601  * The toast relation should have one valid index, so something is going
602  * wrong if there is nothing.
603  */
604  if (!found)
605  elog(ERROR, "no valid index found for toast relation with Oid %u",
606  RelationGetRelid(toastrel));
607 
608  return res;
609 }
610 
611 /* ----------
612  * toast_close_indexes
613  *
614  * Close an array of indexes for a toast relation and free it. This should
615  * be called for a set of indexes opened previously with toast_open_indexes.
616  */
617 void
618 toast_close_indexes(Relation *toastidxs, int num_indexes, LOCKMODE lock)
619 {
620  int i;
621 
622  /* Close relations and clean up things */
623  for (i = 0; i < num_indexes; i++)
624  index_close(toastidxs[i], lock);
625  pfree(toastidxs);
626 }
627 
628 /* ----------
629  * init_toast_snapshot
630  *
631  * Initialize an appropriate TOAST snapshot. We must use an MVCC snapshot
632  * to initialize the TOAST snapshot; since we don't know which one to use,
633  * just use the oldest one. This is safe: at worst, we will get a "snapshot
634  * too old" error that might have been avoided otherwise.
635  */
636 void
638 {
639  Snapshot snapshot = GetOldestSnapshot();
640 
641  if (snapshot == NULL)
642  elog(ERROR, "no known snapshots");
643 
644  InitToastSnapshot(*toast_snapshot, snapshot->lsn, snapshot->whenTaken);
645 }
void heap_insert(Relation relation, HeapTuple tup, CommandId cid, int options, BulkInsertState bistate)
Definition: heapam.c:2060
#define NIL
Definition: pg_list.h:65
uint32 CommandId
Definition: c.h:601
Oid GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn)
Definition: catalog.c:322
#define VARATT_IS_EXTERNAL_ONDISK(PTR)
Definition: postgres.h:327
#define VARATT_IS_COMPRESSED(PTR)
Definition: postgres.h:325
void heap_abort_speculative(Relation relation, ItemPointer tid)
Definition: heapam.c:5906
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:167
#define VARDATA(PTR)
Definition: postgres.h:315
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:595
Datum toast_compress_datum(Datum value, char cmethod)
#define TOAST_MAX_CHUNK_SIZE
Definition: heaptoast.h:84
#define VARATT_EXTERNAL_IS_COMPRESSED(toast_pointer)
Definition: postgres.h:391
static struct @142 value
int LOCKMODE
Definition: lockdefs.h:26
#define CompressionMethodIsValid(cm)
#define VARHDRSZ_SHORT
Definition: postgres.h:292
#define VARSIZE(PTR)
Definition: postgres.h:316
#define VARATT_EXTERNAL_GET_POINTER(toast_pointer, attr)
Definition: detoast.h:22
#define PointerGetDatum(X)
Definition: postgres.h:600
void init_toast_snapshot(Snapshot toast_snapshot)
#define VARHDRSZ
Definition: c.h:627
ToastCompressionId
#define Min(x, y)
Definition: c.h:986
XLogRecPtr lsn
Definition: snapshot.h:209
#define AccessShareLock
Definition: lockdefs.h:36
Oid va_toastrelid
Definition: postgres.h:75
int32 va_rawsize
Definition: postgres.h:71
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:1020
#define VARDATA_COMPRESSED_GET_EXTSIZE(PTR)
Definition: postgres.h:365
HeapTuple systable_getnext_ordered(SysScanDesc sysscan, ScanDirection direction)
Definition: genam.c:707
Form_pg_class rd_rel
Definition: rel.h:109
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1338
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:710
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:383
#define VARDATA_EXTERNAL(PTR)
Definition: postgres.h:323
signed int int32
Definition: c.h:429
#define VARATT_IS_EXTERNAL(PTR)
Definition: postgres.h:326
Form_pg_index rd_index
Definition: rel.h:187
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:502
void pfree(void *pointer)
Definition: mcxt.c:1169
char * Pointer
Definition: c.h:418
#define ObjectIdGetDatum(X)
Definition: postgres.h:551
#define ERROR
Definition: elog.h:46
#define VARATT_IS_SHORT(PTR)
Definition: postgres.h:339
static bool toastid_valueid_exists(Oid toastrelid, Oid valueid)
ItemPointerData t_self
Definition: htup.h:65
#define TOAST_LZ4_COMPRESSION
#define NoLock
Definition: lockdefs.h:34
struct varlena * pglz_compress_datum(const struct varlena *value)
#define SET_VARTAG_EXTERNAL(PTR, tag)
Definition: postgres.h:346
Oid rd_toastoid
Definition: rel.h:246
#define RowExclusiveLock
Definition: lockdefs.h:38
void toast_close_indexes(Relation *toastidxs, int num_indexes, LOCKMODE lock)
#define TOAST_POINTER_SIZE
Definition: detoast.h:31
void toast_delete_datum(Relation rel, Datum value, bool is_speculative)
#define VARSIZE_SHORT(PTR)
Definition: postgres.h:318
int toast_open_indexes(Relation toastrel, LOCKMODE lock, Relation **toastidxs, int *num_indexes)
uintptr_t Datum
Definition: postgres.h:411
Snapshot GetOldestSnapshot(void)
Definition: snapmgr.c:357
void systable_endscan_ordered(SysScanDesc sysscan)
Definition: genam.c:732
struct varlena * lz4_compress_datum(const struct varlena *value)
TupleDesc rd_att
Definition: rel.h:110
#define InvalidOid
Definition: postgres_ext.h:36
#define TOAST_COMPRESS_SET_SIZE_AND_COMPRESS_METHOD(ptr, len, cm_method)
#define Assert(condition)
Definition: c.h:804
uint32 va_extinfo
Definition: postgres.h:72
static int list_length(const List *l)
Definition: pg_list.h:149
void simple_heap_delete(Relation relation, ItemPointer tid)
Definition: heapam.c:3175
#define VARDATA_COMPRESSED_GET_COMPRESS_METHOD(PTR)
Definition: postgres.h:367
#define TOAST_PGLZ_COMPRESSION
List * RelationGetIndexList(Relation relation)
Definition: relcache.c:4570
#define SnapshotAny
Definition: snapmgr.h:67
void index_close(Relation relation, LOCKMODE lockmode)
Definition: indexam.c:158
#define DatumGetPointer(X)
Definition: postgres.h:593
#define VARDATA_SHORT(PTR)
Definition: postgres.h:319
#define Int32GetDatum(X)
Definition: postgres.h:523
#define VARSIZE_ANY_EXHDR(PTR)
Definition: postgres.h:354
void * palloc(Size size)
Definition: mcxt.c:1062
SysScanDesc systable_beginscan_ordered(Relation heapRelation, Relation indexRelation, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:642
void list_free(List *list)
Definition: list.c:1391
#define elog(elevel,...)
Definition: elog.h:232
int i
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
#define VARATT_EXTERNAL_SET_SIZE_AND_COMPRESS_METHOD(toast_pointer, len, cm)
Definition: postgres.h:376
Definition: c.h:621
TimestampTz whenTaken
Definition: snapshot.h:208
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:102
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:342
CommandId GetCurrentCommandId(bool used)
Definition: xact.c:761
bool index_insert(Relation indexRelation, Datum *values, bool *isnull, ItemPointer heap_t_ctid, Relation heapRelation, IndexUniqueCheck checkUnique, bool indexUnchanged, IndexInfo *indexInfo)
Definition: indexam.c:176
static bool toastrel_valueid_exists(Relation toastrel, Oid valueid)
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39
Definition: pg_list.h:50
int16 AttrNumber
Definition: attnum.h:21
#define RelationGetRelid(relation)
Definition: rel.h:469
Datum toast_save_datum(Relation rel, Datum value, struct varlena *oldexternal, int options)
Relation index_open(Oid relationId, LOCKMODE lockmode)
Definition: indexam.c:132
#define BTEqualStrategyNumber
Definition: stratnum.h:31
#define InitToastSnapshot(snapshotdata, l, w)
Definition: snapmgr.h:90
#define lfirst_oid(lc)
Definition: pg_list.h:171
Oid toast_get_valid_index(Oid toastoid, LOCKMODE lock)