Re: functions: VOLATILE performs better than STABLE

Поиск
Список
Период
Сортировка
От Laurenz Albe
Тема Re: functions: VOLATILE performs better than STABLE
Дата
Msg-id 1521954043.2350.15.camel@cybertec.at
обсуждение исходный текст
Ответ на functions: VOLATILE performs better than STABLE  (Peter <pmc@citylink.dinoex.sub.org>)
Ответы Re: functions: VOLATILE performs better than STABLE  (David Rowley <david.rowley@2ndquadrant.com>)
Re: functions: VOLATILE performs better than STABLE  (Merlin Moncure <mmoncure@gmail.com>)
Список pgsql-performance
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 that the system is not allowed to
> execute the function twice when declared VOLATILE. It IS ALLOWED to
> execute it twice when STABLE - but to what point, except prolonging
> execution time?
> 
> 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 performance.

Yours,
Laurenz Albe
-- 
Cybertec | https://www.cybertec-postgresql.com


В списке pgsql-performance по дате отправления:

Предыдущее
От: David Rowley
Дата:
Сообщение: Re: Slow planning time for custom function
Следующее
От: Laurenz Albe
Дата:
Сообщение: Re: Should from_collapse be switched off? (queries 10 times faster)