Re: EXPLAIN with anonymous DO block?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Ron <ronljohnsonjr(at)gmail(dot)com>
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: EXPLAIN with anonymous DO block?
Date: 2021-07-01 16:27:35
Message-ID: 699960.1625156855@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Ron <ronljohnsonjr(at)gmail(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2021-07-01 16:28:54 Re: EXPLAIN with anonymous DO block?
Previous Message Michael Lewis 2021-07-01 16:21:39 Re: EXPLAIN with anonymous DO block?