Re: Custom pgstat support performance regression for simple queries

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Andres Freund <andres(at)anarazel(dot)de>
Cc: pgsql-hackers(at)postgresql(dot)org, Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Subject: Re: Custom pgstat support performance regression for simple queries
Date: 2025-07-23 00:54:12
Message-ID: aIAytLj0-krHdKCH@paquier.xyz
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Jul 22, 2025 at 10:57:06AM -0400, Andres Freund wrote:
> It seems rather unsurprising that that causes a slowdown.
>
> The pre-check is there to:
> /* Don't expend a clock check if nothing to do */
>
> but you made it way more expensive than a clock check would have been (not
> counting old vmware installs or such, where clock checks take ages).
>
> If I change the loop count to only be the builtin stats kinds, the overhead
> goes away almost completely.

Noted. I was wondering originally if the threshold for the builtin
and custom kinds should be lowered, as well. Perhaps that's just too
optimistic, so we can first lower things. Say PGSTAT_KIND_CUSTOM_MIN
to 32 and PGSTAT_KIND_MAX to 48 or so to begin with? I don't see a
strict policy here, but these would make the whole cheaper to begin
with, with enough margin for any new stats kinds.

Then, about the loop used here, I'd be OK to keep the past shortcuts
for the builtin fixed-sized stats kinds with the requirement that new
builtin stats kinds need to hack into pgstat_report_stat() themselves
on efficiency grounds, combined with a second loop for custom kinds,
taken only if pgstat_register_kind() has been used by tracking if
that's the case in a flag. Do you have a specific preference here?
--
Michael

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Yugo Nagata 2025-07-23 00:55:31 Re: stats.sql might fail due to shared buffers also used by parallel tests
Previous Message Tomas Vondra 2025-07-23 00:50:04 Re: index prefetching