Re: pg_stat_statements stores WITH HOLD cursor query with literals

From: Sami Imseih <samimseih(dot)pg(at)gmail(dot)com>
To: Lukas Fittl <lukas(at)fittl(dot)com>
Cc: Michael Paquier <michael(at)paquier(dot)xyz>, Gaurav Singh <gaurav(dot)singh(at)yugabyte(dot)com>, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: pg_stat_statements stores WITH HOLD cursor query with literals
Date: 2026-10-27 22:03:21
Message-ID: CAN12+Y+ZCk470o89Bjxx4HJNG2dO_=qmey+ibLLxvf8yHQoPgA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

> That said, I'm still not convinced that using this extensibility for
> tracking nesting level is the best approach, vs figuring a way in-core
> to pass the current nesting level to executor hooks. It seems every
> extension re-invents this, and keeps copying the same mistakes, e.g.
> I'm sure pg_stat_monitor, pg_stat_kcache and pg_stat_plans will need
> to solve this same tracking problem that is being talked about in this
> thread.

One point raised is that the two contrib extensions that currently keep a
nesting_level, auto_explain and pg_stat_statements, do not give it quite the
same meaning. They both bump it around ExecutorRun and ExecutorFinish, but
pg_stat_statements also bumps it around the planner and ProcessUtility calls.

For auto_explain, nesting_level == 0 is used at ExecutorStart and ExecutorEnd
as part of its sampling, instrumentation and logging decisions. If that value
also counted utility or planning nesting, auto_explain would start treating
some currently top-level plans, such as CREATE TABLE AS queries, as nested.

So at least for these two contrib modules, preserving the current behavior
would seem to require keeping the nesting decision decoupled from a single
shared nesting_level.

Those differences could perhaps be worked around, but each extension would
still need to decide what the value means for its own purposes, so they may
still need some form of queryDesc state.

--
Sami Imseih
Amazon Web Services (AWS)

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Michael Paquier 2026-10-27 23:35:06 Re: pg_stat_statements stores WITH HOLD cursor query with literals
Previous Message David Rowley 2026-10-27 20:11:18 Re: BUG #19759: Hashed SetOp / RecursiveUnion pre-allocate up to 64 GB from the row estimate since 8f29467c57f