Re: Convincing STABLE functions to run once

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Convincing STABLE functions to run once
Дата
Msg-id 9740.1410276996@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Convincing STABLE functions to run once  (Dan Wells <dbw2@calvin.edu>)
Список pgsql-general
Dan Wells <dbw2@calvin.edu> writes:
> I've run into this issue in several contexts recently, and wonder if
> folks here can help clear up my understanding of function volatility.  I
> often have functions which are not truly immutable (they do something
> minor, like read in configuration information), but the functions
> themselves are fairly expensive, so I want them to run just once per
> query.  At face value, I feel like STABLE should do what I want, but
> often it does not.

STABLE tells the system it's *okay* to run the function fewer times than
naive SQL semantics might suggest.  There's no *guarantee* that any such
optimization will happen (and in fact, about the only special thing that
currently happens for STABLE functions is that they're considered okay
to use in indexscan qualifications).

What I'd suggest is sticking the expensive function call into a CTE
(a WITH clause).  We do guarantee only-once eval for CTEs.

            regards, tom lane


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

Предыдущее
От: Lou Oquin
Дата:
Сообщение: Re: Issue with to_timestamp function
Следующее
От: John R Pierce
Дата:
Сообщение: Re: stackbuilder