toast_helper.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*-------------------------------------------------------------------------
  2. *
  3. * toast_helper.h
  4. * Helper functions for table AMs implementing compressed or
  5. * out-of-line storage of varlena attributes.
  6. *
  7. * Copyright (c) 2000-2022, PostgreSQL Global Development Group
  8. *
  9. * src/include/access/toast_helper.h
  10. *
  11. *-------------------------------------------------------------------------
  12. */
  13. #ifndef TOAST_HELPER_H
  14. #define TOAST_HELPER_H
  15. #include "utils/rel.h"
  16. /*
  17. * Information about one column of a tuple being toasted.
  18. *
  19. * NOTE: toast_action[i] can have these values:
  20. * ' ' default handling
  21. * TYPSTORAGE_PLAIN already processed --- don't touch it
  22. * TYPSTORAGE_EXTENDED incompressible, but OK to move off
  23. *
  24. * NOTE: toast_attr[i].tai_size is only made valid for varlena attributes with
  25. * toast_action[i] different from TYPSTORAGE_PLAIN.
  26. */
  27. typedef struct
  28. {
  29. struct varlena *tai_oldexternal;
  30. int32 tai_size;
  31. uint8 tai_colflags;
  32. char tai_compression;
  33. } ToastAttrInfo;
  34. /*
  35. * Information about one tuple being toasted.
  36. */
  37. typedef struct
  38. {
  39. /*
  40. * Before calling toast_tuple_init, the caller must initialize the
  41. * following fields. Each array must have a length equal to
  42. * ttc_rel->rd_att->natts. The tts_oldvalues and tts_oldisnull fields
  43. * should be NULL in the case of an insert.
  44. */
  45. Relation ttc_rel; /* the relation that contains the tuple */
  46. Datum *ttc_values; /* values from the tuple columns */
  47. bool *ttc_isnull; /* null flags for the tuple columns */
  48. Datum *ttc_oldvalues; /* values from previous tuple */
  49. bool *ttc_oldisnull; /* null flags from previous tuple */
  50. /*
  51. * Before calling toast_tuple_init, the caller should set tts_attr to
  52. * point to an array of ToastAttrInfo structures of a length equal to
  53. * tts_rel->rd_att->natts. The contents of the array need not be
  54. * initialized. ttc_flags also does not need to be initialized.
  55. */
  56. uint8 ttc_flags;
  57. ToastAttrInfo *ttc_attr;
  58. } ToastTupleContext;
  59. /*
  60. * Flags indicating the overall state of a TOAST operation.
  61. *
  62. * TOAST_NEEDS_DELETE_OLD indicates that one or more old TOAST datums need
  63. * to be deleted.
  64. *
  65. * TOAST_NEEDS_FREE indicates that one or more TOAST values need to be freed.
  66. *
  67. * TOAST_HAS_NULLS indicates that nulls were found in the tuple being toasted.
  68. *
  69. * TOAST_NEEDS_CHANGE indicates that a new tuple needs to built; in other
  70. * words, the toaster did something.
  71. */
  72. #define TOAST_NEEDS_DELETE_OLD 0x0001
  73. #define TOAST_NEEDS_FREE 0x0002
  74. #define TOAST_HAS_NULLS 0x0004
  75. #define TOAST_NEEDS_CHANGE 0x0008
  76. /*
  77. * Flags indicating the status of a TOAST operation with respect to a
  78. * particular column.
  79. *
  80. * TOASTCOL_NEEDS_DELETE_OLD indicates that the old TOAST datums for this
  81. * column need to be deleted.
  82. *
  83. * TOASTCOL_NEEDS_FREE indicates that the value for this column needs to
  84. * be freed.
  85. *
  86. * TOASTCOL_IGNORE indicates that the toaster should not further process
  87. * this column.
  88. *
  89. * TOASTCOL_INCOMPRESSIBLE indicates that this column has been found to
  90. * be incompressible, but could be moved out-of-line.
  91. */
  92. #define TOASTCOL_NEEDS_DELETE_OLD TOAST_NEEDS_DELETE_OLD
  93. #define TOASTCOL_NEEDS_FREE TOAST_NEEDS_FREE
  94. #define TOASTCOL_IGNORE 0x0010
  95. #define TOASTCOL_INCOMPRESSIBLE 0x0020
  96. extern void toast_tuple_init(ToastTupleContext *ttc);
  97. extern int toast_tuple_find_biggest_attribute(ToastTupleContext *ttc,
  98. bool for_compression,
  99. bool check_main);
  100. extern void toast_tuple_try_compression(ToastTupleContext *ttc, int attribute);
  101. extern void toast_tuple_externalize(ToastTupleContext *ttc, int attribute,
  102. int options);
  103. extern void toast_tuple_cleanup(ToastTupleContext *ttc);
  104. extern void toast_delete_external(Relation rel, Datum *values, bool *isnull,
  105. bool is_speculative);
  106. #endif