1
0
mirror of https://github.com/postgres/postgres.git synced 2026-10-23 13:29:09 +03:00

Remove duplicate definition of the compressed varlena header

toast_internals.h described the header of a compressed-in-line varlena
a second time, as toast_compress_header, with its own TOAST_COMPRESS_*
macros to read and write the tcinfo word.  varatt.h already describes
the same bytes as varattrib_4b.va_compressed and provides equivalent
macros that act as setter and getter of this information, as of
VARDATA_COMPRESSED_GET_EXTSIZE() and GET_COMPRESS_METHOD().

Let's remove the duplicate definition, and switch the TOAST code to use
the macros from varatt.h.  There should be no behavior change.

Note that toast_compression.h is removed from toast_internals.h, added
to the C files where its declarations are required.

Author: Nikhil Kumar Veldanda <veldanda.nikhilkumar17@gmail.com>
Author: Michael Paquier <michael@paquier.xyz>
Discussion: https://postgr.es/m/CAFAfj_FeJQZrKyVn7ur0aJx8iz8SR14NheVJNyc8JNoqtMX+og@mail.gmail.com
This commit is contained in:
Michael Paquier
2026-09-25 14:24:06 +09:00
parent 2c10c2ce4d
commit e27f3b2cad
7 changed files with 23 additions and 34 deletions

View File

@@ -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"

View File

@@ -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"

View File

@@ -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:

View File

@@ -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

View File

@@ -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);

View File

@@ -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.
*/

View File

@@ -4357,7 +4357,6 @@ timeout_handler_proc
timeout_params
timerCA
tlist_vinfo
toast_compress_header
toast_external_data
tokenize_error_callback_arg
transferMode