]> granicus.if.org Git - postgresql/blob - src/include/utils/pg_lzcompress.h
Fix hstore_to_json_loose's detection of valid JSON number values.
[postgresql] / src / include / utils / pg_lzcompress.h
1 /* ----------
2  * pg_lzcompress.h -
3  *
4  *      Definitions for the builtin LZ compressor
5  *
6  * src/include/utils/pg_lzcompress.h
7  * ----------
8  */
9
10 #ifndef _PG_LZCOMPRESS_H_
11 #define _PG_LZCOMPRESS_H_
12
13
14 /* ----------
15  * PGLZ_Header -
16  *
17  *              The information at the start of the compressed data.
18  * ----------
19  */
20 typedef struct PGLZ_Header
21 {
22         int32           vl_len_;                /* varlena header (do not touch directly!) */
23         int32           rawsize;
24 } PGLZ_Header;
25
26
27 /* ----------
28  * PGLZ_MAX_OUTPUT -
29  *
30  *              Macro to compute the buffer size required by pglz_compress().
31  *              We allow 4 bytes for overrun before detecting compression failure.
32  * ----------
33  */
34 #define PGLZ_MAX_OUTPUT(_dlen)                  ((_dlen) + 4 + sizeof(PGLZ_Header))
35
36 /* ----------
37  * PGLZ_RAW_SIZE -
38  *
39  *              Macro to determine the uncompressed data size contained
40  *              in the entry.
41  * ----------
42  */
43 #define PGLZ_RAW_SIZE(_lzdata)                  ((_lzdata)->rawsize)
44
45
46 /* ----------
47  * PGLZ_Strategy -
48  *
49  *              Some values that control the compression algorithm.
50  *
51  *              min_input_size          Minimum input data size to consider compression.
52  *
53  *              max_input_size          Maximum input data size to consider compression.
54  *
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
58  *                                                      compressed.
59  *
60  *              first_success_by        Abandon compression if we find no compressible
61  *                                                      data within the first this-many bytes.
62  *
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.
72  *
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).
77  * ----------
78  */
79 typedef struct PGLZ_Strategy
80 {
81         int32           min_input_size;
82         int32           max_input_size;
83         int32           min_comp_rate;
84         int32           first_success_by;
85         int32           match_size_good;
86         int32           match_size_drop;
87 } PGLZ_Strategy;
88
89
90 /* ----------
91  * The standard strategies
92  *
93  *              PGLZ_strategy_default           Recommended default strategy for TOAST.
94  *
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.
98  * ----------
99  */
100 extern const PGLZ_Strategy *const PGLZ_strategy_default;
101 extern const PGLZ_Strategy *const PGLZ_strategy_always;
102
103
104 /* ----------
105  * Global function declarations
106  * ----------
107  */
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);
111
112 #endif   /* _PG_LZCOMPRESS_H_ */