Re: functions: VOLATILE performs better than STABLE

2018-04-05 Thread Merlin Moncure
On Sun, Mar 25, 2018 at 12:00 AM, Laurenz Albe wrote: > Peter wrote: >> Given an arbitrary function fn(x) returning numeric. >> >> Question: how often is the function executed? >> [...] >> C. >> select v.v,v.v from (select fn('const') as v) as v; >> >> Answer: >> Once if declared VOLATILE. >> Twic

Re: functions: VOLATILE performs better than STABLE

2018-03-25 Thread David Rowley
On 25 March 2018 at 18:00, Laurenz Albe wrote: > Peter wrote: >> Over all, VOLATILE performs better than STABLE. > > The reason is that the subquery with the VOLATILE function can be > flattened; see the EXPLAIN (VERBOSE) output. > > There is not guarantee that less volatility means better perform

Re: functions: VOLATILE performs better than STABLE

2018-03-24 Thread Laurenz Albe
Peter wrote: > Given an arbitrary function fn(x) returning numeric. > > Question: how often is the function executed? > [...] > C. > select v.v,v.v from (select fn('const') as v) as v; > > Answer: > Once if declared VOLATILE. > Twice if declared STABLE. > > Now this IS a surprize. It is clear th

functions: VOLATILE performs better than STABLE

2018-03-23 Thread Peter
Given an arbitrary function fn(x) returning numeric. Question: how often is the function executed? A. select fn('const'), fn('const'); Answer: Twice. This is not a surprize. B. select v,v from fn('const') as v; [1] Answer: Once. C. select v.v,v.v from (select fn('const') as v) as v;