Re: Re: Patch to add functionality to specify ORDER BY in CREATE FUNCTION for SRFs
От | Jim Nasby |
---|---|
Тема | Re: Re: Patch to add functionality to specify ORDER BY in CREATE FUNCTION for SRFs |
Дата | |
Msg-id | 54AC6C30.7010504@BlueTreble.com обсуждение исходный текст |
Ответ на | Re: Re: Patch to add functionality to specify ORDER BY in CREATE FUNCTION for SRFs (Tom Lane <tgl@sss.pgh.pa.us>) |
Список | pgsql-hackers |
On 1/5/15, 3:14 PM, Tom Lane wrote: > Jim Nasby <Jim.Nasby@bluetreble.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 thattoday though. Perhaps a good interim solution would be a flag/option you could set on SQL functions to force (or disallow) inlining? Thatmeans 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'ssomething 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
В списке pgsql-hackers по дате отправления: