itemid.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /*-------------------------------------------------------------------------
  2. *
  3. * itemid.h
  4. * Standard POSTGRES buffer page item identifier definitions.
  5. *
  6. *
  7. * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
  8. * Portions Copyright (c) 1994, Regents of the University of California
  9. *
  10. * src/include/storage/itemid.h
  11. *
  12. *-------------------------------------------------------------------------
  13. */
  14. #ifndef ITEMID_H
  15. #define ITEMID_H
  16. /*
  17. * An item pointer (also called line pointer) on a buffer page
  18. *
  19. * In some cases an item pointer is "in use" but does not have any associated
  20. * storage on the page. By convention, lp_len == 0 in every item pointer
  21. * that does not have storage, independently of its lp_flags state.
  22. */
  23. typedef struct ItemIdData
  24. {
  25. unsigned lp_off:15, /* offset to tuple (from start of page) */
  26. lp_flags:2, /* state of item pointer, see below */
  27. lp_len:15; /* byte length of tuple */
  28. } ItemIdData;
  29. typedef ItemIdData *ItemId;
  30. /*
  31. * lp_flags has these possible states. An UNUSED line pointer is available
  32. * for immediate re-use, the other states are not.
  33. */
  34. #define LP_UNUSED 0 /* unused (should always have lp_len=0) */
  35. #define LP_NORMAL 1 /* used (should always have lp_len>0) */
  36. #define LP_REDIRECT 2 /* HOT redirect (should have lp_len=0) */
  37. #define LP_DEAD 3 /* dead, may or may not have storage */
  38. /*
  39. * Item offsets and lengths are represented by these types when
  40. * they're not actually stored in an ItemIdData.
  41. */
  42. typedef uint16 ItemOffset;
  43. typedef uint16 ItemLength;
  44. /* ----------------
  45. * support macros
  46. * ----------------
  47. */
  48. /*
  49. * ItemIdGetLength
  50. */
  51. #define ItemIdGetLength(itemId) \
  52. ((itemId)->lp_len)
  53. /*
  54. * ItemIdGetOffset
  55. */
  56. #define ItemIdGetOffset(itemId) \
  57. ((itemId)->lp_off)
  58. /*
  59. * ItemIdGetFlags
  60. */
  61. #define ItemIdGetFlags(itemId) \
  62. ((itemId)->lp_flags)
  63. /*
  64. * ItemIdGetRedirect
  65. * In a REDIRECT pointer, lp_off holds the link to the next item pointer
  66. */
  67. #define ItemIdGetRedirect(itemId) \
  68. ((itemId)->lp_off)
  69. /*
  70. * ItemIdIsValid
  71. * True iff item identifier is valid.
  72. * This is a pretty weak test, probably useful only in Asserts.
  73. */
  74. #define ItemIdIsValid(itemId) PointerIsValid(itemId)
  75. /*
  76. * ItemIdIsUsed
  77. * True iff item identifier is in use.
  78. */
  79. #define ItemIdIsUsed(itemId) \
  80. ((itemId)->lp_flags != LP_UNUSED)
  81. /*
  82. * ItemIdIsNormal
  83. * True iff item identifier is in state NORMAL.
  84. */
  85. #define ItemIdIsNormal(itemId) \
  86. ((itemId)->lp_flags == LP_NORMAL)
  87. /*
  88. * ItemIdIsRedirected
  89. * True iff item identifier is in state REDIRECT.
  90. */
  91. #define ItemIdIsRedirected(itemId) \
  92. ((itemId)->lp_flags == LP_REDIRECT)
  93. /*
  94. * ItemIdIsDead
  95. * True iff item identifier is in state DEAD.
  96. */
  97. #define ItemIdIsDead(itemId) \
  98. ((itemId)->lp_flags == LP_DEAD)
  99. /*
  100. * ItemIdHasStorage
  101. * True iff item identifier has associated storage.
  102. */
  103. #define ItemIdHasStorage(itemId) \
  104. ((itemId)->lp_len != 0)
  105. /*
  106. * ItemIdSetUnused
  107. * Set the item identifier to be UNUSED, with no storage.
  108. * Beware of multiple evaluations of itemId!
  109. */
  110. #define ItemIdSetUnused(itemId) \
  111. ( \
  112. (itemId)->lp_flags = LP_UNUSED, \
  113. (itemId)->lp_off = 0, \
  114. (itemId)->lp_len = 0 \
  115. )
  116. /*
  117. * ItemIdSetNormal
  118. * Set the item identifier to be NORMAL, with the specified storage.
  119. * Beware of multiple evaluations of itemId!
  120. */
  121. #define ItemIdSetNormal(itemId, off, len) \
  122. ( \
  123. (itemId)->lp_flags = LP_NORMAL, \
  124. (itemId)->lp_off = (off), \
  125. (itemId)->lp_len = (len) \
  126. )
  127. /*
  128. * ItemIdSetRedirect
  129. * Set the item identifier to be REDIRECT, with the specified link.
  130. * Beware of multiple evaluations of itemId!
  131. */
  132. #define ItemIdSetRedirect(itemId, link) \
  133. ( \
  134. (itemId)->lp_flags = LP_REDIRECT, \
  135. (itemId)->lp_off = (link), \
  136. (itemId)->lp_len = 0 \
  137. )
  138. /*
  139. * ItemIdSetDead
  140. * Set the item identifier to be DEAD, with no storage.
  141. * Beware of multiple evaluations of itemId!
  142. */
  143. #define ItemIdSetDead(itemId) \
  144. ( \
  145. (itemId)->lp_flags = LP_DEAD, \
  146. (itemId)->lp_off = 0, \
  147. (itemId)->lp_len = 0 \
  148. )
  149. /*
  150. * ItemIdMarkDead
  151. * Set the item identifier to be DEAD, keeping its existing storage.
  152. *
  153. * Note: in indexes, this is used as if it were a hint-bit mechanism;
  154. * we trust that multiple processors can do this in parallel and get
  155. * the same result.
  156. */
  157. #define ItemIdMarkDead(itemId) \
  158. ( \
  159. (itemId)->lp_flags = LP_DEAD \
  160. )
  161. #endif /* ITEMID_H */