LCOV - differential code coverage report
Current view: top level - src/backend/utils/adt - multixactfuncs.c (source / functions) Coverage Total Hit UBC CBC
Current: 1a1248818fb8b8b0353c292c632d6a6af77e8209 vs 8e82d6610e7280d7870c0c36ff1c797e3cfb3e09 Lines: 90.5 % 42 38 4 38
Current Date: 2026-10-12 11:56:10 +0200 Functions: 100.0 % 2 2 2
Baseline: lcov-20261012-baseline Branches: 45.5 % 22 10 12 10
Baseline Date: 2026-10-12 10:36:06 +0200 Line coverage date bins:
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
(7,30] days: 50.0 % 2 1 1 1
(30,360] days: 93.3 % 15 14 1 14
(360..) days: 92.0 % 25 23 2 23
Function coverage date bins:
(30,360] days: 100.0 % 1 1 1
(360..) days: 100.0 % 1 1 1
Branch coverage date bins:
(7,30] days: 25.0 % 4 1 3 1
(30,360] days: 50.0 % 6 3 3 3
(360..) days: 50.0 % 12 6 6 6

 Age         Owner                    Branch data    TLA  Line data    Source code
                                  1                 :                : /*-------------------------------------------------------------------------
                                  2                 :                :  *
                                  3                 :                :  * multixactfuncs.c
                                  4                 :                :  *    Functions for accessing multixact-related data.
                                  5                 :                :  *
                                  6                 :                :  * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
                                  7                 :                :  * Portions Copyright (c) 1994, Regents of the University of California
                                  8                 :                :  *
                                  9                 :                :  * IDENTIFICATION
                                 10                 :                :  *    src/backend/utils/adt/multixactfuncs.c
                                 11                 :                :  *
                                 12                 :                :  *-------------------------------------------------------------------------
                                 13                 :                :  */
                                 14                 :                : 
                                 15                 :                : #include "postgres.h"
                                 16                 :                : 
                                 17                 :                : #include "access/htup_details.h"
                                 18                 :                : #include "access/multixact.h"
                                 19                 :                : #include "access/multixact_internal.h"
                                 20                 :                : #include "access/xlog.h"
                                 21                 :                : #include "catalog/pg_authid_d.h"
                                 22                 :                : #include "funcapi.h"
                                 23                 :                : #include "miscadmin.h"
                                 24                 :                : #include "utils/acl.h"
                                 25                 :                : #include "utils/builtins.h"
                                 26                 :                : 
                                 27                 :                : /*
                                 28                 :                :  * pg_get_multixact_members
                                 29                 :                :  *
                                 30                 :                :  * Returns information about the MultiXactMembers of the specified
                                 31                 :                :  * MultiXactId.
                                 32                 :                :  */
                                 33                 :                : Datum
  420 michael@paquier.xyz        34                 :CBC      198078 : pg_get_multixact_members(PG_FUNCTION_ARGS)
                                 35                 :                : {
                                 36                 :                :     typedef struct
                                 37                 :                :     {
                                 38                 :                :         MultiXactMember *members;
                                 39                 :                :         int         nmembers;
                                 40                 :                :         int         iter;
                                 41                 :                :     } mxact;
                                 42                 :         198078 :     MultiXactId mxid = PG_GETARG_TRANSACTIONID(0);
                                 43                 :                :     mxact      *multi;
                                 44                 :                :     FuncCallContext *funccxt;
                                 45                 :                : 
                                 46         [ -  + ]:         198078 :     if (mxid < FirstMultiXactId)
  420 michael@paquier.xyz        47         [ #  # ]:UBC           0 :         ereport(ERROR,
                                 48                 :                :                 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                                 49                 :                :                  errmsg("invalid MultiXactId: %u", mxid)));
                                 50                 :                : 
  420 michael@paquier.xyz        51         [ +  + ]:CBC      198078 :     if (SRF_IS_FIRSTCALL())
                                 52                 :                :     {
                                 53                 :                :         MemoryContext oldcxt;
                                 54                 :                :         TupleDesc   tupdesc;
                                 55                 :                : 
                                 56                 :           9990 :         funccxt = SRF_FIRSTCALL_INIT();
                                 57                 :           9990 :         oldcxt = MemoryContextSwitchTo(funccxt->multi_call_memory_ctx);
                                 58                 :                : 
  306                            59                 :           9990 :         multi = palloc_object(mxact);
                                 60                 :                :         /* no need to allow for old values here */
  420                            61                 :           9990 :         multi->nmembers = GetMultiXactIdMembers(mxid, &multi->members, false,
                                 62                 :                :                                                 false);
                                 63                 :           9990 :         multi->iter = 0;
                                 64                 :                : 
                                 65         [ -  + ]:           9990 :         if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
  420 michael@paquier.xyz        66         [ #  # ]:UBC           0 :             elog(ERROR, "return type must be a row type");
  420 michael@paquier.xyz        67                 :CBC        9990 :         funccxt->tuple_desc = tupdesc;
                                 68                 :           9990 :         funccxt->attinmeta = TupleDescGetAttInMetadata(tupdesc);
                                 69                 :           9990 :         funccxt->user_fctx = multi;
                                 70                 :                : 
                                 71                 :           9990 :         MemoryContextSwitchTo(oldcxt);
                                 72                 :                :     }
                                 73                 :                : 
                                 74                 :         198078 :     funccxt = SRF_PERCALL_SETUP();
                                 75                 :         198078 :     multi = (mxact *) funccxt->user_fctx;
                                 76                 :                : 
                                 77         [ +  + ]:         198078 :     while (multi->iter < multi->nmembers)
                                 78                 :                :     {
                                 79                 :                :         HeapTuple   tuple;
                                 80                 :                :         char       *values[2];
                                 81                 :                : 
                                 82                 :         188088 :         values[0] = psprintf("%u", multi->members[multi->iter].xid);
                                 83                 :         188088 :         values[1] = mxstatus_to_string(multi->members[multi->iter].status);
                                 84                 :                : 
                                 85                 :         188088 :         tuple = BuildTupleFromCStrings(funccxt->attinmeta, values);
                                 86                 :                : 
                                 87                 :         188088 :         multi->iter++;
                                 88                 :         188088 :         pfree(values[0]);
                                 89                 :         188088 :         SRF_RETURN_NEXT(funccxt, HeapTupleGetDatum(tuple));
                                 90                 :                :     }
                                 91                 :                : 
                                 92                 :           9990 :     SRF_RETURN_DONE(funccxt);
                                 93                 :                : }
                                 94                 :                : 
                                 95                 :                : /*
                                 96                 :                :  * pg_get_multixact_stats
                                 97                 :                :  *
                                 98                 :                :  * Returns statistics about current multixact usage.
                                 99                 :                :  */
                                100                 :                : Datum
  286                           101                 :             15 : pg_get_multixact_stats(PG_FUNCTION_ARGS)
                                102                 :                : {
                                103                 :                :     TupleDesc   tupdesc;
                                104                 :                :     Datum       values[4];
                                105                 :                :     bool        nulls[4];
                                106                 :                : 
   18                           107         [ -  + ]:             15 :     if (RecoveryInProgress())
   18 michael@paquier.xyz       108         [ #  # ]:UBC           0 :         ereport(ERROR,
                                109                 :                :                 (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
                                110                 :                :                  errmsg("recovery is in progress"),
                                111                 :                :                  errhint("%s cannot be executed during recovery.",
                                112                 :                :                          "pg_get_multixact_stats()")));
                                113                 :                : 
  286 michael@paquier.xyz       114         [ -  + ]:CBC          15 :     if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
  286 michael@paquier.xyz       115         [ #  # ]:UBC           0 :         ereport(ERROR,
                                116                 :                :                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
                                117                 :                :                  errmsg("return type must be a row type")));
                                118                 :                : 
  286 michael@paquier.xyz       119         [ +  + ]:CBC          15 :     if (!has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS))
                                120                 :                :     {
                                121                 :                :         /*
                                122                 :                :          * Only superusers and roles with privileges of pg_read_all_stats can
                                123                 :                :          * see details.
                                124                 :                :          */
                                125                 :              4 :         memset(nulls, true, sizeof(bool) * tupdesc->natts);
                                126                 :                :     }
                                127                 :                :     else
                                128                 :                :     {
                                129                 :                :         uint64      members;
                                130                 :                :         MultiXactId oldestMultiXactId;
                                131                 :                :         uint32      multixacts;
                                132                 :                :         MultiXactOffset oldestOffset;
                                133                 :                :         MultiXactOffset nextOffset;
                                134                 :                :         uint64      membersBytes;
                                135                 :                : 
  103                           136                 :             11 :         GetMultiXactInfo(&multixacts, &nextOffset, &oldestMultiXactId, &oldestOffset);
                                137                 :             11 :         members = nextOffset - oldestOffset;
                                138                 :             11 :         membersBytes = MultiXactOffsetStorageSize(nextOffset, oldestOffset);
                                139                 :                : 
  286                           140                 :             11 :         values[0] = UInt32GetDatum(multixacts);
                                141                 :             11 :         values[1] = Int64GetDatum(members);
                                142                 :             11 :         values[2] = Int64GetDatum(membersBytes);
                                143                 :             11 :         values[3] = UInt32GetDatum(oldestMultiXactId);
                                144                 :             11 :         memset(nulls, false, sizeof(nulls));
                                145                 :                :     }
                                146                 :                : 
                                147                 :             15 :     return HeapTupleGetDatum(heap_form_tuple(tupdesc, values, nulls));
                                148                 :                : }
        

Generated by: LCOV version 2.0-1