Re: Is there a way around function search_path killing SQL function inlining?

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Regina Obe <lr(at)pcorp(dot)us>, Andreas Karlsson <andreas(at)proxel(dot)se>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Is there a way around function search_path killing SQL function inlining?
Date: 2016-08-12 18:52:25
Message-ID: CA+TgmobynOK-j5v-ZL18mRsVkH5s_vA65Zj-uctEu-QJG7tLfg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Mar 10, 2016 at 11:48 AM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Robert Haas <robertmhaas(at)gmail(dot)com> writes:
>> Hmm. The meaning of funcs.inline depends on the search_path, not just
>> during dump restoration but all the time. So anything uses it under a
>> different search_path setting than the normal one will have this kind
>> of problem; not just dump/restore.
>
> Yeah, I see no reason to claim that this is a dump/restore-specific
> problem.
>
>> I don't have a very good idea what to do about that.
>
> The safe way to write SQL-language functions to be search-path-proof
> is to schema-qualify the names in them, or to add a "SET search_path"
> clause to the function definition.
>
> The problem with the latter approach is that it defeats inlining.
> I thought for a minute that maybe we could teach the planner to do
> inlining anyway by parsing the function body with the adjusted
> search_path, but that doesn't really preserve the same semantics
> (a SET would change the environment for called functions too).

Let's introduce a new variant of SET that only affects the lexical
scope of the function to which it is attached, and then do what you
said. That would be full of win, because actually I think in nearly
every case that's the behavior people actually want. There's a reason
why (for example) Perl started out with dynamic scoping (local) and
then eventually introduced lexical scoping (my): it's because lexical
scoping makes writing correct programs easier to a greater degree than
dynamic scoping. That's basically the same problem we're hitting here
- and not only here.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2016-08-12 18:53:48 Re: No longer possible to query catalogs for index capabilities?
Previous Message Tom Lane 2016-08-12 18:40:11 Re: Add hint for function named "is"