[PERFORM] query - laziness of lateral join with function

2015-02-12 Thread paulcc
Hi I'm using cross join lateral with a non-trivial function in an attempt to limit calculation of that function, and am wondering about some aspects of how lateral is currently implemented. NB these queries are generated by a certain ORM, and are usually embedded in much more complex

Re: [PERFORM] query - laziness of lateral join with function

2015-02-12 Thread Tom Lane
paulcc paulcc@gmail.com writes: select count(alpha.id) from alpha cross join lateral some_function(alpha.id) as some_val where alpha.test Here the function is strict, and moreover its argument will never be null - hence there should always be a non-null value

Re: [PERFORM] query - laziness of lateral join with function

2015-02-12 Thread David G Johnston
Tom Lane-2 wrote paulcc lt; paulcc.two@ gt; writes: select count(alpha.id) from alpha cross join lateral some_function(alpha.id) as some_val where alpha.test Here the function is strict, and moreover its argument will never be null - hence there should always be a

Re: [PERFORM] query - laziness of lateral join with function

2015-02-12 Thread Paul Callaghan
On Feb 12, 2015 9:17 PM, Tom Lane t...@sss.pgh.pa.us wrote: The planner might produce such a result if there's an opportunity to perform the sorting via an index on alpha (ie, the ORDER BY matches some index). If it has to do an explicit sort it's gonna do the join first. (If you have such