PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
itemptr.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * itemptr.h
4  * POSTGRES disk item pointer definitions.
5  *
6  *
7  * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * src/include/storage/itemptr.h
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef ITEMPTR_H
15 #define ITEMPTR_H
16 
17 #include "storage/block.h"
18 #include "storage/off.h"
19 
20 /*
21  * ItemPointer:
22  *
23  * This is a pointer to an item within a disk page of a known file
24  * (for example, a cross-link from an index to its parent table).
25  * blkid tells us which block, posid tells us which entry in the linp
26  * (ItemIdData) array we want.
27  *
28  * Note: because there is an item pointer in each tuple header and index
29  * tuple header on disk, it's very important not to waste space with
30  * structure padding bytes. The struct is designed to be six bytes long
31  * (it contains three int16 fields) but a few compilers will pad it to
32  * eight bytes unless coerced. We apply appropriate persuasion where
33  * possible. If your compiler can't be made to play along, you'll waste
34  * lots of space.
35  */
36 typedef struct ItemPointerData
37 {
40 }
41 /* If compiler understands packed and aligned pragmas, use those */
42 #if defined(pg_attribute_packed) && defined(pg_attribute_aligned)
43 pg_attribute_packed()
44 pg_attribute_aligned(2)
45 #endif
47 
48 typedef ItemPointerData *ItemPointer;
49 
50 /* ----------------
51  * support macros
52  * ----------------
53  */
54 
55 /*
56  * ItemPointerIsValid
57  * True iff the disk item pointer is not NULL.
58  */
59 #define ItemPointerIsValid(pointer) \
60  ((bool) (PointerIsValid(pointer) && ((pointer)->ip_posid != 0)))
61 
62 /*
63  * ItemPointerGetBlockNumber
64  * Returns the block number of a disk item pointer.
65  */
66 #define ItemPointerGetBlockNumber(pointer) \
67 ( \
68  AssertMacro(ItemPointerIsValid(pointer)), \
69  BlockIdGetBlockNumber(&(pointer)->ip_blkid) \
70 )
71 
72 /*
73  * ItemPointerGetOffsetNumber
74  * Returns the offset number of a disk item pointer.
75  */
76 #define ItemPointerGetOffsetNumber(pointer) \
77 ( \
78  AssertMacro(ItemPointerIsValid(pointer)), \
79  (pointer)->ip_posid \
80 )
81 
82 /*
83  * ItemPointerSet
84  * Sets a disk item pointer to the specified block and offset.
85  */
86 #define ItemPointerSet(pointer, blockNumber, offNum) \
87 ( \
88  AssertMacro(PointerIsValid(pointer)), \
89  BlockIdSet(&((pointer)->ip_blkid), blockNumber), \
90  (pointer)->ip_posid = offNum \
91 )
92 
93 /*
94  * ItemPointerSetBlockNumber
95  * Sets a disk item pointer to the specified block.
96  */
97 #define ItemPointerSetBlockNumber(pointer, blockNumber) \
98 ( \
99  AssertMacro(PointerIsValid(pointer)), \
100  BlockIdSet(&((pointer)->ip_blkid), blockNumber) \
101 )
102 
103 /*
104  * ItemPointerSetOffsetNumber
105  * Sets a disk item pointer to the specified offset.
106  */
107 #define ItemPointerSetOffsetNumber(pointer, offsetNumber) \
108 ( \
109  AssertMacro(PointerIsValid(pointer)), \
110  (pointer)->ip_posid = (offsetNumber) \
111 )
112 
113 /*
114  * ItemPointerCopy
115  * Copies the contents of one disk item pointer to another.
116  *
117  * Should there ever be padding in an ItemPointer this would need to be handled
118  * differently as it's used as hash key.
119  */
120 #define ItemPointerCopy(fromPointer, toPointer) \
121 ( \
122  AssertMacro(PointerIsValid(toPointer)), \
123  AssertMacro(PointerIsValid(fromPointer)), \
124  *(toPointer) = *(fromPointer) \
125 )
126 
127 /*
128  * ItemPointerSetInvalid
129  * Sets a disk item pointer to be invalid.
130  */
131 #define ItemPointerSetInvalid(pointer) \
132 ( \
133  AssertMacro(PointerIsValid(pointer)), \
134  BlockIdSet(&((pointer)->ip_blkid), InvalidBlockNumber), \
135  (pointer)->ip_posid = InvalidOffsetNumber \
136 )
137 
138 /* ----------------
139  * externs
140  * ----------------
141  */
142 
143 extern bool ItemPointerEquals(ItemPointer pointer1, ItemPointer pointer2);
144 extern int32 ItemPointerCompare(ItemPointer arg1, ItemPointer arg2);
145 
146 #endif /* ITEMPTR_H */
int32 ItemPointerCompare(ItemPointer arg1, ItemPointer arg2)
Definition: itemptr.c:52
signed int int32
Definition: c.h:256
uint16 OffsetNumber
Definition: off.h:24
ItemPointerData * ItemPointer
Definition: itemptr.h:48
BlockIdData ip_blkid
Definition: itemptr.h:38
bool ItemPointerEquals(ItemPointer pointer1, ItemPointer pointer2)
Definition: itemptr.c:29
struct ItemPointerData ItemPointerData
OffsetNumber ip_posid
Definition: itemptr.h:39