PostgreSQL Source Code  git master
detoast.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * detoast.h
4  * Access to compressed and external varlena values.
5  *
6  * Copyright (c) 2000-2019, PostgreSQL Global Development Group
7  *
8  * src/include/access/detoast.h
9  *
10  *-------------------------------------------------------------------------
11  */
12 #ifndef DETOAST_H
13 #define DETOAST_H
14 
15 /*
16  * Testing whether an externally-stored value is compressed now requires
17  * comparing extsize (the actual length of the external data) to rawsize
18  * (the original uncompressed datum's size). The latter includes VARHDRSZ
19  * overhead, the former doesn't. We never use compression unless it actually
20  * saves space, so we expect either equality or less-than.
21  */
22 #define VARATT_EXTERNAL_IS_COMPRESSED(toast_pointer) \
23  ((toast_pointer).va_extsize < (toast_pointer).va_rawsize - VARHDRSZ)
24 
25 /*
26  * Macro to fetch the possibly-unaligned contents of an EXTERNAL datum
27  * into a local "struct varatt_external" toast pointer. This should be
28  * just a memcpy, but some versions of gcc seem to produce broken code
29  * that assumes the datum contents are aligned. Introducing an explicit
30  * intermediate "varattrib_1b_e *" variable seems to fix it.
31  */
32 #define VARATT_EXTERNAL_GET_POINTER(toast_pointer, attr) \
33 do { \
34  varattrib_1b_e *attre = (varattrib_1b_e *) (attr); \
35  Assert(VARATT_IS_EXTERNAL(attre)); \
36  Assert(VARSIZE_EXTERNAL(attre) == sizeof(toast_pointer) + VARHDRSZ_EXTERNAL); \
37  memcpy(&(toast_pointer), VARDATA_EXTERNAL(attre), sizeof(toast_pointer)); \
38 } while (0)
39 
40 /* Size of an EXTERNAL datum that contains a standard TOAST pointer */
41 #define TOAST_POINTER_SIZE (VARHDRSZ_EXTERNAL + sizeof(varatt_external))
42 
43 /* Size of an EXTERNAL datum that contains an indirection pointer */
44 #define INDIRECT_POINTER_SIZE (VARHDRSZ_EXTERNAL + sizeof(varatt_indirect))
45 
46 /* ----------
47  * detoast_external_attr() -
48  *
49  * Fetches an external stored attribute from the toast
50  * relation. Does NOT decompress it, if stored external
51  * in compressed format.
52  * ----------
53  */
54 extern struct varlena *detoast_external_attr(struct varlena *attr);
55 
56 /* ----------
57  * detoast_attr() -
58  *
59  * Fully detoasts one attribute, fetching and/or decompressing
60  * it as needed.
61  * ----------
62  */
63 extern struct varlena *detoast_attr(struct varlena *attr);
64 
65 /* ----------
66  * detoast_attr_slice() -
67  *
68  * Fetches only the specified portion of an attribute.
69  * (Handles all cases for attribute storage)
70  * ----------
71  */
72 extern struct varlena *detoast_attr_slice(struct varlena *attr,
73  int32 sliceoffset,
74  int32 slicelength);
75 
76 /* ----------
77  * toast_raw_datum_size -
78  *
79  * Return the raw (detoasted) size of a varlena datum
80  * ----------
81  */
83 
84 /* ----------
85  * toast_datum_size -
86  *
87  * Return the storage size of a varlena datum
88  * ----------
89  */
91 
92 #endif /* DETOAST_H */
struct varlena * detoast_external_attr(struct varlena *attr)
Definition: detoast.c:45
struct varlena * detoast_attr_slice(struct varlena *attr, int32 sliceoffset, int32 slicelength)
Definition: detoast.c:204
static struct @145 value
signed int int32
Definition: c.h:347
Size toast_raw_datum_size(Datum value)
Definition: detoast.c:806
Size toast_datum_size(Datum value)
Definition: detoast.c:862
uintptr_t Datum
Definition: postgres.h:367
size_t Size
Definition: c.h:467
struct varlena * detoast_attr(struct varlena *attr)
Definition: detoast.c:116
Definition: c.h:556