Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1ugI1Q-000nJQ-0G for pgsql-hackers@arkaria.postgresql.org; Mon, 28 Jul 2025 07:11:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1ugI1P-005U3I-2p for pgsql-hackers@arkaria.postgresql.org; Mon, 28 Jul 2025 07:11:43 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1ugI1O-005U2u-Pz for pgsql-hackers@lists.postgresql.org; Mon, 28 Jul 2025 07:11:43 +0000 Received: from mail.postgrespro.ru ([93.174.132.70]) by makus.postgresql.org with smtp (Exim 4.96) (envelope-from ) id 1ugI1N-001AMw-00 for pgsql-hackers@postgresql.org; Mon, 28 Jul 2025 07:11:42 +0000 Received: from [192.168.15.242] (unknown [80.251.191.198]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (Client did not present a certificate) (Authenticated sender: a.lepikhov@postgrespro.ru) by mail.postgrespro.ru (Postfix/587) with ESMTPSA id A58116024C; Mon, 28 Jul 2025 10:11:37 +0300 (MSK) Message-ID: Date: Mon, 28 Jul 2025 09:11:36 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: track generic and custom plans in pg_stat_statements To: Michael Paquier Cc: Sami Imseih , Tom Lane , Greg Sabino Mullane , pgsql-hackers , Nikolay Samokhvalov , Ilia Evdokimov References: <1647760.1753369510@sss.pgh.pa.us> <1673684.1753379027@sss.pgh.pa.us> <1933906.1753462272@sss.pgh.pa.us> Content-Language: en-US From: Andrei Lepikhov In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-KSMG-AntiPhishing: NotDetected X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 2.1.0.7854, bases: 2025/07/28 05:40:00 #27643190 X-KSMG-AntiVirus-Status: NotDetected, skipped X-KSMG-LinksScanning: not scanned, disabled by settings X-KSMG-Message-Action: skipped X-KSMG-Rule-ID: 1 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 28/7/2025 08:46, Michael Paquier wrote: > On Mon, Jul 28, 2025 at 08:41:29AM +0200, Andrei Lepikhov wrote: >> It looks good, but doesn't it seem too narrow? > > For the use case of the thread which is to count the number of custom > vs generic plans, it would be good enough. Sure, no objections. > >> This minor change allows an extension to track a specific query from >> the parse tree up to the end of execution and carry as much data as >> needed. The extension (pg_stat_statements as well) may add all the >> necessary data in the parse hook, planner hook, or any of the >> execution hooks. With a trivial naming convention, Extensible nodes of >> different extensions will not interfere. >> To identify the cached plan, the GetCachedPlan hook may be introduced. > > Without knowing the actual use cases where these additions can be > useful, introducing this extra amount of infrastructure may not be > justified. Just my 2c and my impressions after studying the whole > thread. The case is as I already described: in Postgres, extensions have no way to identify how their path hooks really influenced specific query plan and its execution. During planning, they have only a pointer to the Query structure, but at the end of execution, only a PlannedStmt is available. I propose improving this 'blind' approach to planning. The only argument I usually receive in response to such a proposal is to add a beneficial example. The current pg_stat_statements change may be a good example of the employment of such infrastructure, isn't it? -- regards, Andrei Lepikhov