1 /*-------------------------------------------------------------------------
4 * Functions for toast compression.
6 * Copyright (c) 2021, PostgreSQL Global Development Group
8 * src/include/access/toast_compression.h
10 *-------------------------------------------------------------------------
13 #ifndef TOAST_COMPRESSION_H
14 #define TOAST_COMPRESSION_H
19 * default_toast_compression is an integer for purposes of the GUC machinery,
20 * but the value is one of the char values defined below, as they appear in
21 * pg_attribute.attcompression, e.g. TOAST_PGLZ_COMPRESSION.
23 extern int default_toast_compression
;
26 * Built-in compression method ID. The toast compression header will store
27 * this in the first 2 bits of the raw length. These built-in compression
28 * method IDs are directly mapped to the built-in compression methods.
30 * Don't use these values for anything other than understanding the meaning
31 * of the raw bits from a varlena; in particular, if the goal is to identify
32 * a compression method, use the constants TOAST_PGLZ_COMPRESSION, etc.
33 * below. We might someday support more than 4 compression methods, but
34 * we can never have more than 4 values in this enum, because there are
35 * only 2 bits available in the places where this is stored.
37 typedef enum ToastCompressionId
39 TOAST_PGLZ_COMPRESSION_ID
= 0,
40 TOAST_LZ4_COMPRESSION_ID
= 1,
41 TOAST_INVALID_COMPRESSION_ID
= 2
45 * Built-in compression methods. pg_attribute will store these in the
46 * attcompression column. In attcompression, InvalidCompressionMethod
47 * denotes the default behavior.
49 #define TOAST_PGLZ_COMPRESSION 'p'
50 #define TOAST_LZ4_COMPRESSION 'l'
51 #define InvalidCompressionMethod '\0'
53 #define CompressionMethodIsValid(cm) ((cm) != InvalidCompressionMethod)
56 /* pglz compression/decompression routines */
57 extern struct varlena
*pglz_compress_datum(const struct varlena
*value
);
58 extern struct varlena
*pglz_decompress_datum(const struct varlena
*value
);
59 extern struct varlena
*pglz_decompress_datum_slice(const struct varlena
*value
,
62 /* lz4 compression/decompression routines */
63 extern struct varlena
*lz4_compress_datum(const struct varlena
*value
);
64 extern struct varlena
*lz4_decompress_datum(const struct varlena
*value
);
65 extern struct varlena
*lz4_decompress_datum_slice(const struct varlena
*value
,
69 extern ToastCompressionId
toast_get_compression_id(struct varlena
*attr
);
70 extern char CompressionNameToMethod(const char *compression
);
71 extern const char *GetCompressionMethodName(char method
);
73 #endif /* TOAST_COMPRESSION_H */