Header And Logo

PostgreSQL
| The world's most advanced open source database.

itemptr.h

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * itemptr.h
00004  *    POSTGRES disk item pointer definitions.
00005  *
00006  *
00007  * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
00008  * Portions Copyright (c) 1994, Regents of the University of California
00009  *
00010  * src/include/storage/itemptr.h
00011  *
00012  *-------------------------------------------------------------------------
00013  */
00014 #ifndef ITEMPTR_H
00015 #define ITEMPTR_H
00016 
00017 #include "storage/block.h"
00018 #include "storage/off.h"
00019 
00020 /*
00021  * ItemPointer:
00022  *
00023  * This is a pointer to an item within a disk page of a known file
00024  * (for example, a cross-link from an index to its parent table).
00025  * blkid tells us which block, posid tells us which entry in the linp
00026  * (ItemIdData) array we want.
00027  *
00028  * Note: because there is an item pointer in each tuple header and index
00029  * tuple header on disk, it's very important not to waste space with
00030  * structure padding bytes.  The struct is designed to be six bytes long
00031  * (it contains three int16 fields) but a few compilers will pad it to
00032  * eight bytes unless coerced.  We apply appropriate persuasion where
00033  * possible, and to cope with unpersuadable compilers, we try to use
00034  * "SizeOfIptrData" rather than "sizeof(ItemPointerData)" when computing
00035  * on-disk sizes.
00036  */
00037 typedef struct ItemPointerData
00038 {
00039     BlockIdData ip_blkid;
00040     OffsetNumber ip_posid;
00041 }
00042 
00043 #ifdef __arm__
00044 __attribute__((packed))         /* Appropriate whack upside the head for ARM */
00045 #endif
00046 ItemPointerData;
00047 
00048 #define SizeOfIptrData  \
00049     (offsetof(ItemPointerData, ip_posid) + sizeof(OffsetNumber))
00050 
00051 typedef ItemPointerData *ItemPointer;
00052 
00053 /* ----------------
00054  *      support macros
00055  * ----------------
00056  */
00057 
00058 /*
00059  * ItemPointerIsValid
00060  *      True iff the disk item pointer is not NULL.
00061  */
00062 #define ItemPointerIsValid(pointer) \
00063     ((bool) (PointerIsValid(pointer) && ((pointer)->ip_posid != 0)))
00064 
00065 /*
00066  * ItemPointerGetBlockNumber
00067  *      Returns the block number of a disk item pointer.
00068  */
00069 #define ItemPointerGetBlockNumber(pointer) \
00070 ( \
00071     AssertMacro(ItemPointerIsValid(pointer)), \
00072     BlockIdGetBlockNumber(&(pointer)->ip_blkid) \
00073 )
00074 
00075 /*
00076  * ItemPointerGetOffsetNumber
00077  *      Returns the offset number of a disk item pointer.
00078  */
00079 #define ItemPointerGetOffsetNumber(pointer) \
00080 ( \
00081     AssertMacro(ItemPointerIsValid(pointer)), \
00082     (pointer)->ip_posid \
00083 )
00084 
00085 /*
00086  * ItemPointerSet
00087  *      Sets a disk item pointer to the specified block and offset.
00088  */
00089 #define ItemPointerSet(pointer, blockNumber, offNum) \
00090 ( \
00091     AssertMacro(PointerIsValid(pointer)), \
00092     BlockIdSet(&((pointer)->ip_blkid), blockNumber), \
00093     (pointer)->ip_posid = offNum \
00094 )
00095 
00096 /*
00097  * ItemPointerSetBlockNumber
00098  *      Sets a disk item pointer to the specified block.
00099  */
00100 #define ItemPointerSetBlockNumber(pointer, blockNumber) \
00101 ( \
00102     AssertMacro(PointerIsValid(pointer)), \
00103     BlockIdSet(&((pointer)->ip_blkid), blockNumber) \
00104 )
00105 
00106 /*
00107  * ItemPointerSetOffsetNumber
00108  *      Sets a disk item pointer to the specified offset.
00109  */
00110 #define ItemPointerSetOffsetNumber(pointer, offsetNumber) \
00111 ( \
00112     AssertMacro(PointerIsValid(pointer)), \
00113     (pointer)->ip_posid = (offsetNumber) \
00114 )
00115 
00116 /*
00117  * ItemPointerCopy
00118  *      Copies the contents of one disk item pointer to another.
00119  */
00120 #define ItemPointerCopy(fromPointer, toPointer) \
00121 ( \
00122     AssertMacro(PointerIsValid(toPointer)), \
00123     AssertMacro(PointerIsValid(fromPointer)), \
00124     *(toPointer) = *(fromPointer) \
00125 )
00126 
00127 /*
00128  * ItemPointerSetInvalid
00129  *      Sets a disk item pointer to be invalid.
00130  */
00131 #define ItemPointerSetInvalid(pointer) \
00132 ( \
00133     AssertMacro(PointerIsValid(pointer)), \
00134     BlockIdSet(&((pointer)->ip_blkid), InvalidBlockNumber), \
00135     (pointer)->ip_posid = InvalidOffsetNumber \
00136 )
00137 
00138 /* ----------------
00139  *      externs
00140  * ----------------
00141  */
00142 
00143 extern bool ItemPointerEquals(ItemPointer pointer1, ItemPointer pointer2);
00144 extern int32 ItemPointerCompare(ItemPointer arg1, ItemPointer arg2);
00145 
00146 #endif   /* ITEMPTR_H */