aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Paquier <michael@paquier.xyz>2022-09-22 20:03:30 +0900
committerMichael Paquier <michael@paquier.xyz>2022-09-22 20:03:30 +0900
commitade925e1693a595ef1c278583fa699ca6fc1ff45 (patch)
tree6e7be7def3c8cb804d7310cf228beec2d3f3c92f
parent901ef14afe981065a0c5c61b1759d36482869d98 (diff)
downloadpostgresql-ade925e1693a595ef1c278583fa699ca6fc1ff45.tar.gz
postgresql-ade925e1693a595ef1c278583fa699ca6fc1ff45.zip
Use min/max bounds defined by Zstd for compression level
The bounds hardcoded in compression.c since ffd5365 (minimum at 1 and maximum at 22) do not match the reality of what zstd is able to handle, these values being available via ZSTD_maxCLevel() and ZSTD_minCLevel() at run-time. The maximum of 22 is actually correct in recent versions, but the minimum was not as the library can go down to -131720 by design. This commit changes the code to use the run-time values in the code instead of some hardcoded ones. Zstd seems to assume that these bounds could change in the future, and Postgres will be able to adapt automatically to such changes thanks to what's being done in this commit. Reported-by: Justin Prysby Discussion: https://postgr.es/m/20220922033716.GL31833@telsasoft.com Backpatch-through: 15
-rw-r--r--doc/src/sgml/protocol.sgml6
-rw-r--r--src/common/compression.c3
2 files changed, 6 insertions, 3 deletions
diff --git a/doc/src/sgml/protocol.sgml b/doc/src/sgml/protocol.sgml
index 946d5634913..1a70685021d 100644
--- a/doc/src/sgml/protocol.sgml
+++ b/doc/src/sgml/protocol.sgml
@@ -2757,8 +2757,10 @@ psql "dbname=postgres replication=database" -c "IDENTIFY_SYSTEM;"
<literal>-1</literal>), for <literal>lz4</literal> an integer
between 1 and 12 (default <literal>0</literal> for fast compression
mode), and for <literal>zstd</literal> an integer between
- <literal>1</literal> and <literal>22</literal> (default
- <literal>ZSTD_CLEVEL_DEFAULT</literal> or <literal>3</literal>).
+ <literal>ZSTD_minCLevel()</literal> (usually <literal>-131072</literal>)
+ and <literal>ZSTD_maxCLevel()</literal> (usually <literal>22</literal>),
+ (default <literal>ZSTD_CLEVEL_DEFAULT</literal> or
+ <literal>3</literal>).
</para>
<para>
diff --git a/src/common/compression.c b/src/common/compression.c
index e40ce98ef3a..0c6bb9177b9 100644
--- a/src/common/compression.c
+++ b/src/common/compression.c
@@ -324,8 +324,9 @@ validate_compress_specification(pg_compress_specification *spec)
default_level = 0; /* fast mode */
break;
case PG_COMPRESSION_ZSTD:
- max_level = 22;
#ifdef USE_ZSTD
+ max_level = ZSTD_maxCLevel();
+ min_level = ZSTD_minCLevel();
default_level = ZSTD_CLEVEL_DEFAULT;
#endif
break;