33 #include "utils/fmgroids.h"
54 rel->
rd_rel->relkind == RELKIND_MATVIEW);
126 rel->
rd_rel->relkind == RELKIND_MATVIEW);
132 numAttrs = tupleDesc->
natts;
185 toast_values, toast_isnull) > maxDataLen)
190 if (biggest_attno < 0)
215 if (toast_attr[biggest_attno].tai_size > maxDataLen &&
226 toast_values, toast_isnull) > maxDataLen &&
232 if (biggest_attno < 0)
242 toast_values, toast_isnull) > maxDataLen)
247 if (biggest_attno < 0)
261 toast_values, toast_isnull) > maxDataLen &&
267 if (biggest_attno < 0)
281 int32 new_header_len;
298 new_header_len =
MAXALIGN(new_header_len);
300 toast_values, toast_isnull);
301 new_tuple_len = new_header_len + new_data_len;
307 result_tuple->
t_len = new_tuple_len;
311 result_tuple->
t_data = new_data;
318 new_data->
t_hoff = new_header_len;
324 (
char *) new_data + new_header_len,
331 result_tuple = newtup;
353 int numAttrs = tupleDesc->
natts;
365 memset(toast_free, 0, numAttrs *
sizeof(
bool));
367 for (
i = 0;
i < numAttrs;
i++)
381 toast_free[
i] =
true;
411 for (
i = 0;
i < numAttrs;
i++)
454 int32 new_header_len;
458 int numAttrs = tupleDesc->
natts;
460 bool has_nulls =
false;
466 tmptup.
t_len = tup_len;
477 memset(toast_free, 0, numAttrs *
sizeof(
bool));
479 for (
i = 0;
i < numAttrs;
i++)
496 toast_free[
i] =
true;
510 new_header_len =
MAXALIGN(new_header_len);
512 toast_values, toast_isnull);
513 new_tuple_len = new_header_len + new_data_len;
522 new_data->
t_hoff = new_header_len;
533 (
char *) new_data + new_header_len,
536 has_nulls ? new_data->
t_bits : NULL);
541 for (
i = 0;
i < numAttrs;
i++)
568 int numAttrs = tupleDesc->
natts;
579 memcpy(new_values,
values, numAttrs *
sizeof(
Datum));
582 for (
i = 0;
i < numAttrs;
i++)
596 freeable_values[num_to_free++] = (
Pointer) new_value;
609 for (
i = 0;
i < num_to_free;
i++)
610 pfree(freeable_values[
i]);
652 Assert(endchunk <= totalchunks);
664 if (startchunk == 0 && endchunk == totalchunks - 1)
666 else if (startchunk == endchunk)
690 &SnapshotToast, nscankeys, toastkey);
697 expectedchunk = startchunk;
730 elog(
ERROR,
"found toasted toast chunk for toast value %u in %s",
739 if (curchunk != expectedchunk)
742 errmsg_internal(
"unexpected chunk number %d (expected %d) for toast value %u in %s",
743 curchunk, expectedchunk, valueid,
745 if (curchunk > endchunk)
748 errmsg_internal(
"unexpected chunk number %d (out of range %d..%d) for toast value %u in %s",
750 startchunk, endchunk, valueid,
754 if (chunksize != expected_size)
757 errmsg_internal(
"unexpected chunk size %d (expected %d) in chunk %d of %d for toast value %u in %s",
758 chunksize, expected_size,
759 curchunk, totalchunks, valueid,
766 chcpyend = chunksize - 1;
767 if (curchunk == startchunk)
769 if (curchunk == endchunk)
774 chunkdata + chcpystrt,
775 (chcpyend - chcpystrt) + 1);
783 if (expectedchunk != (endchunk + 1))
787 expectedchunk, valueid,
static Datum values[MAXATTR]
#define Assert(condition)
struct varlena * detoast_external_attr(struct varlena *attr)
struct varlena * detoast_attr(struct varlena *attr)
int errmsg_internal(const char *fmt,...)
int errcode(int sqlerrcode)
#define ereport(elevel,...)
SysScanDesc systable_beginscan_ordered(Relation heapRelation, Relation indexRelation, Snapshot snapshot, int nkeys, ScanKey key)
void systable_endscan_ordered(SysScanDesc sysscan)
HeapTuple systable_getnext_ordered(SysScanDesc sysscan, ScanDirection direction)
#define HEAP_INSERT_SPECULATIVE
void heap_fetch_toast_slice(Relation toastrel, Oid valueid, int32 attrsize, int32 sliceoffset, int32 slicelength, struct varlena *result)
void heap_toast_delete(Relation rel, HeapTuple oldtup, bool is_speculative)
HeapTuple heap_toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup, int options)
HeapTuple toast_build_flattened_tuple(TupleDesc tupleDesc, Datum *values, bool *isnull)
HeapTuple toast_flatten_tuple(HeapTuple tup, TupleDesc tupleDesc)
Datum toast_flatten_tuple_to_datum(HeapTupleHeader tup, uint32 tup_len, TupleDesc tupleDesc)
#define TOAST_TUPLE_TARGET
#define TOAST_TUPLE_TARGET_MAIN
#define TOAST_MAX_CHUNK_SIZE
Size heap_compute_data_size(TupleDesc tupleDesc, const Datum *values, const bool *isnull)
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
void heap_fill_tuple(TupleDesc tupleDesc, const Datum *values, const bool *isnull, char *data, Size data_size, uint16 *infomask, bits8 *bit)
void heap_deform_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *values, bool *isnull)
HeapTupleData * HeapTuple
HeapTupleHeaderData * HeapTupleHeader
#define HeapTupleHeaderSetTypMod(tup, typmod)
#define SizeofHeapTupleHeader
#define MaxTupleAttributeNumber
#define HeapTupleHeaderSetNatts(tup, natts)
#define MaxHeapAttributeNumber
#define HeapTupleHeaderSetDatumLength(tup, len)
static Datum fastgetattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
#define HeapTupleHeaderSetTypeId(tup, typeid)
static void ItemPointerSetInvalid(ItemPointerData *pointer)
void pfree(void *pointer)
void * palloc0(Size size)
#define ERRCODE_DATA_CORRUPTED
static Datum PointerGetDatum(const void *X)
static Datum ObjectIdGetDatum(Oid X)
static Pointer DatumGetPointer(Datum X)
static Datum Int32GetDatum(int32 X)
static int32 DatumGetInt32(Datum X)
#define RelationGetRelationName(relation)
#define RelationGetToastTupleTarget(relation, defaulttarg)
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
#define BTEqualStrategyNumber
#define BTLessEqualStrategyNumber
#define BTGreaterEqualStrategyNumber
void toast_tuple_init(ToastTupleContext *ttc)
void toast_delete_external(Relation rel, const Datum *values, const bool *isnull, bool is_speculative)
void toast_tuple_try_compression(ToastTupleContext *ttc, int attribute)
void toast_tuple_externalize(ToastTupleContext *ttc, int attribute, int options)
void toast_tuple_cleanup(ToastTupleContext *ttc)
int toast_tuple_find_biggest_attribute(ToastTupleContext *ttc, bool for_compression, bool check_main)
#define TOAST_NEEDS_CHANGE
#define TOASTCOL_INCOMPRESSIBLE
void toast_close_indexes(Relation *toastidxs, int num_indexes, LOCKMODE lock)
void init_toast_snapshot(Snapshot toast_snapshot)
int toast_open_indexes(Relation toastrel, LOCKMODE lock, Relation **toastidxs, int *num_indexes)
#define TupleDescAttr(tupdesc, i)
#define VARSIZE_SHORT(PTR)
#define VARATT_IS_EXTENDED(PTR)
#define VARATT_IS_SHORT(PTR)
#define VARATT_IS_COMPRESSED(PTR)
#define VARATT_IS_EXTERNAL(PTR)
#define VARDATA_SHORT(PTR)