On 1/5/15, 3:14 PM, Tom Lane wrote:
Jim Nasby <jim.na...@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 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
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers