pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Ron <ronljohnsonjr@gmail.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: EXPLAIN with anonymous DO block?
Date: Thu, 01 Jul 2021 12:27:35 -0400
Message-ID: <699960.1625156855@sss.pgh.pa.us> (raw)
In-Reply-To: <a1a8a7f0-207f-2046-bb4a-348250bc08c0@gmail.com>
References: <a1a8a7f0-207f-2046-bb4a-348250bc08c0@gmail.com>

Ron <ronljohnsonjr@gmail.com> writes:
> There's a query inside a DO block which -- because it's parameterized -- I'd 
> rather analyze while it's in the FOR loop of a DO block, instead of pulling 
> it out and hard-coding the parameters.

> Is this possible?

No.

The thing to do to duplicate the behavior of a plpgsql query is
to set it up as a PREPAREd statement (with parameters for any
plpgsql variables it references) and use EXPLAIN EXECUTE.
This also works if you're curious about the behavior of a
query issued via PQexecParams or the like.

It's recommendable to repeat the EXPLAIN half a dozen times
to see if the plancache switches from a custom to a generic
plan.  (In recent PG releases, changing plan_cache_mode
is another way to check what happens.)

			regards, tom lane





view thread (5+ messages)  latest in thread

Message-ID: <699960.1625156855@sss.pgh.pa.us>
Permalink:  ../699960.1625156855@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/699960.1625156855@sss.pgh.pa.us

 · 

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-general@postgresql.org
  Cc: tgl@sss.pgh.pa.us, ronljohnsonjr@gmail.com
  Subject: Re: EXPLAIN with anonymous DO block?
  In-Reply-To: <699960.1625156855@sss.pgh.pa.us>
  References: <a1a8a7f0-207f-2046-bb4a-348250bc08c0@gmail.com> <699960.1625156855@sss.pgh.pa.us>

* 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