PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
itemptr.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * itemptr.c
4  * POSTGRES disk item pointer code.
5  *
6  * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  *
10  * IDENTIFICATION
11  * src/backend/storage/page/itemptr.c
12  *
13  *-------------------------------------------------------------------------
14  */
15 #include "postgres.h"
16 
17 #include "storage/itemptr.h"
18 
19 
20 /*
21  * ItemPointerEquals
22  * Returns true if both item pointers point to the same item,
23  * otherwise returns false.
24  *
25  * Note:
26  * Asserts that the disk item pointers are both valid!
27  */
28 bool
30 {
31  /*
32  * We really want ItemPointerData to be exactly 6 bytes. This is rather a
33  * random place to check, but there is no better place.
34  */
35  StaticAssertStmt(sizeof(ItemPointerData) == 3 * sizeof(uint16),
36  "ItemPointerData struct is improperly padded");
37 
38  if (ItemPointerGetBlockNumber(pointer1) ==
39  ItemPointerGetBlockNumber(pointer2) &&
40  ItemPointerGetOffsetNumber(pointer1) ==
42  return true;
43  else
44  return false;
45 }
46 
47 /*
48  * ItemPointerCompare
49  * Generic btree-style comparison for item pointers.
50  */
51 int32
53 {
54  /*
55  * Use ItemPointerGet{Offset,Block}NumberNoCheck to avoid asserting
56  * ip_posid != 0, which may not be true for a user-supplied TID.
57  */
60 
61  if (b1 < b2)
62  return -1;
63  else if (b1 > b2)
64  return 1;
65  else if (ItemPointerGetOffsetNumberNoCheck(arg1) <
67  return -1;
68  else if (ItemPointerGetOffsetNumberNoCheck(arg1) >
70  return 1;
71  else
72  return 0;
73 }
int32 ItemPointerCompare(ItemPointer arg1, ItemPointer arg2)
Definition: itemptr.c:52
#define ItemPointerGetOffsetNumberNoCheck(pointer)
Definition: itemptr.h:86
uint32 BlockNumber
Definition: block.h:31
signed int int32
Definition: c.h:256
#define StaticAssertStmt(condition, errmessage)
Definition: c.h:757
unsigned short uint16
Definition: c.h:267
#define ItemPointerGetOffsetNumber(pointer)
Definition: itemptr.h:95
bool ItemPointerEquals(ItemPointer pointer1, ItemPointer pointer2)
Definition: itemptr.c:29
#define ItemPointerGetBlockNumberNoCheck(pointer)
Definition: itemptr.h:67
#define ItemPointerGetBlockNumber(pointer)
Definition: itemptr.h:76