4 * Definitions for the builtin LZ compressor
6 * src/include/utils/pg_lzcompress.h
10 #ifndef _PG_LZCOMPRESS_H_
11 #define _PG_LZCOMPRESS_H_
17 * The information at the start of the compressed data.
20 typedef struct PGLZ_Header
22 int32 vl_len_; /* varlena header (do not touch directly!) */
30 * Macro to compute the buffer size required by pglz_compress().
31 * We allow 4 bytes for overrun before detecting compression failure.
34 #define PGLZ_MAX_OUTPUT(_dlen) ((_dlen) + 4 + sizeof(PGLZ_Header))
39 * Macro to determine the uncompressed data size contained
43 #define PGLZ_RAW_SIZE(_lzdata) ((_lzdata)->rawsize)
49 * Some values that control the compression algorithm.
51 * min_input_size Minimum input data size to consider compression.
53 * max_input_size Maximum input data size to consider compression.
55 * min_comp_rate Minimum compression rate (0-99%) to require.
56 * Regardless of min_comp_rate, the output must be
57 * smaller than the input, else we don't store
60 * first_success_by Abandon compression if we find no compressible
61 * data within the first this-many bytes.
63 * match_size_good The initial GOOD match size when starting history
64 * lookup. When looking up the history to find a
65 * match that could be expressed as a tag, the
66 * algorithm does not always walk back entirely.
67 * A good match fast is usually better than the
68 * best possible one very late. For each iteration
69 * in the lookup, this value is lowered so the
70 * longer the lookup takes, the smaller matches
71 * are considered good.
73 * match_size_drop The percentage by which match_size_good is lowered
74 * after each history check. Allowed values are
75 * 0 (no change until end) to 100 (only check
76 * latest history entry at all).
79 typedef struct PGLZ_Strategy
84 int32 first_success_by;
85 int32 match_size_good;
86 int32 match_size_drop;
91 * The standard strategies
93 * PGLZ_strategy_default Recommended default strategy for TOAST.
95 * PGLZ_strategy_always Try to compress inputs of any length.
96 * Fallback to uncompressed storage only if
97 * output would be larger than input.
100 extern const PGLZ_Strategy *const PGLZ_strategy_default;
101 extern const PGLZ_Strategy *const PGLZ_strategy_always;
105 * Global function declarations
108 extern bool pglz_compress(const char *source, int32 slen, PGLZ_Header *dest,
109 const PGLZ_Strategy *strategy);
110 extern void pglz_decompress(const PGLZ_Header *source, char *dest);
112 #endif /* _PG_LZCOMPRESS_H_ */