From d3a04843fd969d3e15b2f950f14a57a8b74716ab Mon Sep 17 00:00:00 2001 From: Michael Paquier Date: Fri, 8 Aug 2025 15:40:04 +0900 Subject: [PATCH v5 06/15] Move static inline routines of varatt_external_oid to toast_external.c This isolates most of the knowledge of varatt_external_oid into the local area where it is manipulated through the toast_external transition type, with the backend code not requiring it. Extension code should not need it either, as toast_external should be the layer to use when looking at external on-dist TOAST varlenas. --- src/include/varatt.h | 31 ----------------- src/backend/access/common/toast_external.c | 40 ++++++++++++++++++++-- 2 files changed, 37 insertions(+), 34 deletions(-) diff --git a/src/include/varatt.h b/src/include/varatt.h index 790d9f844c91..035c0f95e5b6 100644 --- a/src/include/varatt.h +++ b/src/include/varatt.h @@ -513,22 +513,6 @@ VARDATA_COMPRESSED_GET_COMPRESS_METHOD(const void *PTR) return ((varattrib_4b *) PTR)->va_compressed.va_tcinfo >> VARLENA_EXTSIZE_BITS; } -/* - * Same for external Datums; but note argument is a struct - * varatt_external_oid. - */ -static inline Size -VARATT_EXTERNAL_GET_EXTSIZE(varatt_external_oid toast_pointer) -{ - return toast_pointer.va_extinfo & VARLENA_EXTSIZE_MASK; -} - -static inline uint32 -VARATT_EXTERNAL_GET_COMPRESS_METHOD(varatt_external_oid toast_pointer) -{ - return toast_pointer.va_extinfo >> VARLENA_EXTSIZE_BITS; -} - /* Set size and compress method of an externally-stored varlena datum */ /* This has to remain a macro; beware multiple evaluations! */ #define VARATT_EXTERNAL_SET_SIZE_AND_COMPRESS_METHOD(toast_pointer, len, cm) \ @@ -538,19 +522,4 @@ VARATT_EXTERNAL_GET_COMPRESS_METHOD(varatt_external_oid toast_pointer) ((toast_pointer).va_extinfo = \ (len) | ((uint32) (cm) << VARLENA_EXTSIZE_BITS)); \ } while (0) - -/* - * Testing whether an externally-stored value is compressed now requires - * comparing size stored in va_extinfo (the actual length of the external data) - * to rawsize (the original uncompressed datum's size). The latter includes - * VARHDRSZ overhead, the former doesn't. We never use compression unless it - * actually saves space, so we expect either equality or less-than. - */ -static inline bool -VARATT_EXTERNAL_IS_COMPRESSED(varatt_external_oid toast_pointer) -{ - return VARATT_EXTERNAL_GET_EXTSIZE(toast_pointer) < - (Size) (toast_pointer.va_rawsize - VARHDRSZ); -} - #endif diff --git a/src/backend/access/common/toast_external.c b/src/backend/access/common/toast_external.c index 5c8679a0f485..d7bf2f7c69b2 100644 --- a/src/backend/access/common/toast_external.c +++ b/src/backend/access/common/toast_external.c @@ -26,6 +26,40 @@ static void ondisk_oid_to_external_data(struct varlena *attr, toast_external_data *data); static struct varlena *ondisk_oid_create_external_data(toast_external_data data); +/* + * Decompressed size of an on-disk varlena; but note argument is a struct + * varatt_external_oid. + */ +static inline Size +varatt_external_oid_get_extsize(varatt_external_oid toast_pointer) +{ + return toast_pointer.va_extinfo & VARLENA_EXTSIZE_MASK; +} + +/* + * Compression method of an on-disk varlena; but note argument is a struct + * varatt_external_oid. + */ +static inline uint32 +varatt_external_oid_get_compress_method(varatt_external_oid toast_pointer) +{ + return toast_pointer.va_extinfo >> VARLENA_EXTSIZE_BITS; +} + +/* + * Testing whether an externally-stored TOAST value is compressed now requires + * comparing size stored in va_extinfo (the actual length of the external data) + * to rawsize (the original uncompressed datum's size). The latter includes + * VARHDRSZ overhead, the former doesn't. We never use compression unless it + * actually saves space, so we expect either equality or less-than. + */ +static inline bool +varatt_external_oid_is_compressed(varatt_external_oid toast_pointer) +{ + return varatt_external_oid_get_extsize(toast_pointer) < + (Size) (toast_pointer.va_rawsize - VARHDRSZ); +} + /* * Size of an EXTERNAL datum that contains a standard TOAST pointer (OID * value). @@ -141,10 +175,10 @@ ondisk_oid_to_external_data(struct varlena *attr, toast_external_data *data) * External size and compression methods are stored in the same field, * extract. */ - if (VARATT_EXTERNAL_IS_COMPRESSED(external)) + if (varatt_external_oid_is_compressed(external)) { - data->extsize = VARATT_EXTERNAL_GET_EXTSIZE(external); - data->compression_method = VARATT_EXTERNAL_GET_COMPRESS_METHOD(external); + data->extsize = varatt_external_oid_get_extsize(external); + data->compression_method = varatt_external_oid_get_compress_method(external); } else { -- 2.50.0