1996-08-28 03:59:28 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* bufpage.h--
|
1997-09-07 07:04:48 +02:00
|
|
|
* Standard POSTGRES buffer page definitions.
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
1998-01-13 15:56:15 +01:00
|
|
|
* $Id: bufpage.h,v 1.15 1998/01/13 14:56:15 vadim Exp $
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
#ifndef BUFPAGE_H
|
1996-08-28 03:59:28 +02:00
|
|
|
#define BUFPAGE_H
|
|
|
|
|
1996-11-05 07:11:08 +01:00
|
|
|
#include <storage/off.h>
|
|
|
|
#include <storage/itemid.h>
|
|
|
|
#include <storage/item.h>
|
|
|
|
#include <storage/buf.h>
|
|
|
|
#include <storage/page.h>
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* a postgres disk page is an abstraction layered on top of a postgres
|
|
|
|
* disk block (which is simply a unit of i/o, see block.h).
|
|
|
|
*
|
|
|
|
* specifically, while a disk block can be unformatted, a postgres
|
|
|
|
* disk page is always a slotted page of the form:
|
|
|
|
*
|
|
|
|
* +----------------+---------------------------------+
|
1997-09-07 07:04:48 +02:00
|
|
|
* | PageHeaderData | linp0 linp1 linp2 ... |
|
1996-08-28 03:59:28 +02:00
|
|
|
* +-----------+----+---------------------------------+
|
1997-09-07 07:04:48 +02:00
|
|
|
* | ... linpN | |
|
1996-08-28 03:59:28 +02:00
|
|
|
* +-----------+--------------------------------------+
|
1997-09-07 07:04:48 +02:00
|
|
|
* | ^ pd_lower |
|
|
|
|
* | |
|
|
|
|
* | v pd_upper |
|
1996-08-28 03:59:28 +02:00
|
|
|
* +-------------+------------------------------------+
|
1997-09-07 07:04:48 +02:00
|
|
|
* | | tupleN ... |
|
1996-08-28 03:59:28 +02:00
|
|
|
* +-------------+------------------+-----------------+
|
1997-09-07 07:04:48 +02:00
|
|
|
* | ... tuple2 tuple1 tuple0 | "special space" |
|
1996-08-28 03:59:28 +02:00
|
|
|
* +--------------------------------+-----------------+
|
1997-09-07 07:04:48 +02:00
|
|
|
* ^ pd_special
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
|
|
|
* a page is full when nothing can be added between pd_lower and
|
|
|
|
* pd_upper.
|
|
|
|
*
|
|
|
|
* all blocks written out by an access method must be disk pages.
|
|
|
|
*
|
|
|
|
* EXCEPTIONS:
|
|
|
|
*
|
|
|
|
* obviously, a page is not formatted before it is initialized with by
|
|
|
|
* a call to PageInit.
|
|
|
|
*
|
|
|
|
* the contents of the special pg_variable/pg_time/pg_log tables are
|
|
|
|
* raw disk blocks with special formats. these are the only "access
|
|
|
|
* methods" that need not write disk pages.
|
|
|
|
*
|
|
|
|
* NOTES:
|
|
|
|
*
|
|
|
|
* linp0..N form an ItemId array. ItemPointers point into this array
|
|
|
|
* rather than pointing directly to a tuple.
|
|
|
|
*
|
|
|
|
* tuple0..N are added "backwards" on the page. because a tuple's
|
|
|
|
* ItemPointer points to its ItemId entry rather than its actual
|
|
|
|
* byte-offset position, tuples can be physically shuffled on a page
|
|
|
|
* whenever the need arises.
|
|
|
|
*
|
|
|
|
* AM-generic per-page information is kept in the pd_opaque field of
|
1997-09-07 07:04:48 +02:00
|
|
|
* the PageHeaderData. (this is currently only the page size.)
|
1996-08-28 03:59:28 +02:00
|
|
|
* AM-specific per-page data is kept in the area marked "special
|
|
|
|
* space"; each AM has an "opaque" structure defined somewhere that is
|
1997-09-07 07:04:48 +02:00
|
|
|
* stored as the page trailer. an access method should always
|
1996-08-28 03:59:28 +02:00
|
|
|
* initialize its pages with PageInit and then set its own opaque
|
|
|
|
* fields.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* PageIsValid --
|
1997-09-07 07:04:48 +02:00
|
|
|
* True iff page is valid.
|
1996-08-28 03:59:28 +02:00
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
#define PageIsValid(page) PointerIsValid(page)
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* location (byte offset) within a page.
|
|
|
|
*
|
|
|
|
* note that this is actually limited to 2^13 because we have limited
|
|
|
|
* ItemIdData.lp_off and ItemIdData.lp_len to 13 bits (see itemid.h).
|
1998-01-13 05:05:12 +01:00
|
|
|
*
|
|
|
|
* uint16 is still valid, but the limit has been raised to 15 bits.
|
|
|
|
* 06 Jan 98 - darrenk
|
1996-08-28 03:59:28 +02:00
|
|
|
*/
|
1997-09-08 04:41:22 +02:00
|
|
|
typedef uint16 LocationIndex;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* space management information generic to any page
|
|
|
|
*
|
1997-09-07 07:04:48 +02:00
|
|
|
* od_pagesize - size in bytes.
|
|
|
|
* in reality, we need at least 64B to fit the
|
|
|
|
* page header, opaque space and a minimal tuple;
|
|
|
|
* on the high end, we can only support pages up
|
|
|
|
* to 8KB because lp_off/lp_len are 13 bits.
|
1998-01-13 05:05:12 +01:00
|
|
|
*
|
|
|
|
* see above comment. Now use 15 bits and pages
|
|
|
|
* up to 32KB at your own risk.
|
1996-08-28 03:59:28 +02:00
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct OpaqueData
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
uint16 od_pagesize;
|
1997-09-08 23:56:23 +02:00
|
|
|
} OpaqueData;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
typedef OpaqueData *Opaque;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* disk page organization
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct PageHeaderData
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
LocationIndex pd_lower; /* offset to start of free space */
|
|
|
|
LocationIndex pd_upper; /* offset to end of free space */
|
|
|
|
LocationIndex pd_special; /* offset to start of special space */
|
|
|
|
OpaqueData pd_opaque; /* AM-generic information */
|
|
|
|
ItemIdData pd_linp[1]; /* line pointers */
|
1997-09-08 23:56:23 +02:00
|
|
|
} PageHeaderData;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
typedef PageHeaderData *PageHeader;
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
ShufflePageManagerMode,
|
|
|
|
OverwritePageManagerMode
|
1997-09-08 23:56:23 +02:00
|
|
|
} PageManagerMode;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/* ----------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* misc support macros
|
1996-08-28 03:59:28 +02:00
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX this is wrong -- ignores padding/alignment, variable page size,
|
|
|
|
* AM-specific opaque space at the end of the page (as in btrees), ...
|
|
|
|
* however, it at least serves as an upper bound for heap pages.
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
#define MAXTUPLEN (BLCKSZ - sizeof (PageHeaderData))
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/* ----------------------------------------------------------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* page support macros
|
1996-08-28 03:59:28 +02:00
|
|
|
* ----------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* PageIsValid -- This is defined in page.h.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* PageIsUsed --
|
1997-09-07 07:04:48 +02:00
|
|
|
* True iff the page size is used.
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
|
|
|
* Note:
|
1997-09-07 07:04:48 +02:00
|
|
|
* Assumes page is valid.
|
1996-08-28 03:59:28 +02:00
|
|
|
*/
|
|
|
|
#define PageIsUsed(page) \
|
1997-09-07 07:04:48 +02:00
|
|
|
(AssertMacro(PageIsValid(page)) ? \
|
|
|
|
((bool) (((PageHeader) (page))->pd_lower != 0)) : false)
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* PageIsEmpty --
|
1997-09-07 07:04:48 +02:00
|
|
|
* returns true iff no itemid has been allocated on the page
|
1996-08-28 03:59:28 +02:00
|
|
|
*/
|
|
|
|
#define PageIsEmpty(page) \
|
1997-09-07 07:04:48 +02:00
|
|
|
(((PageHeader) (page))->pd_lower == \
|
|
|
|
(sizeof(PageHeaderData) - sizeof(ItemIdData)) ? true : false)
|
1996-08-28 03:59:28 +02:00
|
|
|
|
1996-10-18 09:39:07 +02:00
|
|
|
/*
|
1997-09-07 07:04:48 +02:00
|
|
|
* PageIsNew --
|
|
|
|
* returns true iff page is not initialized (by PageInit)
|
1996-10-18 09:39:07 +02:00
|
|
|
*/
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
#define PageIsNew(page) (((PageHeader) (page))->pd_upper == 0)
|
1996-10-18 09:39:07 +02:00
|
|
|
|
1996-08-28 03:59:28 +02:00
|
|
|
/*
|
|
|
|
* PageGetItemId --
|
1997-09-07 07:04:48 +02:00
|
|
|
* Returns an item identifier of a page.
|
1996-08-28 03:59:28 +02:00
|
|
|
*/
|
|
|
|
#define PageGetItemId(page, offsetNumber) \
|
1997-09-07 07:04:48 +02:00
|
|
|
((ItemId) (&((PageHeader) (page))->pd_linp[(-1) + (offsetNumber)]))
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/* ----------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* macros to access opaque space
|
1996-08-28 03:59:28 +02:00
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* PageSizeIsValid --
|
1997-09-07 07:04:48 +02:00
|
|
|
* True iff the page size is valid.
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
|
|
|
* XXX currently all page sizes are "valid" but we only actually
|
1997-09-07 07:04:48 +02:00
|
|
|
* use BLCKSZ.
|
1998-01-13 05:05:12 +01:00
|
|
|
*
|
|
|
|
* 01/06/98 Now does something useful. darrenk
|
|
|
|
*
|
1996-08-28 03:59:28 +02:00
|
|
|
*/
|
1998-01-13 05:05:12 +01:00
|
|
|
#define PageSizeIsValid(pageSize) ((pageSize) == BLCKSZ)
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* PageGetPageSize --
|
1997-09-07 07:04:48 +02:00
|
|
|
* Returns the page size of a page.
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
|
|
|
* this can only be called on a formatted page (unlike
|
|
|
|
* BufferGetPageSize, which can be called on an unformatted page).
|
|
|
|
* however, it can be called on a page for which there is no buffer.
|
|
|
|
*/
|
|
|
|
#define PageGetPageSize(page) \
|
1997-09-07 07:04:48 +02:00
|
|
|
((Size) ((PageHeader) (page))->pd_opaque.od_pagesize)
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* PageSetPageSize --
|
1997-09-07 07:04:48 +02:00
|
|
|
* Sets the page size of a page.
|
1996-08-28 03:59:28 +02:00
|
|
|
*/
|
|
|
|
#define PageSetPageSize(page, size) \
|
1997-09-07 07:04:48 +02:00
|
|
|
((PageHeader) (page))->pd_opaque.od_pagesize = (size)
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/* ----------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* page special data macros
|
1996-08-28 03:59:28 +02:00
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* PageGetSpecialSize --
|
1997-09-07 07:04:48 +02:00
|
|
|
* Returns size of special space on a page.
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
|
|
|
* Note:
|
1997-09-07 07:04:48 +02:00
|
|
|
* Assumes page is locked.
|
1996-08-28 03:59:28 +02:00
|
|
|
*/
|
|
|
|
#define PageGetSpecialSize(page) \
|
1997-09-07 07:04:48 +02:00
|
|
|
((uint16) (PageGetPageSize(page) - ((PageHeader)(page))->pd_special))
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* PageGetSpecialPointer --
|
1997-09-07 07:04:48 +02:00
|
|
|
* Returns pointer to special space on a page.
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
|
|
|
* Note:
|
1997-09-07 07:04:48 +02:00
|
|
|
* Assumes page is locked.
|
1996-08-28 03:59:28 +02:00
|
|
|
*/
|
|
|
|
#define PageGetSpecialPointer(page) \
|
1997-09-07 07:04:48 +02:00
|
|
|
(AssertMacro(PageIsValid(page)) ? \
|
|
|
|
(char *) ((char *) (page) + ((PageHeader) (page))->pd_special) \
|
|
|
|
: (char *)0 )
|
1996-08-28 03:59:28 +02:00
|
|
|
|
1997-08-25 01:08:01 +02:00
|
|
|
/*
|
|
|
|
* PageGetItem --
|
1997-09-07 07:04:48 +02:00
|
|
|
* Retrieves an item on the given page.
|
1997-08-25 01:08:01 +02:00
|
|
|
*
|
|
|
|
* Note:
|
1997-09-07 07:04:48 +02:00
|
|
|
* This does change the status of any of the resources passed.
|
|
|
|
* The semantics may change in the future.
|
1997-08-25 01:08:01 +02:00
|
|
|
*/
|
|
|
|
#define PageGetItem(page, itemId) \
|
1997-09-07 07:04:48 +02:00
|
|
|
(AssertMacro(PageIsValid(page)) ? \
|
|
|
|
AssertMacro((itemId)->lp_flags & LP_USED) ? \
|
|
|
|
(Item)(((char *)(page)) + (itemId)->lp_off) : false : false)
|
1997-08-25 01:08:01 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* BufferGetPageSize --
|
1997-09-07 07:04:48 +02:00
|
|
|
* Returns the page size within a buffer.
|
1997-08-25 01:08:01 +02:00
|
|
|
*
|
|
|
|
* Notes:
|
1997-09-07 07:04:48 +02:00
|
|
|
* Assumes buffer is valid.
|
1997-08-25 01:08:01 +02:00
|
|
|
*
|
1997-09-07 07:04:48 +02:00
|
|
|
* The buffer can be a raw disk block and need not contain a valid
|
|
|
|
* (formatted) disk page.
|
1997-08-25 01:08:01 +02:00
|
|
|
*/
|
|
|
|
/* XXX dig out of buffer descriptor */
|
|
|
|
#define BufferGetPageSize(buffer) \
|
1998-01-13 15:56:15 +01:00
|
|
|
(AssertMacro(BufferIsValid(buffer)) ? (Size)BLCKSZ : false)
|
1997-08-25 01:08:01 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* BufferGetPage --
|
1997-09-07 07:04:48 +02:00
|
|
|
* Returns the page associated with a buffer.
|
1997-08-25 01:08:01 +02:00
|
|
|
*/
|
|
|
|
#define BufferGetPage(buffer) ((Page)BufferGetBlock(buffer))
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1996-08-28 03:59:28 +02:00
|
|
|
/* ----------------------------------------------------------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* extern declarations
|
1996-08-28 03:59:28 +02:00
|
|
|
* ----------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
extern void PageInit(Page page, Size pageSize, Size specialSize);
|
1997-09-08 23:56:23 +02:00
|
|
|
extern OffsetNumber
|
1997-09-07 07:04:48 +02:00
|
|
|
PageAddItem(Page page, Item item, Size size,
|
|
|
|
OffsetNumber offsetNumber, ItemIdFlags flags);
|
1997-09-08 04:41:22 +02:00
|
|
|
extern Page PageGetTempPage(Page page, Size specialSize);
|
|
|
|
extern void PageRestoreTempPage(Page tempPage, Page oldPage);
|
1996-08-28 03:59:28 +02:00
|
|
|
extern OffsetNumber PageGetMaxOffsetNumber(Page page);
|
1997-09-08 04:41:22 +02:00
|
|
|
extern void PageRepairFragmentation(Page page);
|
|
|
|
extern Size PageGetFreeSpace(Page page);
|
|
|
|
extern void PageManagerModeSet(PageManagerMode mode);
|
|
|
|
extern void PageIndexTupleDelete(Page page, OffsetNumber offset);
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
#endif /* BUFPAGE_H */
|