LCOV - code coverage report
Current view: top level - contrib/pg_freespacemap - pg_freespacemap.c (source / functions) Hit Total Coverage
Test: PostgreSQL 17beta1 Lines: 11 11 100.0 %
Date: 2024-06-17 22:11:45 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*-------------------------------------------------------------------------
       2             :  *
       3             :  * pg_freespacemap.c
       4             :  *    display contents of a free space map
       5             :  *
       6             :  *    contrib/pg_freespacemap/pg_freespacemap.c
       7             :  *-------------------------------------------------------------------------
       8             :  */
       9             : #include "postgres.h"
      10             : 
      11             : #include "access/relation.h"
      12             : #include "funcapi.h"
      13             : #include "storage/freespace.h"
      14             : 
      15           2 : PG_MODULE_MAGIC;
      16             : 
      17             : /*
      18             :  * Returns the amount of free space on a given page, according to the
      19             :  * free space map.
      20             :  */
      21           4 : PG_FUNCTION_INFO_V1(pg_freespace);
      22             : 
      23             : Datum
      24          94 : pg_freespace(PG_FUNCTION_ARGS)
      25             : {
      26          94 :     Oid         relid = PG_GETARG_OID(0);
      27          94 :     int64       blkno = PG_GETARG_INT64(1);
      28             :     int16       freespace;
      29             :     Relation    rel;
      30             : 
      31          94 :     rel = relation_open(relid, AccessShareLock);
      32             : 
      33          94 :     if (blkno < 0 || blkno > MaxBlockNumber)
      34           4 :         ereport(ERROR,
      35             :                 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
      36             :                  errmsg("invalid block number")));
      37             : 
      38          90 :     freespace = GetRecordedFreeSpace(rel, blkno);
      39             : 
      40          90 :     relation_close(rel, AccessShareLock);
      41          90 :     PG_RETURN_INT16(freespace);
      42             : }

Generated by: LCOV version 1.14