From: Michael Paquier Date: Wed, 1 Jul 2026 03:17:17 +0000 (+0900) Subject: Avoid useless calls in pg_get_multixact_stats() X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b542d556670586ebadf380102f6ead920609e592;p=thirdparty%2Fpostgresql.git Avoid useless calls in pg_get_multixact_stats() MultiXactOffsetStorageSize() and GetMultiXactInfo() are called to gather the information reported by the function, but were wasteful for the case where a role does not have the privileges of pg_read_all_stats, where we return a set of NULLs. These calls are moved to the code path where their results are used. Author: Ranier Vilela Discussion: https://postgr.es/m/CAEudQAonQh7be=wOR-CJFW=bgMBz5wW_bv4t0OFxbgn-794JCQ@mail.gmail.com Backpatch-through: 19 --- diff --git a/src/backend/utils/adt/multixactfuncs.c b/src/backend/utils/adt/multixactfuncs.c index 9fe2ebafa73..d9aa58e821d 100644 --- a/src/backend/utils/adt/multixactfuncs.c +++ b/src/backend/utils/adt/multixactfuncs.c @@ -102,23 +102,12 @@ pg_get_multixact_stats(PG_FUNCTION_ARGS) TupleDesc tupdesc; Datum values[4]; bool nulls[4]; - uint64 members; - MultiXactId oldestMultiXactId; - uint32 multixacts; - MultiXactOffset oldestOffset; - MultiXactOffset nextOffset; - uint64 membersBytes; if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("return type must be a row type"))); - GetMultiXactInfo(&multixacts, &nextOffset, &oldestMultiXactId, &oldestOffset); - members = nextOffset - oldestOffset; - - membersBytes = MultiXactOffsetStorageSize(nextOffset, oldestOffset); - if (!has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS)) { /* @@ -129,6 +118,17 @@ pg_get_multixact_stats(PG_FUNCTION_ARGS) } else { + uint64 members; + MultiXactId oldestMultiXactId; + uint32 multixacts; + MultiXactOffset oldestOffset; + MultiXactOffset nextOffset; + uint64 membersBytes; + + GetMultiXactInfo(&multixacts, &nextOffset, &oldestMultiXactId, &oldestOffset); + members = nextOffset - oldestOffset; + membersBytes = MultiXactOffsetStorageSize(nextOffset, oldestOffset); + values[0] = UInt32GetDatum(multixacts); values[1] = Int64GetDatum(members); values[2] = Int64GetDatum(membersBytes);