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 1lyzXU-0005xU-7G for pgsql-general@arkaria.postgresql.org; Thu, 01 Jul 2021 16:27:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lyzXQ-00085S-IQ for pgsql-general@arkaria.postgresql.org; Thu, 01 Jul 2021 16:27:40 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lyzXQ-00084b-9r for pgsql-general@lists.postgresql.org; Thu, 01 Jul 2021 16:27:40 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lyzXO-00015o-2r for pgsql-general@lists.postgresql.org; Thu, 01 Jul 2021 16:27:39 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 161GRZUG699961; Thu, 1 Jul 2021 12:27:35 -0400 From: Tom Lane To: Ron cc: pgsql-general@lists.postgresql.org Subject: Re: EXPLAIN with anonymous DO block? In-reply-to: References: Comments: In-reply-to Ron message dated "Thu, 01 Jul 2021 11:16:25 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <699959.1625156855.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Thu, 01 Jul 2021 12:27:35 -0400 Message-ID: <699960.1625156855@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Ron 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 pull= ing = > 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