agora inbox for pgsql-committers@postgresql.org  
help / color / mirror / Atom feed
From: Andres Freund <andres@anarazel.de>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: instrumentation: Allocate query level instrumentation in Executo
Date: Wed, 08 Apr 2026 04:09:54 +0000
Message-ID: <E1wAKEj-003Ukg-0v@gemulon.postgresql.org> (raw)

instrumentation: Allocate query level instrumentation in ExecutorStart

Until now extensions that wanted to measure overall query execution could
create QueryDesc->totaltime, which the core executor would then start and
stop.  That's a bit odd and composes badly, e.g. extensions always had to use
INSTRUMENT_ALL, because otherwise another extension might not get what they
need.

Instead this introduces a new field, QueryDesc->query_instr_options, that
extensions can use to indicate whether they need query level instrumentation
populated, and with which instrumentation options. Extensions should take care
to only add options they need, instead of replacing the options of others.

The prior name of the field, totaltime, sounded like it would only measure
time, but these days the instrumentation infrastructure can track more
resources.  The secondary benefit is that this will make it obvious to
extensions that they may not create the Instrumentation struct themselves
anymore (often extensions build only against a postgres build without
assertions).

Adjust pg_stat_statements and auto_explain to match, and lower the
requested instrumentation level for auto_explain to INSTRUMENT_TIMER,
since the summary instrumentation it needs is only runtime.

The reason to push this now, rather in the PG 20 cycle, is that 5a79e78501f
already required extensions using query level instrumentations to adjust their
code, and it seemed undesirable to require them to do so again for 20.

Author: Lukas Fittl <lukas@fittl.com>
Reviewed-by: Andres Freund <andres@anarazel.de>
Discussion: https://postgr.es/m/CAP53Pkyqsht+exJQYRsjhSWYKu+vFGHhPub7m6PmFD6Or0=p1g@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/2c16deee2f7d52d6567dcbad046f74a8e880ee52

Modified Files
--------------
contrib/auto_explain/auto_explain.c             | 24 ++++--------------
contrib/pg_stat_statements/pg_stat_statements.c | 33 +++++++++----------------
src/backend/executor/execMain.c                 | 27 +++++++++++++-------
src/backend/tcop/pquery.c                       |  3 ++-
src/include/executor/execdesc.h                 |  6 +++--
5 files changed, 40 insertions(+), 53 deletions(-)



Message-ID: <E1wAKEj-003Ukg-0v@gemulon.postgresql.org>
Permalink:  ../E1wAKEj-003Ukg-0v@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1wAKEj-003Ukg-0v@gemulon.postgresql.org

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: andres@anarazel.de, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: instrumentation: Allocate query level instrumentation in Executo
  In-Reply-To: <E1wAKEj-003Ukg-0v@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox