Re: pg_stat_statements: Fix nested tracking for implicitly closed cursors

From: Lukas Fittl <lukas(at)fittl(dot)com>
To: Michael Paquier <michael(at)paquier(dot)xyz>
Cc: Sami Imseih <samimseih(at)gmail(dot)com>, Martin Huang <jjja5555(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: pg_stat_statements: Fix nested tracking for implicitly closed cursors
Date: 2026-01-20 21:27:05
Message-ID: CAP53PkxSYyOqK1qj6Wj+VY8bhm8k7sjRqZu8pZTcr2R05N0-DQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sun, Jan 18, 2026 at 7:18 PM Michael Paquier <michael(at)paquier(dot)xyz> wrote:
> Hmm. While reading through the patch, I am wondering if this approach
> to this kind of problem is the right thing to do long-term, relying on
> a static flag to decide if the nesting level should be manipulated or
> not when we end the executor. pgss is not the only module where I
> have seen that we want to track a nesting level in a precise way. So
> could be it more flexible to attach that to a backend structure at
> this point and make manipulations of this number through the core
> backend, reducing TRY/CATCH blocks required in extension code?

+1

I think tracking nesting level in core would make a lot of sense -
I've noticed this too that extensions (pg_wait_sampling, pg_qualstats,
pg_stat_plans, etc) seem to keep re-inventing this, and I assume the
definition of this would be the same across extensions.

Not sure if you already had a place in mind, but thinking through
where we could attach it, I realized two things:

1) QueryDesc seems like a reasonable struct to communicate nesting
level (since it gets passed to the relevant executor hooks already),
but that doesn't get passed to ProcessUtility today
2) ProcessUtility has an existing indicator for top-level statements
in ProcessUtilityContext (PROCESS_UTILITY_TOPLEVEL)

Were you thinking of actually using a backend struct (i.e.
PgBackendStatus) and keep changing that as we run through the
different execution levels, and exposing a helper function to retrieve
it?

Thanks,
Lukas

--
Lukas Fittl

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2026-01-20 21:32:31 Re: Mystery with REVOKE PRIVILEGE
Previous Message Peter Smith 2026-01-20 21:20:33 Re: Proposal: Conflict log history table for Logical Replication