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 1tzJPE-000ebZ-AS for pgsql-general@arkaria.postgresql.org; Mon, 31 Mar 2025 17:58:40 +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 1tzJPC-009mPM-Qx for pgsql-general@arkaria.postgresql.org; Mon, 31 Mar 2025 17:58:38 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tzJPC-009mPD-FK for pgsql-general@lists.postgresql.org; Mon, 31 Mar 2025 17:58:38 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tzJPA-002GwZ-0x for pgsql-general@postgresql.org; Mon, 31 Mar 2025 17:58:38 +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 52VHwXdE4119653; Mon, 31 Mar 2025 13:58:33 -0400 From: Tom Lane To: Laurenz Albe cc: Renan Alves Fonseca , David Rowley , Evgeny Morozov , pgsql-general Subject: Re: Querying one partition in a function takes locks on all partitions In-reply-to: References: <01020195b987abd3-a008b77d-8c63-4931-80a4-be36a351c8b2-000000@eu-west-1.amazonses.com> <01020195dd9e8337-c912f36d-54ef-4d3c-a00d-5e697b308d33-000000@eu-west-1.amazonses.com> Comments: In-reply-to Laurenz Albe message dated "Mon, 31 Mar 2025 19:08:02 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <4119651.1743443913.1@sss.pgh.pa.us> Date: Mon, 31 Mar 2025 13:58:33 -0400 Message-ID: <4119652.1743443913@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Laurenz Albe writes: > On Mon, 2025-03-31 at 18:41 +0200, Renan Alves Fonseca wrote: >> I would add another Note below like: >> "Except when inlined, an SQL function is always executed with a >> generic plan. This behavior may not be desired in some situations, and >> it will be fixed in future versions." > But that is not true, as far as I can tell: just like any other prepared > statement, it may keep using custom plans. No, it is a generic plan in the current code. See functions.c's init_execution_state, which calls pg_plan_query without passing any boundParams. That's kind of necessary in the current scheme of things, because the SQL function holds onto the plan for the duration of the current query and re-uses the plan during subsequent calls with (possibly) different parameter values. So it's sort of a poor man's plan cache, but implemented in about the stupidest way possible. Jacking that up and rolling the plancache.c infrastructure underneath has been on my to-do list for years. regards, tom lane