1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-10 17:42:29 +03:00

Tidy up more loose ends related to configurable TOAST compression.

Change the default_toast_compression GUC to be an enum rather than
a string. Earlier, uncommitted versions of the patch supported using
CREATE ACCESS METHOD to add new compression methods to a running
system, but that idea was dropped before commit. So, we can simplify
the GUC handling as well, which has the nice side effect of improving
the error messages.

While updating the documentation to reflect the new GUC type, also
move it back to the right place in the list. I moved this while
revising what became commit 24f0e395ac,
but apparently the intended ordering is "alphabetical" rather than
"whatever Robert thinks looks nice."

Rejigger things to avoid having access/toast_compression.h depend on
utils/guc.h, so that we don't end up with every file that includes
it also depending on something largely unrelated. Move a few
inline functions back into the C source file partly to help reduce
dependencies and partly just to avoid clutter. A few very minor
cosmetic fixes.

Original patch by Justin Pryzby, but very heavily edited by me,
and reverse reviewed by him and also reviewed by by Tom Lane.

Discussion: http://postgr.es/m/CA+TgmoYp=GT_ztUCeZg2i4hkHAQv8o=-nVJ1-TKWTG1zQOmOpg@mail.gmail.com
This commit is contained in:
Robert Haas
2021-03-24 12:36:08 -04:00
parent 49ab61f0bd
commit e5595de03e
6 changed files with 110 additions and 138 deletions

View File

@@ -23,8 +23,15 @@
#include "fmgr.h"
#include "utils/builtins.h"
/* Compile-time default */
char *default_toast_compression = DEFAULT_TOAST_COMPRESSION;
/* GUC */
int default_toast_compression = TOAST_PGLZ_COMPRESSION;
#define NO_LZ4_SUPPORT() \
ereport(ERROR, \
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED), \
errmsg("unsupported LZ4 compression method"), \
errdetail("This functionality requires the server to be built with lz4 support."), \
errhint("You need to rebuild PostgreSQL using --with-lz4.")))
/*
* Compress a varlena using PGLZ.
@@ -271,46 +278,41 @@ toast_get_compression_id(struct varlena *attr)
}
/*
* Validate a new value for the default_toast_compression GUC.
* CompressionNameToMethod - Get compression method from compression name
*
* Search in the available built-in methods. If the compression not found
* in the built-in methods then return InvalidCompressionMethod.
*/
bool
check_default_toast_compression(char **newval, void **extra, GucSource source)
char
CompressionNameToMethod(const char *compression)
{
if (**newval == '\0')
if (strcmp(compression, "pglz") == 0)
return TOAST_PGLZ_COMPRESSION;
else if (strcmp(compression, "lz4") == 0)
{
GUC_check_errdetail("%s cannot be empty.",
"default_toast_compression");
return false;
#ifndef USE_LZ4
NO_LZ4_SUPPORT();
#endif
return TOAST_LZ4_COMPRESSION;
}
if (strlen(*newval) >= NAMEDATALEN)
{
GUC_check_errdetail("%s is too long (maximum %d characters).",
"default_toast_compression", NAMEDATALEN - 1);
return false;
}
if (!CompressionMethodIsValid(CompressionNameToMethod(*newval)))
{
/*
* When source == PGC_S_TEST, don't throw a hard error for a
* nonexistent compression method, only a NOTICE. See comments in
* guc.h.
*/
if (source == PGC_S_TEST)
{
ereport(NOTICE,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("compression method \"%s\" does not exist",
*newval)));
}
else
{
GUC_check_errdetail("Compression method \"%s\" does not exist.",
*newval);
return false;
}
}
return true;
return InvalidCompressionMethod;
}
/*
* GetCompressionMethodName - Get compression method name
*/
const char *
GetCompressionMethodName(char method)
{
switch (method)
{
case TOAST_PGLZ_COMPRESSION:
return "pglz";
case TOAST_LZ4_COMPRESSION:
return "lz4";
default:
elog(ERROR, "invalid compression method %c", method);
return NULL; /* keep compiler quiet */
}
}