1 /*-------------------------------------------------------------------------
4 * Access to compressed and external varlena values.
6 * Copyright (c) 2000-2021, PostgreSQL Global Development Group
8 * src/include/access/detoast.h
10 *-------------------------------------------------------------------------
16 * Macro to fetch the possibly-unaligned contents of an EXTERNAL datum
17 * into a local "struct varatt_external" toast pointer. This should be
18 * just a memcpy, but some versions of gcc seem to produce broken code
19 * that assumes the datum contents are aligned. Introducing an explicit
20 * intermediate "varattrib_1b_e *" variable seems to fix it.
22 #define VARATT_EXTERNAL_GET_POINTER(toast_pointer, attr) \
24 varattrib_1b_e *attre = (varattrib_1b_e *) (attr); \
25 Assert(VARATT_IS_EXTERNAL(attre)); \
26 Assert(VARSIZE_EXTERNAL(attre) == sizeof(toast_pointer) + VARHDRSZ_EXTERNAL); \
27 memcpy(&(toast_pointer), VARDATA_EXTERNAL(attre), sizeof(toast_pointer)); \
30 /* Size of an EXTERNAL datum that contains a standard TOAST pointer */
31 #define TOAST_POINTER_SIZE (VARHDRSZ_EXTERNAL + sizeof(varatt_external))
33 /* Size of an EXTERNAL datum that contains an indirection pointer */
34 #define INDIRECT_POINTER_SIZE (VARHDRSZ_EXTERNAL + sizeof(varatt_indirect))
37 * detoast_external_attr() -
39 * Fetches an external stored attribute from the toast
40 * relation. Does NOT decompress it, if stored external
41 * in compressed format.
44 extern struct varlena
*detoast_external_attr(struct varlena
*attr
);
49 * Fully detoasts one attribute, fetching and/or decompressing
53 extern struct varlena
*detoast_attr(struct varlena
*attr
);
56 * detoast_attr_slice() -
58 * Fetches only the specified portion of an attribute.
59 * (Handles all cases for attribute storage)
62 extern struct varlena
*detoast_attr_slice(struct varlena
*attr
,
67 * toast_raw_datum_size -
69 * Return the raw (detoasted) size of a varlena datum
72 extern Size
toast_raw_datum_size(Datum value
);
77 * Return the storage size of a varlena datum
80 extern Size
toast_datum_size(Datum value
);
82 #endif /* DETOAST_H */