Refactor non-supported compression error message in toast_compression.c
authorMichael Paquier <michael@paquier.xyz>
Wed, 16 Jul 2025 02:59:22 +0000 (11:59 +0900)
committerMichael Paquier <michael@paquier.xyz>
Wed, 16 Jul 2025 02:59:22 +0000 (11:59 +0900)
This code used a NO_LZ4_SUPPORT() macro to issue an error in the code
paths where LZ4 [de]compression is attempted but the build does not
support it.  This commit refactors the code to use a more flexible error
message so as it can be used for other compression methods, where the
method is given in input of macro.

Extracted from a larger patch by the same author.

Author: Nikhil Kumar Veldanda <veldanda.nikhilkumar17@gmail.com>
Reviewed-by: Kirill Reshke <reshkekirill@gmail.com>
Discussion: https://postgr.es/m/CAFAfj_HX84EK4hyRYw50AOHOcdVi-+FFwAAPo7JHx4aShCvunQ@mail.gmail.com

src/backend/access/common/toast_compression.c

index 21f2f4af97e3ff55b7054be5284d14d4c729772e..926f1e4008abed6478bcc67559aad5603284dd25 100644 (file)
 /* GUC */
 int                    default_toast_compression = TOAST_PGLZ_COMPRESSION;
 
-#define NO_LZ4_SUPPORT() \
+#define NO_COMPRESSION_SUPPORT(method) \
        ereport(ERROR, \
                        (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), \
-                        errmsg("compression method lz4 not supported"), \
-                        errdetail("This functionality requires the server to be built with lz4 support.")))
+                        errmsg("compression method %s not supported", method), \
+                        errdetail("This functionality requires the server to be built with %s support.", method)))
 
 /*
  * Compress a varlena using PGLZ.
@@ -139,7 +139,7 @@ struct varlena *
 lz4_compress_datum(const struct varlena *value)
 {
 #ifndef USE_LZ4
-       NO_LZ4_SUPPORT();
+       NO_COMPRESSION_SUPPORT("lz4");
        return NULL;                            /* keep compiler quiet */
 #else
        int32           valsize;
@@ -182,7 +182,7 @@ struct varlena *
 lz4_decompress_datum(const struct varlena *value)
 {
 #ifndef USE_LZ4
-       NO_LZ4_SUPPORT();
+       NO_COMPRESSION_SUPPORT("lz4");
        return NULL;                            /* keep compiler quiet */
 #else
        int32           rawsize;
@@ -215,7 +215,7 @@ struct varlena *
 lz4_decompress_datum_slice(const struct varlena *value, int32 slicelength)
 {
 #ifndef USE_LZ4
-       NO_LZ4_SUPPORT();
+       NO_COMPRESSION_SUPPORT("lz4");
        return NULL;                            /* keep compiler quiet */
 #else
        int32           rawsize;
@@ -289,7 +289,7 @@ CompressionNameToMethod(const char *compression)
        else if (strcmp(compression, "lz4") == 0)
        {
 #ifndef USE_LZ4
-               NO_LZ4_SUPPORT();
+               NO_COMPRESSION_SUPPORT("lz4");
 #endif
                return TOAST_LZ4_COMPRESSION;
        }