pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Paquier <michael@paquier.xyz>
To: Gaurav Singh <gaurav.singh@yugabyte.com>
Cc: Sami Imseih <samimseih.pg@gmail.com>
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: pg_stat_statements stores WITH HOLD cursor query with literals
Date: Thu, 22 Oct 2026 12:09:56 +0900
Message-ID: <atl-hB3haQF62tlN@paquier.xyz> (raw)
In-Reply-To: <CAEcQ1bZ0oW_RaNFAo6S9COOLnhdskx=z6p285WALq10QgVpYBA@mail.gmail.com>
References: <CAEcQ1bZrgwKsauC=03otebkLk77Zc_hYNjhTP3OUdpXs++u+BA@mail.gmail.com>
	<CAN12+YLPn65OFk+POCnLo1QJ=n3Gooz6Bsz_VsF2uh5c45iuPQ@mail.gmail.com>
	<CAEcQ1bZJUzjxe-tSOU25T3XtMEL3YyC4ESjk9k+KVAHRvyhtAQ@mail.gmail.com>
	<CAN12+Y+KwJc8HH9BRzyfuG9vcU-=4vv_gc2BQ24sGpmxZi9Caw@mail.gmail.com>
	<CAN12+YL7jf5_04Lme1Qaf2=_JuMAKAoCQiSY7-4__Svfc4igBA@mail.gmail.com>
	<CAEcQ1bYf03gGvvZWXCTv2L198zNArFrVoNDNQWecJ_7YmfE6UA@mail.gmail.com>
	<CAN12+YJdyb6zRHU+3owvBpKxgqB-tweRjjhUUTa5TyDn433GRw@mail.gmail.com>
	<CAEcQ1bZ0oW_RaNFAo6S9COOLnhdskx=z6p285WALq10QgVpYBA@mail.gmail.com>

On Thu, Oct 15, 2026 at 10:36:06AM +0530, Gaurav Singh wrote:
> I think the issue has existed since PG18, could we have a backpatch too?

With a change in QueryDesc?  I'm afraid not.

+	/*
+	 * Nesting level at which this query started, or -1 if not set.  An
+	 * extension may set this from its ExecutorStart hook and read it back at
+	 * ExecutorEnd, which can run at a different level.  For example, a
+	 * cursor's query starts inside DECLARE but may end at COMMIT.
+	 *
+	 * The level counts as pg_stat_statements does: 0 for a statement sent by
+	 * the client, including EXECUTE of a prepared statement; one deeper for
+	 * each query run by another statement or by a function.  All extensions
+	 * that set this field must use that definition; one that counts
+	 * differently must leave it alone.
+	 */
+	int			start_nesting_level;

This is a one-time extension field, tied exclusively to PGSS that may
or may not conflict depending on what other extensions do.  This does
not give me good vibes in terms of extensibility, due to the easy
conflicts with other extensions.

We have a similar concept for ExplainState with its extension_state
indexed by GetExplainExtensionId() based on an extension name.
Perhaps we should do something similar for QueryDesc?  That would take
care of the conflicting states across extensions at least, giving
extensions way to store in the QueryDesc what they want.  Here, that's
the nesting_level that you want to track *only* in PGSS and have no
other extensions meddle with it.
--
Michael

Attachments:

  signature.asc (application/pgp-signature, 832B) download

view thread (18+ messages)  latest in thread

Message-ID: <atl-hB3haQF62tlN@paquier.xyz>
Permalink:  ../atl-hB3haQF62tlN@paquier.xyz/
Also on:    postgresql.org/message-id/atl-hB3haQF62tlN@paquier.xyz

 · 

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-bugs@postgresql.org
  Cc: michael@paquier.xyz, gaurav.singh@yugabyte.com, samimseih.pg@gmail.com
  Subject: Re: pg_stat_statements stores WITH HOLD cursor query with literals
  In-Reply-To: <atl-hB3haQF62tlN@paquier.xyz>
  References: <CAEcQ1bZrgwKsauC=03otebkLk77Zc_hYNjhTP3OUdpXs++u+BA@mail.gmail.com> <CAN12+YLPn65OFk+POCnLo1QJ=n3Gooz6Bsz_VsF2uh5c45iuPQ@mail.gmail.com> <CAEcQ1bZJUzjxe-tSOU25T3XtMEL3YyC4ESjk9k+KVAHRvyhtAQ@mail.gmail.com> <CAN12+Y+KwJc8HH9BRzyfuG9vcU-=4vv_gc2BQ24sGpmxZi9Caw@mail.gmail.com> <CAN12+YL7jf5_04Lme1Qaf2=_JuMAKAoCQiSY7-4__Svfc4igBA@mail.gmail.com> <CAEcQ1bYf03gGvvZWXCTv2L198zNArFrVoNDNQWecJ_7YmfE6UA@mail.gmail.com> <CAN12+YJdyb6zRHU+3owvBpKxgqB-tweRjjhUUTa5TyDn433GRw@mail.gmail.com> <CAEcQ1bZ0oW_RaNFAo6S9COOLnhdskx=z6p285WALq10QgVpYBA@mail.gmail.com> <atl-hB3haQF62tlN@paquier.xyz>

* 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