From: Pavel Luzanov <p.luzanov@postgrespro.ru>
To: 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, 1 Jul 2021 19:48:11 +0300
Message-ID: <5895ad95-20d0-2ee5-a0d1-9a2d77e6edfb@postgrespro.ru> (raw)
In-Reply-To: <699960.1625156855@sss.pgh.pa.us>
References: <a1a8a7f0-207f-2046-bb4a-348250bc08c0@gmail.com>
<699960.1625156855@sss.pgh.pa.us>
Good day!
>> 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.
Why not to use auto_explain module?
postgres=# LOAD 'auto_explain';
LOAD
postgres=# SET auto_explain.log_min_duration = 0;
SET
postgres=# SET auto_explain.log_nested_statements = on;
SET
postgres=# SET auto_explain.log_analyze = on;
SET
postgres=# SET auto_explain.log_level = 'NOTICE';
SET
postgres=# DO $$BEGIN FOR i IN 112 .. 113 LOOP PERFORM * FROM pg_class
WHERE oid = i::oid; END LOOP; END;$$;
NOTICE: duration: 0.013 ms plan:
Query Text: SELECT * FROM pg_class WHERE oid = i::oid
Index Scan using pg_class_oid_index on pg_class (cost=0.27..8.29 rows=1
width=265) (actual time=0.009..0.011 rows=1 loops=1)
Index Cond: (oid = '112'::oid)
NOTICE: duration: 0.016 ms plan:
Query Text: SELECT * FROM pg_class WHERE oid = i::oid
Index Scan using pg_class_oid_index on pg_class (cost=0.27..8.29 rows=1
width=265) (actual time=0.008..0.009 rows=1 loops=1)
Index Cond: (oid = '113'::oid)
DO
Pavel Luzanov
Postgres Professional: https://postgrespro.com
The Russian Postgres Company
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: p.luzanov@postgrespro.ru, tgl@sss.pgh.pa.us, ronljohnsonjr@gmail.com
Subject: Re: EXPLAIN with anonymous DO block?
In-Reply-To: <5895ad95-20d0-2ee5-a0d1-9a2d77e6edfb@postgrespro.ru>
References: <a1a8a7f0-207f-2046-bb4a-348250bc08c0@gmail.com> <699960.1625156855@sss.pgh.pa.us> <5895ad95-20d0-2ee5-a0d1-9a2d77e6edfb@postgrespro.ru>
* 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