6
6
*
7
7
* Copyright (c) 1994, Regents of the University of California
8
8
*
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 $
10
10
*
11
11
*-------------------------------------------------------------------------
12
12
*/
28
28
* disk page is always a slotted page of the form:
29
29
*
30
30
* +----------------+---------------------------------+
31
- * | PageHeaderData |linp0 linp1 linp2 ... |
31
+ * | PageHeaderData | linp1 linp2 linp3 ... |
32
32
* +-----------+----+---------------------------------+
33
33
* | ... linpN | |
34
34
* +-----------+--------------------------------------+
38
38
* +-------------+------------------------------------+
39
39
* | | tupleN ... |
40
40
* +-------------+------------------+-----------------+
41
- * | ... tuple2 tuple1 tuple0 | "special space" |
41
+ * | ...tuple3 tuple2 tuple1 | "special space" |
42
42
* +--------------------------------+-----------------+
43
43
*^ pd_special
44
44
*
58
58
*
59
59
* NOTES:
60
60
*
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.
63
64
*
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
65
66
* ItemPointer points to its ItemId entry rather than its actual
66
67
* byte-offset position, tuples can be physically shuffled on a page
67
68
* whenever the need arises.
68
69
*
69
70
* 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
72
74
* space"; each AM has an "opaque" structure defined somewhere that is
73
75
* stored as the page trailer.an access method should always
74
76
* initialize its pages with PageInit and then set its own opaque
85
87
/*
86
88
* location (byte offset) within a page.
87
89
*
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).
93
92
*/
94
93
typedef uint16 LocationIndex ;
95
94
@@ -98,13 +97,11 @@ typedef uint16 LocationIndex;
98
97
* space management information generic to any page
99
98
*
100
99
*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
102
101
* 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.
108
105
*/
109
106
typedef struct OpaqueData
110
107
{
@@ -123,7 +120,7 @@ typedef struct PageHeaderData
123
120
LocationIndex pd_upper ;/* offset to end of free space */
124
121
LocationIndex pd_special ;/* offset to start of special space */
125
122
OpaqueData pd_opaque ;/* AM-generic information */
126
- ItemIdData pd_linp [1 ];/* linepointers */
123
+ ItemIdData pd_linp [1 ];/*beginning of linepointer array */
127
124
}PageHeaderData ;
128
125
129
126
typedef PageHeaderData * PageHeader ;
@@ -160,8 +157,8 @@ typedef enum
160
157
*returns true iff no itemid has been allocated on the page
161
158
*/
162
159
#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)))
165
162
166
163
/*
167
164
* PageIsNew
@@ -175,7 +172,7 @@ typedef enum
175
172
*Returns an item identifier of a page.
176
173
*/
177
174
#define PageGetItemId (page ,offsetNumber ) \
178
- ((ItemId) (&((PageHeader) (page))->pd_linp[(-1) + (offsetNumber) ]))
175
+ ((ItemId) (&((PageHeader) (page))->pd_linp[(offsetNumber) - 1 ]))
179
176
180
177
/* ----------------
181
178
*macros to access opaque space
@@ -210,7 +207,7 @@ typedef enum
210
207
*Sets the page size of a page.
211
208
*/
212
209
#define PageSetPageSize (page ,size ) \
213
- ((PageHeader) (page))->pd_opaque.od_pagesize = (size)
210
+ ((( PageHeader) (page))->pd_opaque.od_pagesize = (size) )
214
211
215
212
/* ----------------
216
213
*page special data macros
@@ -244,7 +241,7 @@ typedef enum
244
241
*Retrieves an item on the given page.
245
242
*
246
243
* 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.
248
245
*The semantics may change in the future.
249
246
*/
250
247
#define PageGetItem (page ,itemId ) \
@@ -264,7 +261,7 @@ typedef enum
264
261
*The buffer can be a raw disk block and need not contain a valid
265
262
*(formatted) disk page.
266
263
*/
267
- /* XXX dig out of buffer descriptor */
264
+ /* XXXshould dig out of buffer descriptor */
268
265
#define BufferGetPageSize (buffer ) \
269
266
( \
270
267
AssertMacro(BufferIsValid(buffer)), \
@@ -280,17 +277,17 @@ typedef enum
280
277
/*
281
278
* PageGetMaxOffsetNumber
282
279
*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.
283
282
*
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.. .
287
286
*/
288
287
#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)))
294
291
295
292
296
293
/* ----------------------------------------------------------------