PostgreSQL Source Code  git master
toast_compression.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * toast_compression.h
4  * Functions for toast compression.
5  *
6  * Copyright (c) 2021-2024, PostgreSQL Global Development Group
7  *
8  * src/include/access/toast_compression.h
9  *
10  *-------------------------------------------------------------------------
11  */
12 
13 #ifndef TOAST_COMPRESSION_H
14 #define TOAST_COMPRESSION_H
15 
16 /*
17  * GUC support.
18  *
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.
22  */
24 
25 /*
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.
29  *
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.
36  */
37 typedef enum ToastCompressionId
38 {
43 
44 /*
45  * Built-in compression methods. pg_attribute will store these in the
46  * attcompression column. In attcompression, InvalidCompressionMethod
47  * denotes the default behavior.
48  */
49 #define TOAST_PGLZ_COMPRESSION 'p'
50 #define TOAST_LZ4_COMPRESSION 'l'
51 #define InvalidCompressionMethod '\0'
52 
53 #define CompressionMethodIsValid(cm) ((cm) != InvalidCompressionMethod)
54 
55 
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,
60  int32 slicelength);
61 
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,
66  int32 slicelength);
67 
68 /* other stuff */
70 extern char CompressionNameToMethod(const char *compression);
71 extern const char *GetCompressionMethodName(char method);
72 
73 #endif /* TOAST_COMPRESSION_H */
#define PGDLLIMPORT
Definition: c.h:1319
signed int int32
Definition: c.h:497
static struct @157 value
Definition: c.h:690
ToastCompressionId
@ TOAST_INVALID_COMPRESSION_ID
@ TOAST_LZ4_COMPRESSION_ID
@ TOAST_PGLZ_COMPRESSION_ID
struct varlena * lz4_decompress_datum(const struct varlena *value)
struct varlena * lz4_decompress_datum_slice(const struct varlena *value, int32 slicelength)
PGDLLIMPORT int default_toast_compression
struct varlena * pglz_decompress_datum(const struct varlena *value)
struct varlena * pglz_decompress_datum_slice(const struct varlena *value, int32 slicelength)
const char * GetCompressionMethodName(char method)
struct varlena * lz4_compress_datum(const struct varlena *value)
struct varlena * pglz_compress_datum(const struct varlena *value)
char CompressionNameToMethod(const char *compression)
ToastCompressionId toast_get_compression_id(struct varlena *attr)