1 /*-------------------------------------------------------------------------
4 * Standard POSTGRES buffer page item identifier definitions.
7 * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
12 *-------------------------------------------------------------------------
18 * An item pointer (also called line pointer) on a buffer page
20 * In some cases an item pointer is "in use" but does not have any associated
21 * storage on the page. By convention, lp_len == 0 in every item pointer
22 * that does not have storage, independently of its lp_flags state.
24 typedef struct ItemIdData
26 unsigned lp_off
:15, /* offset to tuple (from start of page) */
27 lp_flags
:2, /* state of item pointer, see below */
28 lp_len
:15; /* byte length of tuple */
31 typedef ItemIdData
*ItemId
;
34 * lp_flags has these possible states. An UNUSED line pointer is available
35 * for immediate re-use, the other states are not.
37 #define LP_UNUSED 0 /* unused (should always have lp_len=0) */
38 #define LP_NORMAL 1 /* used (should always have lp_len>0) */
39 #define LP_REDIRECT 2 /* HOT redirect (should have lp_len=0) */
40 #define LP_DEAD 3 /* dead, may or may not have storage */
43 * Item offsets and lengths are represented by these types when
44 * they're not actually stored in an ItemIdData.
46 typedef uint16 ItemOffset
;
47 typedef uint16 ItemLength
;
58 #define ItemIdGetLength(itemId) \
64 #define ItemIdGetOffset(itemId) \
70 #define ItemIdGetFlags(itemId) \
75 * In a REDIRECT pointer, lp_off holds the link to the next item pointer
77 #define ItemIdGetRedirect(itemId) \
82 * True iff item identifier is valid.
83 * This is a pretty weak test, probably useful only in Asserts.
85 #define ItemIdIsValid(itemId) PointerIsValid(itemId)
89 * True iff item identifier is in use.
91 #define ItemIdIsUsed(itemId) \
92 ((itemId)->lp_flags != LP_UNUSED)
96 * True iff item identifier is in state NORMAL.
98 #define ItemIdIsNormal(itemId) \
99 ((itemId)->lp_flags == LP_NORMAL)
103 * True iff item identifier is in state REDIRECT.
105 #define ItemIdIsRedirected(itemId) \
106 ((itemId)->lp_flags == LP_REDIRECT)
110 * True iff item identifier is in state DEAD.
112 #define ItemIdIsDead(itemId) \
113 ((itemId)->lp_flags == LP_DEAD)
117 * True iff item identifier has associated storage.
119 #define ItemIdHasStorage(itemId) \
120 ((itemId)->lp_len != 0)
124 * Set the item identifier to be UNUSED, with no storage.
125 * Beware of multiple evaluations of itemId!
127 #define ItemIdSetUnused(itemId) \
129 (itemId)->lp_flags = LP_UNUSED, \
130 (itemId)->lp_off = 0, \
131 (itemId)->lp_len = 0 \
136 * Set the item identifier to be NORMAL, with the specified storage.
137 * Beware of multiple evaluations of itemId!
139 #define ItemIdSetNormal(itemId, off, len) \
141 (itemId)->lp_flags = LP_NORMAL, \
142 (itemId)->lp_off = (off), \
143 (itemId)->lp_len = (len) \
148 * Set the item identifier to be REDIRECT, with the specified link.
149 * Beware of multiple evaluations of itemId!
151 #define ItemIdSetRedirect(itemId, link) \
153 (itemId)->lp_flags = LP_REDIRECT, \
154 (itemId)->lp_off = (link), \
155 (itemId)->lp_len = 0 \
160 * Set the item identifier to be DEAD, with no storage.
161 * Beware of multiple evaluations of itemId!
163 #define ItemIdSetDead(itemId) \
165 (itemId)->lp_flags = LP_DEAD, \
166 (itemId)->lp_off = 0, \
167 (itemId)->lp_len = 0 \
172 * Set the item identifier to be DEAD, keeping its existing storage.
174 * Note: in indexes, this is used as if it were a hint-bit mechanism;
175 * we trust that multiple processors can do this in parallel and get
178 #define ItemIdMarkDead(itemId) \
180 (itemId)->lp_flags = LP_DEAD \
183 #endif /* ITEMID_H */