v4-0005-Move-static-inline-routines-of-varatt_external_oi.patch
text/x-diff
Filename: v4-0005-Move-static-inline-routines-of-varatt_external_oi.patch
Type: text/x-diff
Part: 4
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: format-patch
Series: patch v4-0005
Subject: Move static inline routines of varatt_external_oid to toast_external.c
| File | + | − |
|---|---|---|
| src/backend/access/common/toast_external.c | 36 | 3 |
| src/include/varatt.h | 0 | 30 |
From f91260e4b14d11a9189034aed1edcab81da766e8 Mon Sep 17 00:00:00 2001
From: Michael Paquier <michael@paquier.xyz>
Date: Fri, 8 Aug 2025 15:40:04 +0900
Subject: [PATCH v4 05/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 | 30 -----------------
src/backend/access/common/toast_external.c | 39 ++++++++++++++++++++--
2 files changed, 36 insertions(+), 33 deletions(-)
diff --git a/src/include/varatt.h b/src/include/varatt.h
index b791ce7847ed..631aa2ecc494 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(struct varatt_external_oid toast_pointer)
-{
- return toast_pointer.va_extinfo & VARLENA_EXTSIZE_MASK;
-}
-
-static inline uint32
-VARATT_EXTERNAL_GET_COMPRESS_METHOD(struct 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) \
@@ -539,18 +523,4 @@ VARATT_EXTERNAL_GET_COMPRESS_METHOD(struct varatt_external_oid toast_pointer)
(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(struct 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 96ea7be8966e..79ae02873748 100644
--- a/src/backend/access/common/toast_external.c
+++ b/src/backend/access/common/toast_external.c
@@ -22,6 +22,39 @@ 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(struct 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(struct 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(struct 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
@@ -117,10 +150,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