Re: Querying one partition in a function takes locks on all partitions

From: Renan Alves Fonseca <renanfonseca(at)gmail(dot)com>
To: David Rowley <dgrowleyml(at)gmail(dot)com>
Cc: Evgeny Morozov <postgresql4(at)realityexists(dot)net>, pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Querying one partition in a function takes locks on all partitions
Date: 2025-03-31 16:41:54
Message-ID: CAN_p2QjXkBzyx55QAEGLfvWF0_UdusvxNmTykq_6jQsaaqjwTw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Mar 31, 2025 at 5:10 AM David Rowley <dgrowleyml(at)gmail(dot)com> wrote:
>
> On Sat, 29 Mar 2025 at 10:30, Renan Alves Fonseca
> <renanfonseca(at)gmail(dot)com> wrote:
> > Currently, in the SQL function path the plan is always generic. The
> > planner ignores the function arguments. The plan_cache_mode setting
> > has no effect in this path.
> >
> > I agree that the docs should be more explicit about this. There is a
> > high penalty for using generic plans in complex functions.
>
> If you have any suggestions about where you think those should be
> added or wording for that, please feel free to suggest.
>

There is a specific chapter about functions written in SQL: [1]. It is
in an advanced section of the docs, so I think it is a suitable place
to address this level of detail.

There is a Note that says: "The entire body of an SQL function is
parsed before any of it is executed. While an SQL function can contain
commands that alter ..."
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."

I'm not sure if we should mention the fix or if we should mention a
workaround...

If I understood well [2], then both notes may be discarded together in
the next version.

Renan

[1] https://www.postgresql.org/docs/17/xfunc-sql.html
[2] https://www.postgresql.org/message-id/db42573039cc66815e80a48589eebea8%40postgrespro.ru

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Laurenz Albe 2025-03-31 17:08:02 Re: Querying one partition in a function takes locks on all partitions
Previous Message Christophe Pettus 2025-03-31 15:15:39 Re: RDS IO Read time