Re: Querying one partition in a function takes locks on all partitions - Mailing list pgsql-general

From Tom Lane
Subject Re: Querying one partition in a function takes locks on all partitions
Date
Msg-id 4119652.1743443913@sss.pgh.pa.us
Whole thread Raw
In response to Re: Querying one partition in a function takes locks on all partitions  (Laurenz Albe <laurenz.albe@cybertec.at>)
List pgsql-general
Laurenz Albe <laurenz.albe@cybertec.at> 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



pgsql-general by date:

Previous
From: Eden Aharoni
Date:
Subject: Re: [EXTERNAL] RDS IO Read time
Next
From: Christophe Pettus
Date:
Subject: Re: [EXTERNAL] RDS IO Read time