1/*-------------------------------------------------------------------------
4 * Functions for toast compression.
6 * Copyright (c) 2021-2025, 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.
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.
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 */
62/* lz4 compression/decompression routines */
73#endif /* TOAST_COMPRESSION_H */
const char * GetCompressionMethodName(char method)
struct varlena * pglz_decompress_datum(const struct varlena *value)
struct varlena * lz4_compress_datum(const struct varlena *value)
@ TOAST_INVALID_COMPRESSION_ID
@ TOAST_LZ4_COMPRESSION_ID
@ TOAST_PGLZ_COMPRESSION_ID
struct varlena * pglz_decompress_datum_slice(const struct varlena *value, int32 slicelength)
struct varlena * pglz_compress_datum(const struct varlena *value)
PGDLLIMPORT int default_toast_compression
struct varlena * lz4_decompress_datum(const struct varlena *value)
struct varlena * lz4_decompress_datum_slice(const struct varlena *value, int32 slicelength)
char CompressionNameToMethod(const char *compression)
ToastCompressionId toast_get_compression_id(struct varlena *attr)