diff --git a/contrib/amcheck/verify_heapam.c b/contrib/amcheck/verify_heapam.c index c6e272ff0ec..27efe3e20f9 100644 --- a/contrib/amcheck/verify_heapam.c +++ b/contrib/amcheck/verify_heapam.c @@ -16,6 +16,7 @@ #include "access/multixact.h" #include "access/relation.h" #include "access/table.h" +#include "access/toast_compression.h" #include "access/toast_internals.h" #include "access/visibilitymap.h" #include "access/xact.h" diff --git a/src/backend/access/brin/brin_tuple.c b/src/backend/access/brin/brin_tuple.c index af39d448962..091cf71f585 100644 --- a/src/backend/access/brin/brin_tuple.c +++ b/src/backend/access/brin/brin_tuple.c @@ -35,6 +35,7 @@ #include "access/detoast.h" #include "access/heaptoast.h" #include "access/htup_details.h" +#include "access/toast_compression.h" #include "access/toast_internals.h" #include "access/tupdesc.h" #include "access/tupmacs.h" diff --git a/src/backend/access/common/detoast.c b/src/backend/access/common/detoast.c index 06992de1ede..a9d4e3ae98e 100644 --- a/src/backend/access/common/detoast.c +++ b/src/backend/access/common/detoast.c @@ -16,6 +16,7 @@ #include "access/detoast.h" #include "access/table.h" #include "access/tableam.h" +#include "access/toast_compression.h" #include "access/toast_internals.h" #include "common/int.h" #include "common/pg_lzcompress.h" @@ -489,7 +490,7 @@ toast_decompress_datum(varlena *attr) * Fetch the compression method id stored in the compression header and * decompress the data using the appropriate decompression routine. */ - cmid = TOAST_COMPRESS_METHOD(attr); + cmid = VARDATA_COMPRESSED_GET_COMPRESS_METHOD(attr); switch (cmid) { case TOAST_PGLZ_COMPRESSION_ID: @@ -525,14 +526,14 @@ toast_decompress_datum_slice(varlena *attr, int32 slicelength) * have been seen to give wrong results if passed an output size that is * more than the data's true decompressed size. */ - if ((uint32) slicelength >= TOAST_COMPRESS_EXTSIZE(attr)) + if ((uint32) slicelength >= VARDATA_COMPRESSED_GET_EXTSIZE(attr)) return toast_decompress_datum(attr); /* * Fetch the compression method id stored in the compression header and * decompress the data slice using the appropriate decompression routine. */ - cmid = TOAST_COMPRESS_METHOD(attr); + cmid = VARDATA_COMPRESSED_GET_COMPRESS_METHOD(attr); switch (cmid) { case TOAST_PGLZ_COMPRESSION_ID: diff --git a/src/backend/access/common/toast_internals.c b/src/backend/access/common/toast_internals.c index b0bfc1bfc9c..5485d4e3fa9 100644 --- a/src/backend/access/common/toast_internals.c +++ b/src/backend/access/common/toast_internals.c @@ -18,6 +18,7 @@ #include "access/heapam.h" #include "access/heaptoast.h" #include "access/table.h" +#include "access/toast_compression.h" #include "access/toast_internals.h" #include "access/xact.h" #include "catalog/catalog.h" @@ -92,7 +93,7 @@ toast_compress_datum(Datum value, char cmethod) { /* successful compression */ Assert(cmid != TOAST_INVALID_COMPRESSION_ID); - TOAST_COMPRESS_SET_SIZE_AND_COMPRESS_METHOD(tmp, valsize, cmid); + VARDATA_COMPRESSED_SET_TCINFO(tmp, valsize, cmid); return PointerGetDatum(tmp); } else diff --git a/src/include/access/toast_internals.h b/src/include/access/toast_internals.h index e03cc1204be..a31b47f8df5 100644 --- a/src/include/access/toast_internals.h +++ b/src/include/access/toast_internals.h @@ -13,39 +13,10 @@ #define TOAST_INTERNALS_H #include "access/skey.h" -#include "access/toast_compression.h" #include "storage/lockdefs.h" #include "utils/relcache.h" #include "utils/snapshot.h" -/* - * The information at the start of the compressed toast data. - */ -typedef struct toast_compress_header -{ - int32 vl_len_; /* varlena header (do not touch directly!) */ - uint32 tcinfo; /* 2 bits for compression method and 30 bits - * external size; see va_extinfo */ -} toast_compress_header; - -/* - * Utilities for manipulation of header information for compressed - * toast entries. - */ -#define TOAST_COMPRESS_EXTSIZE(ptr) \ - (((toast_compress_header *) (ptr))->tcinfo & VARLENA_EXTSIZE_MASK) -#define TOAST_COMPRESS_METHOD(ptr) \ - (((toast_compress_header *) (ptr))->tcinfo >> VARLENA_EXTSIZE_BITS) - -#define TOAST_COMPRESS_SET_SIZE_AND_COMPRESS_METHOD(ptr, len, cm_method) \ - do { \ - Assert((len) > 0 && (len) <= VARLENA_EXTSIZE_MASK); \ - Assert((cm_method) == TOAST_PGLZ_COMPRESSION_ID || \ - (cm_method) == TOAST_LZ4_COMPRESSION_ID); \ - ((toast_compress_header *) (ptr))->tcinfo = \ - (len) | ((uint32) (cm_method) << VARLENA_EXTSIZE_BITS); \ - } while (0) - extern Datum toast_compress_datum(Datum value, char cmethod); extern Oid toast_get_valid_index(Oid toastoid, LOCKMODE lock); diff --git a/src/include/varatt.h b/src/include/varatt.h index 85d62834295..7951a946a87 100644 --- a/src/include/varatt.h +++ b/src/include/varatt.h @@ -553,6 +553,21 @@ VARDATA_COMPRESSED_GET_COMPRESS_METHOD(const void *PTR) return ((const varattrib_4b *) PTR)->va_compressed.va_tcinfo >> VARLENA_EXTSIZE_BITS; } +/* + * Set the decompressed size and the compression method of a + * compressed-in-line varlena datum. The length word is not touched here; the + * caller is expected to have set it with SET_VARSIZE_COMPRESSED(). + */ +static inline void +VARDATA_COMPRESSED_SET_TCINFO(void *PTR, uint32 extsize, uint32 cmethod) +{ + Assert(extsize > 0 && extsize <= VARLENA_EXTSIZE_MASK); + Assert(cmethod < (1U << (32 - VARLENA_EXTSIZE_BITS))); + + ((varattrib_4b *) PTR)->va_compressed.va_tcinfo = + extsize | (cmethod << VARLENA_EXTSIZE_BITS); +} + /* * Same for external Datums, saved into a va_extinfo. */ diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list index 5d432074c2c..656f1f60862 100644 --- a/src/tools/pgindent/typedefs.list +++ b/src/tools/pgindent/typedefs.list @@ -4357,7 +4357,6 @@ timeout_handler_proc timeout_params timerCA tlist_vinfo -toast_compress_header toast_external_data tokenize_error_callback_arg transferMode