Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lyzrQ-0006Xj-4P for pgsql-general@arkaria.postgresql.org; Thu, 01 Jul 2021 16:48:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lyzrP-0006kt-51 for pgsql-general@arkaria.postgresql.org; Thu, 01 Jul 2021 16:48:19 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lyzrO-0006kg-P9 for pgsql-general@lists.postgresql.org; Thu, 01 Jul 2021 16:48:18 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by makus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lyzrJ-00059a-Cb for pgsql-general@lists.postgresql.org; Thu, 01 Jul 2021 16:48:17 +0000 Received: from [10.0.1.15] (unknown [188.123.231.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id 54DC021C05AC; Thu, 1 Jul 2021 19:48:11 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1625158091; bh=chpreolJQ/A76bsWI54LlbsETRaSBiqZLaJXr84jxoA=; h=Subject:To:Cc:References:From:Date:In-Reply-To; b=PnhagDejITOY6/BcgNYEbl7OSUWq5o+147MI1Ft0wuwgDxdcSm0vHjia2UC0aKpOo 3B4VSxMgfymqCph407jMTu5dL0jMA3caAXExCB8e7uglfiliFt0Gors4XBcviyjohG SdE7xCbew1k5nTWm/5NsMiBEWM5CNg17Av7yl2vc= Subject: Re: EXPLAIN with anonymous DO block? To: Tom Lane , Ron Cc: pgsql-general@lists.postgresql.org References: <699960.1625156855@sss.pgh.pa.us> From: Pavel Luzanov Message-ID: <5895ad95-20d0-2ee5-a0d1-9a2d77e6edfb@postgrespro.ru> Date: Thu, 1 Jul 2021 19:48:11 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <699960.1625156855@sss.pgh.pa.us> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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