LCOV - code coverage report
Current view: top level - src/backend/storage/freespace - indexfsm.c (source / functions) Coverage Total Hit
Test: Code coverage Lines: 100.0 % 15 15
Test Date: 2026-01-26 10:56:24 Functions: 100.0 % 4 4
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
Branches: 100.0 % 2 2

             Branch data     Line data    Source code
       1                 :             : /*-------------------------------------------------------------------------
       2                 :             :  *
       3                 :             :  * indexfsm.c
       4                 :             :  *        POSTGRES free space map for quickly finding free pages in relations
       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                 :             :  * IDENTIFICATION
      11                 :             :  *        src/backend/storage/freespace/indexfsm.c
      12                 :             :  *
      13                 :             :  *
      14                 :             :  * NOTES:
      15                 :             :  *
      16                 :             :  *      This is similar to the FSM used for heap, in freespace.c, but instead
      17                 :             :  *      of tracking the amount of free space on pages, we only track whether
      18                 :             :  *      pages are completely free or in-use. We use the same FSM implementation
      19                 :             :  *      as for heaps, using 0 to denote used pages, and (BLCKSZ - 1) for unused.
      20                 :             :  *
      21                 :             :  *-------------------------------------------------------------------------
      22                 :             :  */
      23                 :             : #include "postgres.h"
      24                 :             : 
      25                 :             : #include "storage/freespace.h"
      26                 :             : #include "storage/indexfsm.h"
      27                 :             : 
      28                 :             : /*
      29                 :             :  * Exported routines
      30                 :             :  */
      31                 :             : 
      32                 :             : /*
      33                 :             :  * GetFreeIndexPage - return a free page from the FSM
      34                 :             :  *
      35                 :             :  * As a side effect, the page is marked as used in the FSM.
      36                 :             :  */
      37                 :             : BlockNumber
      38                 :        6964 : GetFreeIndexPage(Relation rel)
      39                 :             : {
      40                 :        6964 :         BlockNumber blkno = GetPageWithFreeSpace(rel, BLCKSZ / 2);
      41                 :             : 
      42         [ +  + ]:        6964 :         if (blkno != InvalidBlockNumber)
      43                 :          29 :                 RecordUsedIndexPage(rel, blkno);
      44                 :             : 
      45                 :       13928 :         return blkno;
      46                 :        6964 : }
      47                 :             : 
      48                 :             : /*
      49                 :             :  * RecordFreeIndexPage - mark a page as free in the FSM
      50                 :             :  */
      51                 :             : void
      52                 :        1246 : RecordFreeIndexPage(Relation rel, BlockNumber freeBlock)
      53                 :             : {
      54                 :        1246 :         RecordPageWithFreeSpace(rel, freeBlock, BLCKSZ - 1);
      55                 :        1246 : }
      56                 :             : 
      57                 :             : 
      58                 :             : /*
      59                 :             :  * RecordUsedIndexPage - mark a page as used in the FSM
      60                 :             :  */
      61                 :             : void
      62                 :          29 : RecordUsedIndexPage(Relation rel, BlockNumber usedBlock)
      63                 :             : {
      64                 :          29 :         RecordPageWithFreeSpace(rel, usedBlock, 0);
      65                 :          29 : }
      66                 :             : 
      67                 :             : /*
      68                 :             :  * IndexFreeSpaceMapVacuum - scan and fix any inconsistencies in the FSM
      69                 :             :  */
      70                 :             : void
      71                 :          22 : IndexFreeSpaceMapVacuum(Relation rel)
      72                 :             : {
      73                 :          22 :         FreeSpaceMapVacuum(rel);
      74                 :          22 : }
        

Generated by: LCOV version 2.3.2-1