mirror of
https://github.com/postgres/postgres.git
synced 2025-09-03 15:22:11 +03:00
Support long distance matching for zstd compression
zstd compression supports a special mode for finding matched in distant past, which may result in better compression ratio, at the expense of using more memory (the window size is 128MB). To enable this optional mode, use the "long" keyword when specifying the compression method (--compress=zstd:long). Author: Justin Pryzby Reviewed-by: Tomas Vondra, Jacob Champion Discussion: https://postgr.es/m/20230224191840.GD1653@telsasoft.com Discussion: https://postgr.es/m/20220327205020.GM28503@telsasoft.com
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
* Otherwise, a compression specification is a comma-separated list of items,
|
||||
* each having the form keyword or keyword=value.
|
||||
*
|
||||
* Currently, the only supported keywords are "level" and "workers".
|
||||
* Currently, the supported keywords are "level", "long", and "workers".
|
||||
*
|
||||
* Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
|
||||
*
|
||||
@@ -38,6 +38,8 @@
|
||||
|
||||
static int expect_integer_value(char *keyword, char *value,
|
||||
pg_compress_specification *result);
|
||||
static bool expect_boolean_value(char *keyword, char *value,
|
||||
pg_compress_specification *result);
|
||||
|
||||
/*
|
||||
* Look up a compression algorithm by name. Returns true and sets *algorithm
|
||||
@@ -232,6 +234,11 @@ parse_compress_specification(pg_compress_algorithm algorithm, char *specificatio
|
||||
result->workers = expect_integer_value(keyword, value, result);
|
||||
result->options |= PG_COMPRESSION_OPTION_WORKERS;
|
||||
}
|
||||
else if (strcmp(keyword, "long") == 0)
|
||||
{
|
||||
result->long_distance = expect_boolean_value(keyword, value, result);
|
||||
result->options |= PG_COMPRESSION_OPTION_LONG_DISTANCE;
|
||||
}
|
||||
else
|
||||
result->parse_error =
|
||||
psprintf(_("unrecognized compression option: \"%s\""), keyword);
|
||||
@@ -289,6 +296,43 @@ expect_integer_value(char *keyword, char *value, pg_compress_specification *resu
|
||||
return ivalue;
|
||||
}
|
||||
|
||||
/*
|
||||
* Parse 'value' as a boolean and return the result.
|
||||
*
|
||||
* If parsing fails, set result->parse_error to an appropriate message
|
||||
* and return -1. The caller must check result->parse_error to determine if
|
||||
* the call was successful.
|
||||
*
|
||||
* Valid values are: yes, no, on, off, 1, 0.
|
||||
*
|
||||
* Inspired by ParseVariableBool().
|
||||
*/
|
||||
static bool
|
||||
expect_boolean_value(char *keyword, char *value, pg_compress_specification *result)
|
||||
{
|
||||
if (value == NULL)
|
||||
return true;
|
||||
|
||||
if (pg_strcasecmp(value, "yes") == 0)
|
||||
return true;
|
||||
if (pg_strcasecmp(value, "on") == 0)
|
||||
return true;
|
||||
if (pg_strcasecmp(value, "1") == 0)
|
||||
return true;
|
||||
|
||||
if (pg_strcasecmp(value, "no") == 0)
|
||||
return false;
|
||||
if (pg_strcasecmp(value, "off") == 0)
|
||||
return false;
|
||||
if (pg_strcasecmp(value, "0") == 0)
|
||||
return false;
|
||||
|
||||
result->parse_error =
|
||||
psprintf(_("value for compression option \"%s\" must be a boolean"),
|
||||
keyword);
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns NULL if the compression specification string was syntactically
|
||||
* valid and semantically sensible. Otherwise, returns an error message.
|
||||
@@ -354,6 +398,17 @@ validate_compress_specification(pg_compress_specification *spec)
|
||||
get_compress_algorithm_name(spec->algorithm));
|
||||
}
|
||||
|
||||
/*
|
||||
* Of the compression algorithms that we currently support, only zstd
|
||||
* supports long-distance mode.
|
||||
*/
|
||||
if ((spec->options & PG_COMPRESSION_OPTION_LONG_DISTANCE) != 0 &&
|
||||
(spec->algorithm != PG_COMPRESSION_ZSTD))
|
||||
{
|
||||
return psprintf(_("compression algorithm \"%s\" does not support long-distance mode"),
|
||||
get_compress_algorithm_name(spec->algorithm));
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user