LCOV - code coverage report
Current view: top level - src/backend/storage/page - itemptr.c (source / functions) Hit Total Coverage
Test: PostgreSQL 13beta1 Lines: 21 21 100.0 %
Date: 2020-06-05 18:07:03 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*-------------------------------------------------------------------------
       2             :  *
       3             :  * itemptr.c
       4             :  *    POSTGRES disk item pointer code.
       5             :  *
       6             :  * Portions Copyright (c) 1996-2020, 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
      29     1379606 : ItemPointerEquals(ItemPointer pointer1, ItemPointer pointer2)
      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     2759212 :     if (ItemPointerGetBlockNumber(pointer1) ==
      39     1379606 :         ItemPointerGetBlockNumber(pointer2) &&
      40      856046 :         ItemPointerGetOffsetNumber(pointer1) ==
      41      856046 :         ItemPointerGetOffsetNumber(pointer2))
      42      513416 :         return true;
      43             :     else
      44      866190 :         return false;
      45             : }
      46             : 
      47             : /*
      48             :  * ItemPointerCompare
      49             :  *      Generic btree-style comparison for item pointers.
      50             :  */
      51             : int32
      52    34819676 : ItemPointerCompare(ItemPointer arg1, ItemPointer arg2)
      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             :      */
      58    34819676 :     BlockNumber b1 = ItemPointerGetBlockNumberNoCheck(arg1);
      59    34819676 :     BlockNumber b2 = ItemPointerGetBlockNumberNoCheck(arg2);
      60             : 
      61    34819676 :     if (b1 < b2)
      62      173196 :         return -1;
      63    34646480 :     else if (b1 > b2)
      64    17278272 :         return 1;
      65    34736416 :     else if (ItemPointerGetOffsetNumberNoCheck(arg1) <
      66    17368208 :              ItemPointerGetOffsetNumberNoCheck(arg2))
      67      614098 :         return -1;
      68    33508220 :     else if (ItemPointerGetOffsetNumberNoCheck(arg1) >
      69    16754110 :              ItemPointerGetOffsetNumberNoCheck(arg2))
      70    15704542 :         return 1;
      71             :     else
      72     1049568 :         return 0;
      73             : }

Generated by: LCOV version 1.13