Re: EXPLAIN with anonymous DO block? - Mailing list pgsql-general

From Tom Lane
Subject Re: EXPLAIN with anonymous DO block?
Date
Msg-id 699960.1625156855@sss.pgh.pa.us
Whole thread Raw
In response to EXPLAIN with anonymous DO block?  (Ron <ronljohnsonjr@gmail.com>)
Responses Re: EXPLAIN with anonymous DO block?  (Pavel Luzanov <p.luzanov@postgrespro.ru>)
List pgsql-general
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



pgsql-general by date:

Previous
From: Michael Lewis
Date:
Subject: Re: EXPLAIN with anonymous DO block?
Next
From: "David G. Johnston"
Date:
Subject: Re: EXPLAIN with anonymous DO block?