Re: Re: Patch to add functionality to specify ORDER BY in CREATE FUNCTION for SRFs - Mailing list pgsql-hackers

From Jim Nasby
Subject Re: Re: Patch to add functionality to specify ORDER BY in CREATE FUNCTION for SRFs
Date
Msg-id 54AAFB3F.9080509@BlueTreble.com
Whole thread Raw
In response to Re: Re: Patch to add functionality to specify ORDER BY in CREATE FUNCTION for SRFs  (Atri Sharma <atri.jiit@gmail.com>)
Responses Re: Re: Patch to add functionality to specify ORDER BY in CREATE FUNCTION for SRFs
List pgsql-hackers
On 1/5/15, 12:20 PM, Atri Sharma wrote:
>     What would make sense to me is to teach the planner about inlining
>     SQL functions that include ORDER BY clauses, so that the performance
>     issue of a double sort could be avoided entirely transparently to
>     the user.
>
>
> It sounds good, but inlining in current way shall restrict the scope of optimization (which is not applicable for
currentdesign). For eg, you cannot inline RECORD returning SRFs...
 

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)
$$

and have the performance be comparable to

SELECT ..., (SELECT a FROM b WHERE lower(b.c) = lower(something)) AS foo

I realize that there's a whole question about the function not being an SRF, but the thing is this works great when
manuallyinlined and is fast. The SQL function is significantly slower.
 
-- 
Jim Nasby, Data Architect, Blue Treble Consulting
Data in Trouble? Get it in Treble! http://BlueTreble.com



pgsql-hackers by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: SSL information view
Next
From: Tom Lane
Date:
Subject: Re: Re: Patch to add functionality to specify ORDER BY in CREATE FUNCTION for SRFs