23 #include "utils/fmgroids.h" 227 if (slicelength > 0 && sliceoffset >= 0)
257 sliceoffset, slicelength);
271 struct varlena *tmp = preslice;
274 if (slicelength > 0 && sliceoffset >= 0)
296 if (sliceoffset >= attrsize)
302 if (((sliceoffset + slicelength) > attrsize) || slicelength < 0)
303 slicelength = attrsize - sliceoffset;
308 memcpy(
VARDATA(result), attrdata + sliceoffset, slicelength);
310 if (preslice != attr)
347 elog(
ERROR,
"toast_fetch_datum shouldn't be called for non-ondisk datums");
366 toasttupDesc = toastrel->
rd_att;
393 &SnapshotToast, 1, &toastkey);
417 elog(
ERROR,
"found toasted toast chunk for toast value %u in %s",
427 if (residx != nextidx)
430 errmsg_internal(
"unexpected chunk number %d (expected %d) for toast value %u in %s",
434 if (residx < numchunks - 1)
439 errmsg_internal(
"unexpected chunk size %d (expected %d) in chunk %d of %d for toast value %u in %s",
445 else if (residx == numchunks - 1)
450 errmsg_internal(
"unexpected chunk size %d (expected %d) in final chunk %d for toast value %u in %s",
460 errmsg_internal(
"unexpected chunk number %d (out of range %d..%d) for toast value %u in %s",
479 if (nextidx != numchunks)
540 elog(
ERROR,
"toast_fetch_datum_slice shouldn't be called for non-ondisk datums");
555 if (sliceoffset >= attrsize)
567 length = length +
sizeof(
int32);
569 if (((sliceoffset + length) > attrsize) || length < 0)
570 length = attrsize - sliceoffset;
584 numchunks = (endchunk - startchunk) + 1;
593 toasttupDesc = toastrel->
rd_att;
640 nextidx = startchunk;
642 &SnapshotToast, nscankeys, toastkey);
666 elog(
ERROR,
"found toasted toast chunk for toast value %u in %s",
676 if ((residx != nextidx) || (residx > endchunk) || (residx < startchunk))
677 elog(
ERROR,
"unexpected chunk number %d (expected %d) for toast value %u in %s",
681 if (residx < totalchunks - 1)
684 elog(
ERROR,
"unexpected chunk size %d (expected %d) in chunk %d of %d for toast value %u in %s when fetching slice",
690 else if (residx == totalchunks - 1)
693 elog(
ERROR,
"unexpected chunk size %d (expected %d) in final chunk %d for toast value %u in %s when fetching slice",
701 elog(
ERROR,
"unexpected chunk number %d (out of range %d..%d) for toast value %u in %s",
711 chcpyend = chunksize - 1;
712 if (residx == startchunk)
713 chcpystrt = startoffset;
714 if (residx == endchunk)
715 chcpyend = endoffset;
719 chunkdata + chcpystrt,
720 (chcpyend - chcpystrt) + 1);
728 if (nextidx != (endchunk + 1))
729 elog(
ERROR,
"missing chunk number %d for toast value %u in %s",
764 elog(
ERROR,
"compressed data is corrupted");
792 elog(
ERROR,
"compressed data is corrupted");
#define VARATT_IS_EXTERNAL_ONDISK(PTR)
#define VARATT_IS_COMPRESSED(PTR)
int32 pglz_maximum_compressed_size(int32 rawsize, int32 total_compressed_size)
void table_close(Relation relation, LOCKMODE lockmode)
#define fastgetattr(tup, attnum, tupleDesc, isnull)
#define TOAST_MAX_CHUNK_SIZE
#define VARATT_IS_EXTERNAL_EXPANDED(PTR)
static struct varlena * toast_fetch_datum_slice(struct varlena *attr, int32 sliceoffset, int32 length)
#define VARATT_EXTERNAL_GET_POINTER(toast_pointer, attr)
#define PointerGetDatum(X)
void init_toast_snapshot(Snapshot toast_snapshot)
struct varlena * detoast_external_attr(struct varlena *attr)
int errcode(int sqlerrcode)
HeapTuple systable_getnext_ordered(SysScanDesc sysscan, ScanDirection direction)
struct varlena * detoast_attr_slice(struct varlena *attr, int32 sliceoffset, int32 slicelength)
int32 pglz_decompress(const char *source, int32 slen, char *dest, int32 rawsize, bool check_complete)
#define BTLessEqualStrategyNumber
Size toast_datum_size(Datum value)
#define VARATT_IS_EXTERNAL(PTR)
struct varlena * detoast_attr(struct varlena *attr)
void pfree(void *pointer)
#define VARATT_IS_EXTERNAL_INDIRECT(PTR)
#define ObjectIdGetDatum(X)
#define TOAST_COMPRESS_RAWDATA(ptr)
#define VARATT_IS_SHORT(PTR)
void toast_close_indexes(Relation *toastidxs, int num_indexes, LOCKMODE lock)
#define RelationGetRelationName(relation)
Size EOH_get_flat_size(ExpandedObjectHeader *eohptr)
Size toast_raw_datum_size(Datum value)
#define ereport(elevel, rest)
#define VARSIZE_SHORT(PTR)
#define ERRCODE_DATA_CORRUPTED
ExpandedObjectHeader * DatumGetEOHP(Datum d)
#define VARRAWSIZE_4B_C(PTR)
#define TOAST_COMPRESS_SIZE(ptr)
int toast_open_indexes(Relation toastrel, LOCKMODE lock, Relation **toastidxs, int *num_indexes)
void EOH_flatten_into(ExpandedObjectHeader *eohptr, void *result, Size allocated_size)
void systable_endscan_ordered(SysScanDesc sysscan)
static struct varlena * toast_fetch_datum(struct varlena *attr)
int errmsg_internal(const char *fmt,...)
#define Assert(condition)
#define TOAST_COMPRESS_HDRSZ
#define VARATT_IS_EXTENDED(PTR)
#define DatumGetPointer(X)
#define VARDATA_SHORT(PTR)
SysScanDesc systable_beginscan_ordered(Relation heapRelation, Relation indexRelation, Snapshot snapshot, int nkeys, ScanKey key)
#define SET_VARSIZE_COMPRESSED(PTR, len)
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
#define VARATT_EXTERNAL_IS_COMPRESSED(toast_pointer)
#define SET_VARSIZE(PTR, len)
static struct varlena * toast_decompress_datum(struct varlena *attr)
Relation table_open(Oid relationId, LOCKMODE lockmode)
static struct varlena * toast_decompress_datum_slice(struct varlena *attr, int32 slicelength)
#define TOAST_COMPRESS_RAWSIZE(ptr)
#define BTEqualStrategyNumber
#define BTGreaterEqualStrategyNumber