Header And Logo

PostgreSQL
| The world's most advanced open source database.

pg_lzcompress.h

Go to the documentation of this file.
00001 /* ----------
00002  * pg_lzcompress.h -
00003  *
00004  *  Definitions for the builtin LZ compressor
00005  *
00006  * src/include/utils/pg_lzcompress.h
00007  * ----------
00008  */
00009 
00010 #ifndef _PG_LZCOMPRESS_H_
00011 #define _PG_LZCOMPRESS_H_
00012 
00013 
00014 /* ----------
00015  * PGLZ_Header -
00016  *
00017  *      The information at the start of the compressed data.
00018  * ----------
00019  */
00020 typedef struct PGLZ_Header
00021 {
00022     int32       vl_len_;        /* varlena header (do not touch directly!) */
00023     int32       rawsize;
00024 } PGLZ_Header;
00025 
00026 
00027 /* ----------
00028  * PGLZ_MAX_OUTPUT -
00029  *
00030  *      Macro to compute the buffer size required by pglz_compress().
00031  *      We allow 4 bytes for overrun before detecting compression failure.
00032  * ----------
00033  */
00034 #define PGLZ_MAX_OUTPUT(_dlen)          ((_dlen) + 4 + sizeof(PGLZ_Header))
00035 
00036 /* ----------
00037  * PGLZ_RAW_SIZE -
00038  *
00039  *      Macro to determine the uncompressed data size contained
00040  *      in the entry.
00041  * ----------
00042  */
00043 #define PGLZ_RAW_SIZE(_lzdata)          ((_lzdata)->rawsize)
00044 
00045 
00046 /* ----------
00047  * PGLZ_Strategy -
00048  *
00049  *      Some values that control the compression algorithm.
00050  *
00051  *      min_input_size      Minimum input data size to consider compression.
00052  *
00053  *      max_input_size      Maximum input data size to consider compression.
00054  *
00055  *      min_comp_rate       Minimum compression rate (0-99%) to require.
00056  *                          Regardless of min_comp_rate, the output must be
00057  *                          smaller than the input, else we don't store
00058  *                          compressed.
00059  *
00060  *      first_success_by    Abandon compression if we find no compressible
00061  *                          data within the first this-many bytes.
00062  *
00063  *      match_size_good     The initial GOOD match size when starting history
00064  *                          lookup. When looking up the history to find a
00065  *                          match that could be expressed as a tag, the
00066  *                          algorithm does not always walk back entirely.
00067  *                          A good match fast is usually better than the
00068  *                          best possible one very late. For each iteration
00069  *                          in the lookup, this value is lowered so the
00070  *                          longer the lookup takes, the smaller matches
00071  *                          are considered good.
00072  *
00073  *      match_size_drop     The percentage by which match_size_good is lowered
00074  *                          after each history check. Allowed values are
00075  *                          0 (no change until end) to 100 (only check
00076  *                          latest history entry at all).
00077  * ----------
00078  */
00079 typedef struct PGLZ_Strategy
00080 {
00081     int32       min_input_size;
00082     int32       max_input_size;
00083     int32       min_comp_rate;
00084     int32       first_success_by;
00085     int32       match_size_good;
00086     int32       match_size_drop;
00087 } PGLZ_Strategy;
00088 
00089 
00090 /* ----------
00091  * The standard strategies
00092  *
00093  *      PGLZ_strategy_default       Recommended default strategy for TOAST.
00094  *
00095  *      PGLZ_strategy_always        Try to compress inputs of any length.
00096  *                                  Fallback to uncompressed storage only if
00097  *                                  output would be larger than input.
00098  * ----------
00099  */
00100 extern const PGLZ_Strategy *const PGLZ_strategy_default;
00101 extern const PGLZ_Strategy *const PGLZ_strategy_always;
00102 
00103 
00104 /* ----------
00105  * Global function declarations
00106  * ----------
00107  */
00108 extern bool pglz_compress(const char *source, int32 slen, PGLZ_Header *dest,
00109               const PGLZ_Strategy *strategy);
00110 extern void pglz_decompress(const PGLZ_Header *source, char *dest);
00111 
00112 #endif   /* _PG_LZCOMPRESS_H_ */