diff options
Diffstat (limited to 'src/backend/storage/page/itemptr.c')
-rw-r--r-- | src/backend/storage/page/itemptr.c | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/src/backend/storage/page/itemptr.c b/src/backend/storage/page/itemptr.c index 1fcd6cb0acc..08f2273ab91 100644 --- a/src/backend/storage/page/itemptr.c +++ b/src/backend/storage/page/itemptr.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/storage/page/itemptr.c,v 1.17 2006/07/14 14:52:23 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/storage/page/itemptr.c,v 1.18 2006/08/25 04:06:53 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -16,13 +16,14 @@ #include "storage/itemptr.h" + /* * ItemPointerEquals * Returns true if both item pointers point to the same item, * otherwise returns false. * * Note: - * Assumes that the disk item pointers are not NULL. + * Asserts that the disk item pointers are both valid! */ bool ItemPointerEquals(ItemPointer pointer1, ItemPointer pointer2) @@ -35,3 +36,30 @@ ItemPointerEquals(ItemPointer pointer1, ItemPointer pointer2) else return false; } + +/* + * ItemPointerCompare + * Generic btree-style comparison for item pointers. + */ +int32 +ItemPointerCompare(ItemPointer arg1, ItemPointer arg2) +{ + /* + * Don't use ItemPointerGetBlockNumber or ItemPointerGetOffsetNumber here, + * because they assert ip_posid != 0 which might not be true for a + * user-supplied TID. + */ + BlockNumber b1 = BlockIdGetBlockNumber(&(arg1->ip_blkid)); + BlockNumber b2 = BlockIdGetBlockNumber(&(arg2->ip_blkid)); + + if (b1 < b2) + return -1; + else if (b1 > b2) + return 1; + else if (arg1->ip_posid < arg2->ip_posid) + return -1; + else if (arg1->ip_posid > arg2->ip_posid) + return 1; + else + return 0; +} |