2
0

detoast.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*-------------------------------------------------------------------------
  2. *
  3. * detoast.h
  4. * Access to compressed and external varlena values.
  5. *
  6. * Copyright (c) 2000-2022, PostgreSQL Global Development Group
  7. *
  8. * src/include/access/detoast.h
  9. *
  10. *-------------------------------------------------------------------------
  11. */
  12. #ifndef DETOAST_H
  13. #define DETOAST_H
  14. /*
  15. * Macro to fetch the possibly-unaligned contents of an EXTERNAL datum
  16. * into a local "struct varatt_external" toast pointer. This should be
  17. * just a memcpy, but some versions of gcc seem to produce broken code
  18. * that assumes the datum contents are aligned. Introducing an explicit
  19. * intermediate "varattrib_1b_e *" variable seems to fix it.
  20. */
  21. #define VARATT_EXTERNAL_GET_POINTER(toast_pointer, attr) \
  22. do { \
  23. varattrib_1b_e *attre = (varattrib_1b_e *) (attr); \
  24. Assert(VARATT_IS_EXTERNAL(attre)); \
  25. Assert(VARSIZE_EXTERNAL(attre) == sizeof(toast_pointer) + VARHDRSZ_EXTERNAL); \
  26. memcpy(&(toast_pointer), VARDATA_EXTERNAL(attre), sizeof(toast_pointer)); \
  27. } while (0)
  28. /* Size of an EXTERNAL datum that contains a standard TOAST pointer */
  29. #define TOAST_POINTER_SIZE (VARHDRSZ_EXTERNAL + sizeof(varatt_external))
  30. /* Size of an EXTERNAL datum that contains an indirection pointer */
  31. #define INDIRECT_POINTER_SIZE (VARHDRSZ_EXTERNAL + sizeof(varatt_indirect))
  32. /* ----------
  33. * detoast_external_attr() -
  34. *
  35. * Fetches an external stored attribute from the toast
  36. * relation. Does NOT decompress it, if stored external
  37. * in compressed format.
  38. * ----------
  39. */
  40. extern struct varlena *detoast_external_attr(struct varlena *attr);
  41. /* ----------
  42. * detoast_attr() -
  43. *
  44. * Fully detoasts one attribute, fetching and/or decompressing
  45. * it as needed.
  46. * ----------
  47. */
  48. extern struct varlena *detoast_attr(struct varlena *attr);
  49. /* ----------
  50. * detoast_attr_slice() -
  51. *
  52. * Fetches only the specified portion of an attribute.
  53. * (Handles all cases for attribute storage)
  54. * ----------
  55. */
  56. extern struct varlena *detoast_attr_slice(struct varlena *attr,
  57. int32 sliceoffset,
  58. int32 slicelength);
  59. /* ----------
  60. * toast_raw_datum_size -
  61. *
  62. * Return the raw (detoasted) size of a varlena datum
  63. * ----------
  64. */
  65. extern Size toast_raw_datum_size(Datum value);
  66. /* ----------
  67. * toast_datum_size -
  68. *
  69. * Return the storage size of a varlena datum
  70. * ----------
  71. */
  72. extern Size toast_datum_size(Datum value);
  73. #endif /* DETOAST_H */