From: | Jim Nasby <Jim(dot)Nasby(at)BlueTreble(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | Atri Sharma <atri(dot)jiit(at)gmail(dot)com>, David G Johnston <david(dot)g(dot)johnston(at)gmail(dot)com>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Re: Patch to add functionality to specify ORDER BY in CREATE FUNCTION for SRFs |
Date: | 2015-01-06 23:13:52 |
Message-ID: | 54AC6C30.7010504@BlueTreble.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On 1/5/15, 3:14 PM, Tom Lane wrote:
> Jim Nasby <Jim(dot)Nasby(at)bluetreble(dot)com> writes:
>> Related... I'd like to see a way to inline a function that does something like:
>
>> CREATE FUNCTION foo(text) RETURNS int LANGUAGE sql AS $$
>> SELECT a FROM b WHERE lower(b.c) = lower($1)
>> $$
>
> The reason that's not inlined ATM is that the semantics wouldn't be the
> same (ie, what happens if the SELECT returns more than one row). It's
> possible they would be the same if we attached a LIMIT 1 to the function's
> query, but I'm not 100% sure about that offhand. I'm also not real sure
> that you'd still get good performance if there were an inserted LIMIT;
> that would disable at least some optimizations.
In this case there's actually a unique index on lower(b.c). I don't know if the planner is smart enough to recognize that today though.
Perhaps a good interim solution would be a flag/option you could set on SQL functions to force (or disallow) inlining? That means if the option is set it's on the callers head if it doesn't do what's desired. We should throw an error if there's something about the function that would prevent inlining though.
--
Jim Nasby, Data Architect, Blue Treble Consulting
Data in Trouble? Get it in Treble! http://BlueTreble.com
From | Date | Subject | |
---|---|---|---|
Next Message | Jim Nasby | 2015-01-06 23:15:05 | Re: Re: Patch to add functionality to specify ORDER BY in CREATE FUNCTION for SRFs |
Previous Message | Alvaro Herrera | 2015-01-06 23:12:18 | Re: Updating copyright notices to 2015 for PGDG |