Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 18ac08f

Browse files
committed
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
1 parent cbe6dd1 commit 18ac08f

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

doc/src/sgml/protocol.sgml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2757,8 +2757,10 @@ psql "dbname=postgres replication=database" -c "IDENTIFY_SYSTEM;"
27572757
<literal>-1</literal>), for <literal>lz4</literal> an integer
27582758
between 1 and 12 (default <literal>0</literal> for fast compression
27592759
mode), and for <literal>zstd</literal> an integer between
2760-
<literal>1</literal> and <literal>22</literal> (default
2761-
<literal>ZSTD_CLEVEL_DEFAULT</literal> or <literal>3</literal>).
2760+
<literal>ZSTD_minCLevel()</literal> (usually <literal>-131072</literal>)
2761+
and <literal>ZSTD_maxCLevel()</literal> (usually <literal>22</literal>),
2762+
(default <literal>ZSTD_CLEVEL_DEFAULT</literal> or
2763+
<literal>3</literal>).
27622764
</para>
27632765

27642766
<para>

src/common/compression.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,9 @@ validate_compress_specification(pg_compress_specification *spec)
324324
default_level = 0; /* fast mode */
325325
break;
326326
case PG_COMPRESSION_ZSTD:
327-
max_level = 22;
328327
#ifdef USE_ZSTD
328+
max_level = ZSTD_maxCLevel();
329+
min_level = ZSTD_minCLevel();
329330
default_level = ZSTD_CLEVEL_DEFAULT;
330331
#endif
331332
break;

0 commit comments

Comments
 (0)