66 *
77 * Copyright (c) 1994, Regents of the University of California
88 *
9- * $Id: bufpage.h,v 1.26 1999/07/16 17:07:37 momjian Exp $
9+ * $Id: bufpage.h,v 1.27 2000/01/08 21:59:55 tgl Exp $
1010 *
1111 *-------------------------------------------------------------------------
1212 */
2828 * disk page is always a slotted page of the form:
2929 *
3030 * +----------------+---------------------------------+
31- * | PageHeaderData |linp0 linp1 linp2 ... |
31+ * | PageHeaderData | linp1 linp2 linp3 ... |
3232 * +-----------+----+---------------------------------+
3333 * | ... linpN | |
3434 * +-----------+--------------------------------------+
3838 * +-------------+------------------------------------+
3939 * | | tupleN ... |
4040 * +-------------+------------------+-----------------+
41- * | ... tuple2 tuple1 tuple0 | "special space" |
41+ * | ...tuple3 tuple2 tuple1 | "special space" |
4242 * +--------------------------------+-----------------+
4343 *^ pd_special
4444 *
5858 *
5959 * NOTES:
6060 *
61- * linp0..N form an ItemId array. ItemPointers point into this array
62- * rather than pointing directly to a tuple.
61+ * linp1..N form an ItemId array. ItemPointers point into this array
62+ * rather than pointing directly to a tuple. Note that OffsetNumbers
63+ * conventionally start at 1, not 0.
6364 *
64- *tuple0 ..N are added "backwards" on the page. because a tuple's
65+ *tuple1 ..N are added "backwards" on the page. because a tuple's
6566 * ItemPointer points to its ItemId entry rather than its actual
6667 * byte-offset position, tuples can be physically shuffled on a page
6768 * whenever the need arises.
6869 *
6970 * AM-generic per-page information is kept in the pd_opaque field of
70- * the PageHeaderData.(this is currently only the page size.)
71- * AM-specific per-page data is kept in the area marked "special
71+ * the PageHeaderData.(Currently, only the page size is kept here.)
72+ *
73+ * AM-specific per-page data (if any) is kept in the area marked "special
7274 * space"; each AM has an "opaque" structure defined somewhere that is
7375 * stored as the page trailer.an access method should always
7476 * initialize its pages with PageInit and then set its own opaque
8587/*
8688 * location (byte offset) within a page.
8789 *
88- * note that this is actually limited to 2^13 because we have limited
89- * ItemIdData.lp_off and ItemIdData.lp_len to 13 bits (see itemid.h).
90- *
91- * uint16 is still valid, but the limit has been raised to 15 bits.
92- * 06 Jan 98 - darrenk
90+ * note that this is actually limited to 2^15 because we have limited
91+ * ItemIdData.lp_off and ItemIdData.lp_len to 15 bits (see itemid.h).
9392 */
9493typedef uint16 LocationIndex ;
9594
@@ -98,13 +97,11 @@ typedef uint16 LocationIndex;
9897 * space management information generic to any page
9998 *
10099 *od_pagesize- size in bytes.
101- *in reality, we need at least 64B to fit the
100+ *Minimum possible page size is perhaps 64B to fit
102101 * page header, opaque space and a minimal tuple;
103- * on the high end, we can only support pages up
104- * to 8KB because lp_off/lp_len are 13 bits.
105- *
106- * see above comment. Now use 15 bits and pages
107- * up to 32KB at your own risk.
102+ * of course, in reality you want it much bigger.
103+ * On the high end, we can only support pages up
104+ * to 32KB because lp_off/lp_len are 15 bits.
108105 */
109106typedef struct OpaqueData
110107{
@@ -123,7 +120,7 @@ typedef struct PageHeaderData
123120LocationIndex pd_upper ;/* offset to end of free space */
124121LocationIndex pd_special ;/* offset to start of special space */
125122OpaqueData pd_opaque ;/* AM-generic information */
126- ItemIdData pd_linp [1 ];/* linepointers */
123+ ItemIdData pd_linp [1 ];/*beginning of linepointer array */
127124}PageHeaderData ;
128125
129126typedef PageHeaderData * PageHeader ;
@@ -160,8 +157,8 @@ typedef enum
160157 *returns true iff no itemid has been allocated on the page
161158 */
162159#define PageIsEmpty (page ) \
163- (((PageHeader) (page))->pd_lower= = \
164- (sizeof(PageHeaderData) - sizeof(ItemIdData)) ? true : false )
160+ (((PageHeader) (page))->pd_lower< = \
161+ (sizeof(PageHeaderData) - sizeof(ItemIdData)))
165162
166163/*
167164 * PageIsNew
@@ -175,7 +172,7 @@ typedef enum
175172 *Returns an item identifier of a page.
176173 */
177174#define PageGetItemId (page ,offsetNumber ) \
178- ((ItemId) (&((PageHeader) (page))->pd_linp[(-1) + (offsetNumber) ]))
175+ ((ItemId) (&((PageHeader) (page))->pd_linp[(offsetNumber) - 1 ]))
179176
180177/* ----------------
181178 *macros to access opaque space
@@ -210,7 +207,7 @@ typedef enum
210207 *Sets the page size of a page.
211208 */
212209#define PageSetPageSize (page ,size ) \
213- ((PageHeader) (page))->pd_opaque.od_pagesize = (size)
210+ ((( PageHeader) (page))->pd_opaque.od_pagesize = (size) )
214211
215212/* ----------------
216213 *page special data macros
@@ -244,7 +241,7 @@ typedef enum
244241 *Retrieves an item on the given page.
245242 *
246243 * Note:
247- *This does change the status of any of the resources passed.
244+ *This doesnot change the status of any of the resources passed.
248245 *The semantics may change in the future.
249246 */
250247#define PageGetItem (page ,itemId ) \
@@ -264,7 +261,7 @@ typedef enum
264261 *The buffer can be a raw disk block and need not contain a valid
265262 *(formatted) disk page.
266263 */
267- /* XXX dig out of buffer descriptor */
264+ /* XXXshould dig out of buffer descriptor */
268265#define BufferGetPageSize (buffer ) \
269266( \
270267AssertMacro(BufferIsValid(buffer)), \
@@ -280,17 +277,17 @@ typedef enum
280277/*
281278 * PageGetMaxOffsetNumber
282279 *Returns the maximum offset number used by the given page.
280+ *Since offset numbers are 1-based, this is also the number
281+ *of items on the page.
283282 *
284- *NOTE:The offset is invalid if the page isnon-empty.
285- *Test whether PageIsEmpty before calling this routine
286- *and/ orusing its return value .
283+ *NOTE:to ensure sane behavior if the page isnot initialized
284+ *(pd_lower == 0), cast the unsigned values to int before dividing.
285+ *That way we get -1 orso, not a huge positive number.. .
287286 */
288287#define PageGetMaxOffsetNumber (page ) \
289- ( \
290- (((PageHeader) (page))->pd_lower - \
291- (sizeof(PageHeaderData) - sizeof(ItemIdData))) \
292- / sizeof(ItemIdData) \
293- )
288+ (((int) (((PageHeader) (page))->pd_lower - \
289+ (sizeof(PageHeaderData) - sizeof(ItemIdData)))) \
290+ / ((int) sizeof(ItemIdData)))
294291
295292
296293/* ----------------------------------------------------------------