pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Paquier <michael@paquier.xyz>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Add custom extension states to QueryDesc
Date: Tue, 27 Oct 2026 06:09:45 +0000
Message-ID: <E1xLaNV-00000000wHN-0muS@gemulon.postgresql.org> (raw)

Add custom extension states to QueryDesc

Extensions sometimes need to carry private data from one executor hook
to another for a given query.  ExecutorEnd() can run in a different
context than ExecutorStart(), so backend-wide variables cannot be used
for that.

This commit adds a way for loadable modules to attach private state to a
QueryDesc, modeled in the same fashion as what is already done for
PlannerGlobal, PlannerInfo, RelOptInfo and ExplainState.

GetQueryDescExtensionId() maps an extension name to a backend-local ID.
SetQueryDescExtensionState() and GetQueryDescExtensionState() store and
fetch an opaque pointer for that ID.  The array of pointers is allocated
in the memory context of the QueryDesc, and is freed by FreeQueryDesc().
What the pointers refer to is owned by the extensions.

There are no users of this facility yet.  A follow-up commit will make
use of it.  Some potential use cases have been identified for
pg_stat_statements and auto_explain, where both need to be able to
co-exist in peace.  Extensions living outside of core may also find a
use for it.

Author: Michael Paquier <michael@paquier.xyz>
Reviewed-by: Sami Imseih <samimseih.pg@gmail.com>
Discussion: https://postgr.es/m/CAEcQ1bZrgwKsauC=03otebkLk77Zc_hYNjhTP3OUdpXs++u+BA@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/e5d5d1ad1e3aa495609e19fa716dcea6a39db1bb

Modified Files
--------------
src/backend/tcop/pquery.c       | 107 +++++++++++++++++++++++++++++++++++++++-
src/include/executor/execdesc.h |   9 ++++
2 files changed, 114 insertions(+), 2 deletions(-)



Message-ID: <E1xLaNV-00000000wHN-0muS@gemulon.postgresql.org>
Permalink:  ../E1xLaNV-00000000wHN-0muS@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1xLaNV-00000000wHN-0muS@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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: michael@paquier.xyz
  Subject: Re: pgsql: Add custom extension states to QueryDesc
  In-Reply-To: <E1xLaNV-00000000wHN-0muS@gemulon.postgresql.org>
  References: <E1xLaNV-00000000wHN-0muS@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 DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox