Header And Logo

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

itemptr.c

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * itemptr.c
00004  *    POSTGRES disk item pointer code.
00005  *
00006  * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
00007  * Portions Copyright (c) 1994, Regents of the University of California
00008  *
00009  *
00010  * IDENTIFICATION
00011  *    src/backend/storage/page/itemptr.c
00012  *
00013  *-------------------------------------------------------------------------
00014  */
00015 #include "postgres.h"
00016 
00017 #include "storage/itemptr.h"
00018 
00019 
00020 /*
00021  * ItemPointerEquals
00022  *  Returns true if both item pointers point to the same item,
00023  *   otherwise returns false.
00024  *
00025  * Note:
00026  *  Asserts that the disk item pointers are both valid!
00027  */
00028 bool
00029 ItemPointerEquals(ItemPointer pointer1, ItemPointer pointer2)
00030 {
00031     if (ItemPointerGetBlockNumber(pointer1) ==
00032         ItemPointerGetBlockNumber(pointer2) &&
00033         ItemPointerGetOffsetNumber(pointer1) ==
00034         ItemPointerGetOffsetNumber(pointer2))
00035         return true;
00036     else
00037         return false;
00038 }
00039 
00040 /*
00041  * ItemPointerCompare
00042  *      Generic btree-style comparison for item pointers.
00043  */
00044 int32
00045 ItemPointerCompare(ItemPointer arg1, ItemPointer arg2)
00046 {
00047     /*
00048      * Don't use ItemPointerGetBlockNumber or ItemPointerGetOffsetNumber here,
00049      * because they assert ip_posid != 0 which might not be true for a
00050      * user-supplied TID.
00051      */
00052     BlockNumber b1 = BlockIdGetBlockNumber(&(arg1->ip_blkid));
00053     BlockNumber b2 = BlockIdGetBlockNumber(&(arg2->ip_blkid));
00054 
00055     if (b1 < b2)
00056         return -1;
00057     else if (b1 > b2)
00058         return 1;
00059     else if (arg1->ip_posid < arg2->ip_posid)
00060         return -1;
00061     else if (arg1->ip_posid > arg2->ip_posid)
00062         return 1;
00063     else
00064         return 0;
00065 }