toast_compression.h 2.7 KB

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