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 1uezz0-000mWh-Kx for pgsql-hackers@arkaria.postgresql.org; Thu, 24 Jul 2025 17:43:55 +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 1uezyz-009U3q-Ed for pgsql-hackers@arkaria.postgresql.org; Thu, 24 Jul 2025 17:43:53 +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 1uezyz-009U3h-5A for pgsql-hackers@lists.postgresql.org; Thu, 24 Jul 2025 17:43:53 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uezyx-000aaA-2W for pgsql-hackers@postgresql.org; Thu, 24 Jul 2025 17:43:52 +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 56OHhlDn1673685; Thu, 24 Jul 2025 13:43:47 -0400 From: Tom Lane To: Sami Imseih cc: Andrei Lepikhov , Michael Paquier , Greg Sabino Mullane , pgsql-hackers , Nikolay Samokhvalov , Ilia Evdokimov Subject: Re: track generic and custom plans in pg_stat_statements In-reply-to: References: <2f2bde53-972d-402c-9da3-c5467cca00bf@gmail.com> <064b9efd-92c9-4670-95f4-d911d4c7ddeb@gmail.com> <1647760.1753369510@sss.pgh.pa.us> Comments: In-reply-to Sami Imseih message dated "Thu, 24 Jul 2025 11:52:28 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1673683.1753379027.1@sss.pgh.pa.us> Date: Thu, 24 Jul 2025 13:43:47 -0400 Message-ID: <1673684.1753379027@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Sami Imseih writes: >> That is not to say that I think 719dcf3c4 was a good idea: it looks >> rather useless from here. It seems to me that the right place to >> accumulate these sorts of stats is in CachedPlanSources, and I don't >> see how this helps. What likely *would* help is some hooks in >> plancache.c for pg_stat_statements to connect into so it can count > One possible hook for accumulating custom and generic plans per > queryId would be inside GetCachedPlan. However, this would require > calling pgss_store an extra time, in addition to ExecutorEnd, every time > GetCachedPlan is executed, which could introduce non-negligible > overhead. Only if you insist that the way to handle this is to call pgss_store at that time. I'd be inclined to think about having some transient process-local data structure that can remember the info until ExecutorEnd. But the plan tree is not the right place, because of the circularity problem. regards, tom lane