LCOV - differential code coverage report
Current view: top level - src/include/storage - itemptr.h (source / functions) Coverage Total Hit UBC CBC
Current: 4b3c9325757dfd8f2312e9f1a8decf4431f344ae vs e87b024bfb8dd55e3049b1b6e6ab4e810cf1abc8 Lines: 100.0 % 45 45 45
Current Date: 2026-11-28 16:48:44 +0900 Functions: 100.0 % 14 14 14
Baseline: lcov-20261128-baseline Branches: 62.5 % 24 15 9 15
Baseline Date: 2026-11-28 16:48:48 +0900 Line coverage date bins:
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
(360..) days: 100.0 % 45 45 45
Function coverage date bins:
(360..) days: 100.0 % 14 14 14
Branch coverage date bins:
(360..) days: 62.5 % 24 15 9 15

 Age         Owner                    Branch data    TLA  Line data    Source code
                                  1                 :                : /*-------------------------------------------------------------------------
                                  2                 :                :  *
                                  3                 :                :  * itemptr.h
                                  4                 :                :  *    POSTGRES disk item pointer definitions.
                                  5                 :                :  *
                                  6                 :                :  *
                                  7                 :                :  * Portions Copyright (c) 1996-2026, 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                 :                :  * ip_blkid tells us which block, ip_posid tells us which entry in
                                 26                 :                :  * the linp (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                 :                : {
                                 38                 :                :     BlockIdData ip_blkid;
                                 39                 :                :     OffsetNumber ip_posid;
                                 40                 :                : }
                                 41                 :                : 
                                 42                 :                : /* If compiler understands packed and aligned pragmas, use those */
                                 43                 :                : #if defined(pg_attribute_packed) && defined(pg_attribute_aligned)
                                 44                 :                :             pg_attribute_packed()
                                 45                 :                :             pg_attribute_aligned(2)
                                 46                 :                : #endif
                                 47                 :                : ItemPointerData;
                                 48                 :                : 
                                 49                 :                : typedef ItemPointerData *ItemPointer;
                                 50                 :                : 
                                 51                 :                : /* ----------------
                                 52                 :                :  *      special values used in heap tuples (t_ctid)
                                 53                 :                :  * ----------------
                                 54                 :                :  */
                                 55                 :                : 
                                 56                 :                : /*
                                 57                 :                :  * If a heap tuple holds a speculative insertion token rather than a real
                                 58                 :                :  * TID, ip_posid is set to SpecTokenOffsetNumber, and the token is stored in
                                 59                 :                :  * ip_blkid. SpecTokenOffsetNumber must be higher than MaxOffsetNumber, so
                                 60                 :                :  * that it can be distinguished from a valid offset number in a regular item
                                 61                 :                :  * pointer.
                                 62                 :                :  */
                                 63                 :                : #define SpecTokenOffsetNumber       0xfffe
                                 64                 :                : 
                                 65                 :                : /*
                                 66                 :                :  * When a tuple is moved to a different partition by UPDATE, the t_ctid of
                                 67                 :                :  * the old tuple version is set to this magic value.
                                 68                 :                :  */
                                 69                 :                : #define MovedPartitionsOffsetNumber 0xfffd
                                 70                 :                : #define MovedPartitionsBlockNumber  InvalidBlockNumber
                                 71                 :                : 
                                 72                 :                : /*
                                 73                 :                :  * A versioned composite datum (see HEAP_IS_DATUM in htup_details.h) has
                                 74                 :                :  * ip_posid set to VersionedDatumOffsetNumber.
                                 75                 :                :  */
                                 76                 :                : #define VersionedDatumOffsetNumber  0xfffc
                                 77                 :                : 
                                 78                 :                : StaticAssertDecl(VersionedDatumOffsetNumber > MaxOffsetNumber,
                                 79                 :                :                  "VersionedDatumOffsetNumber may not be considered a valid offset");
                                 80                 :                : 
                                 81                 :                : 
                                 82                 :                : /* ----------------
                                 83                 :                :  *      support functions
                                 84                 :                :  * ----------------
                                 85                 :                :  */
                                 86                 :                : 
                                 87                 :                : /*
                                 88                 :                :  * ItemPointerIsValid
                                 89                 :                :  *      True iff the disk item pointer is not NULL.
                                 90                 :                :  */
                                 91                 :                : static inline bool
 1599 peter@eisentraut.org       92                 :CBC   764939693 : ItemPointerIsValid(const ItemPointerData *pointer)
                                 93                 :                : {
  430                            94   [ +  +  +  + ]:      764939693 :     return pointer && pointer->ip_posid != 0;
                                 95                 :                : }
                                 96                 :                : 
                                 97                 :                : /*
                                 98                 :                :  * ItemPointerGetBlockNumberNoCheck
                                 99                 :                :  *      Returns the block number of a disk item pointer.
                                100                 :                :  */
                                101                 :                : static inline BlockNumber
 1599                           102                 :      424908593 : ItemPointerGetBlockNumberNoCheck(const ItemPointerData *pointer)
                                103                 :                : {
                                104                 :      424908593 :     return BlockIdGetBlockNumber(&pointer->ip_blkid);
                                105                 :                : }
                                106                 :                : 
                                107                 :                : /*
                                108                 :                :  * ItemPointerGetBlockNumber
                                109                 :                :  *      As above, but verifies that the item pointer looks valid.
                                110                 :                :  */
                                111                 :                : static inline BlockNumber
                                112                 :      244258733 : ItemPointerGetBlockNumber(const ItemPointerData *pointer)
                                113                 :                : {
                                114         [ -  + ]:      244258733 :     Assert(ItemPointerIsValid(pointer));
                                115                 :      244258733 :     return ItemPointerGetBlockNumberNoCheck(pointer);
                                116                 :                : }
                                117                 :                : 
                                118                 :                : /*
                                119                 :                :  * ItemPointerGetOffsetNumberNoCheck
                                120                 :                :  *      Returns the offset number of a disk item pointer.
                                121                 :                :  */
                                122                 :                : static inline OffsetNumber
                                123                 :     1343210415 : ItemPointerGetOffsetNumberNoCheck(const ItemPointerData *pointer)
                                124                 :                : {
                                125                 :     1343210415 :     return pointer->ip_posid;
                                126                 :                : }
                                127                 :                : 
                                128                 :                : /*
                                129                 :                :  * ItemPointerGetOffsetNumber
                                130                 :                :  *      As above, but verifies that the item pointer looks valid.
                                131                 :                :  */
                                132                 :                : static inline OffsetNumber
                                133                 :      154419590 : ItemPointerGetOffsetNumber(const ItemPointerData *pointer)
                                134                 :                : {
                                135         [ -  + ]:      154419590 :     Assert(ItemPointerIsValid(pointer));
                                136                 :      154419590 :     return ItemPointerGetOffsetNumberNoCheck(pointer);
                                137                 :                : }
                                138                 :                : 
                                139                 :                : /*
                                140                 :                :  * ItemPointerSet
                                141                 :                :  *      Sets a disk item pointer to the specified block and offset.
                                142                 :                :  */
                                143                 :                : static inline void
                                144                 :      174012944 : ItemPointerSet(ItemPointerData *pointer, BlockNumber blockNumber, OffsetNumber offNum)
                                145                 :                : {
  430                           146         [ -  + ]:      174012944 :     Assert(pointer);
 1599                           147                 :      174012944 :     BlockIdSet(&pointer->ip_blkid, blockNumber);
                                148                 :      174012944 :     pointer->ip_posid = offNum;
                                149                 :      174012944 : }
                                150                 :                : 
                                151                 :                : /*
                                152                 :                :  * ItemPointerSetBlockNumber
                                153                 :                :  *      Sets a disk item pointer to the specified block.
                                154                 :                :  */
                                155                 :                : static inline void
                                156                 :       94108166 : ItemPointerSetBlockNumber(ItemPointerData *pointer, BlockNumber blockNumber)
                                157                 :                : {
  430                           158         [ -  + ]:       94108166 :     Assert(pointer);
 1599                           159                 :       94108166 :     BlockIdSet(&pointer->ip_blkid, blockNumber);
                                160                 :       94108166 : }
                                161                 :                : 
                                162                 :                : /*
                                163                 :                :  * ItemPointerSetOffsetNumber
                                164                 :                :  *      Sets a disk item pointer to the specified offset.
                                165                 :                :  */
                                166                 :                : static inline void
                                167                 :      230859962 : ItemPointerSetOffsetNumber(ItemPointerData *pointer, OffsetNumber offsetNumber)
                                168                 :                : {
  430                           169         [ -  + ]:      230859962 :     Assert(pointer);
 1599                           170                 :      230859962 :     pointer->ip_posid = offsetNumber;
                                171                 :      230859962 : }
                                172                 :                : 
                                173                 :                : /*
                                174                 :                :  * ItemPointerCopy
                                175                 :                :  *      Copies the contents of one disk item pointer to another.
                                176                 :                :  *
                                177                 :                :  * Should there ever be padding in an ItemPointer this would need to be handled
                                178                 :                :  * differently as it's used as hash key.
                                179                 :                :  */
                                180                 :                : static inline void
                                181                 :       29646928 : ItemPointerCopy(const ItemPointerData *fromPointer, ItemPointerData *toPointer)
                                182                 :                : {
  430                           183         [ -  + ]:       29646928 :     Assert(toPointer);
                                184         [ -  + ]:       29646928 :     Assert(fromPointer);
 1599                           185                 :       29646928 :     *toPointer = *fromPointer;
                                186                 :       29646928 : }
                                187                 :                : 
                                188                 :                : /*
                                189                 :                :  * ItemPointerSetInvalid
                                190                 :                :  *      Sets a disk item pointer to be invalid.
                                191                 :                :  */
                                192                 :                : static inline void
                                193                 :      189624553 : ItemPointerSetInvalid(ItemPointerData *pointer)
                                194                 :                : {
  430                           195         [ -  + ]:      189624553 :     Assert(pointer);
 1599                           196                 :      189624553 :     BlockIdSet(&pointer->ip_blkid, InvalidBlockNumber);
                                197                 :      189624553 :     pointer->ip_posid = InvalidOffsetNumber;
                                198                 :      189624553 : }
                                199                 :                : 
                                200                 :                : /*
                                201                 :                :  * ItemPointerIndicatesMovedPartitions
                                202                 :                :  *      True iff the block number indicates the tuple has moved to another
                                203                 :                :  *      partition.
                                204                 :                :  */
                                205                 :                : static inline bool
                                206                 :         165137 : ItemPointerIndicatesMovedPartitions(const ItemPointerData *pointer)
                                207                 :                : {
                                208                 :                :     return
                                209   [ +  +  +  - ]:         165150 :         ItemPointerGetOffsetNumber(pointer) == MovedPartitionsOffsetNumber &&
                                210                 :             13 :         ItemPointerGetBlockNumberNoCheck(pointer) == MovedPartitionsBlockNumber;
                                211                 :                : }
                                212                 :                : 
                                213                 :                : /*
                                214                 :                :  * ItemPointerSetMovedPartitions
                                215                 :                :  *      Indicate that the item referenced by the itempointer has moved into a
                                216                 :                :  *      different partition.
                                217                 :                :  */
                                218                 :                : static inline void
                                219                 :            795 : ItemPointerSetMovedPartitions(ItemPointerData *pointer)
                                220                 :                : {
                                221                 :            795 :     ItemPointerSet(pointer, MovedPartitionsBlockNumber, MovedPartitionsOffsetNumber);
                                222                 :            795 : }
                                223                 :                : 
                                224                 :                : /* ----------------
                                225                 :                :  *      externs
                                226                 :                :  * ----------------
                                227                 :                :  */
                                228                 :                : 
                                229                 :                : extern bool ItemPointerEquals(const ItemPointerData *pointer1, const ItemPointerData *pointer2);
                                230                 :                : extern int32 ItemPointerCompare(const ItemPointerData *arg1, const ItemPointerData *arg2);
                                231                 :                : extern void ItemPointerInc(ItemPointer pointer);
                                232                 :                : extern void ItemPointerDec(ItemPointer pointer);
                                233                 :                : 
                                234                 :                : /* ----------------
                                235                 :                :  *      Datum conversion functions
                                236                 :                :  * ----------------
                                237                 :                :  */
                                238                 :                : 
                                239                 :                : static inline ItemPointer
 1384                           240                 :       28409191 : DatumGetItemPointer(Datum X)
                                241                 :                : {
                                242                 :       28409191 :     return (ItemPointer) DatumGetPointer(X);
                                243                 :                : }
                                244                 :                : 
                                245                 :                : static inline Datum
                                246                 :          25933 : ItemPointerGetDatum(const ItemPointerData *X)
                                247                 :                : {
                                248                 :          25933 :     return PointerGetDatum(X);
                                249                 :                : }
                                250                 :                : 
                                251                 :                : #define PG_GETARG_ITEMPOINTER(n) DatumGetItemPointer(PG_GETARG_DATUM(n))
                                252                 :                : #define PG_RETURN_ITEMPOINTER(x) return ItemPointerGetDatum(x)
                                253                 :                : 
                                254                 :                : #endif                          /* ITEMPTR_H */
        

Generated by: LCOV version 2.0-1