toast_internals.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*-------------------------------------------------------------------------
  2. *
  3. * toast_internals.h
  4. * Internal definitions for the TOAST system.
  5. *
  6. * Copyright (c) 2000-2022, PostgreSQL Global Development Group
  7. *
  8. * src/include/access/toast_internals.h
  9. *
  10. *-------------------------------------------------------------------------
  11. */
  12. #ifndef TOAST_INTERNALS_H
  13. #define TOAST_INTERNALS_H
  14. #include "access/toast_compression.h"
  15. #include "storage/lockdefs.h"
  16. #include "utils/relcache.h"
  17. #include "utils/snapshot.h"
  18. /*
  19. * The information at the start of the compressed toast data.
  20. */
  21. typedef struct toast_compress_header
  22. {
  23. int32 vl_len_; /* varlena header (do not touch directly!) */
  24. uint32 tcinfo; /* 2 bits for compression method and 30 bits
  25. * external size; see va_extinfo */
  26. } toast_compress_header;
  27. /*
  28. * Utilities for manipulation of header information for compressed
  29. * toast entries.
  30. */
  31. #define TOAST_COMPRESS_EXTSIZE(ptr) \
  32. (((toast_compress_header *) (ptr))->tcinfo & VARLENA_EXTSIZE_MASK)
  33. #define TOAST_COMPRESS_METHOD(ptr) \
  34. (((toast_compress_header *) (ptr))->tcinfo >> VARLENA_EXTSIZE_BITS)
  35. #define TOAST_COMPRESS_SET_SIZE_AND_COMPRESS_METHOD(ptr, len, cm_method) \
  36. do { \
  37. Assert((len) > 0 && (len) <= VARLENA_EXTSIZE_MASK); \
  38. Assert((cm_method) == TOAST_PGLZ_COMPRESSION_ID || \
  39. (cm_method) == TOAST_LZ4_COMPRESSION_ID); \
  40. ((toast_compress_header *) (ptr))->tcinfo = \
  41. (len) | ((uint32) (cm_method) << VARLENA_EXTSIZE_BITS); \
  42. } while (0)
  43. extern Datum toast_compress_datum(Datum value, char cmethod);
  44. extern Oid toast_get_valid_index(Oid toastoid, LOCKMODE lock);
  45. extern void toast_delete_datum(Relation rel, Datum value, bool is_speculative);
  46. extern Datum toast_save_datum(Relation rel, Datum value,
  47. struct varlena *oldexternal, int options);
  48. extern int toast_open_indexes(Relation toastrel,
  49. LOCKMODE lock,
  50. Relation **toastidxs,
  51. int *num_indexes);
  52. extern void toast_close_indexes(Relation *toastidxs, int num_indexes,
  53. LOCKMODE lock);
  54. extern void init_toast_snapshot(Snapshot toast_snapshot);
  55. #endif /* TOAST_INTERNALS_H */