Re: [PERFORM] optimizing immutable vs. stable function calls?

Поиск
Список
Период
Сортировка
От David G. Johnston
Тема Re: [PERFORM] optimizing immutable vs. stable function calls?
Дата
Msg-id CAKFQuwY-tztAzdaBNZR_uwiQnj1Ovbtd6-6uHQ57k8rXPrR+Nw@mail.gmail.com
обсуждение исходный текст
Ответ на Re: [PERFORM] optimizing immutable vs. stable function calls?  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: [PERFORM] optimizing immutable vs. stable function calls?  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-performance
On Wed, Jan 18, 2017 at 3:54 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Karl Czajkowski <karlcz@isi.edu> writes:
> The query planner does not seem to
> recognize that it can eliminate redundant calls to a STABLE function.

No, it doesn't.

> In my case, the function call does not take any arguments and is thus
> trivially independent of row data, and appears in a WHERE clause being
> compared to constants. Why wouldn't the optimizer treat this case the
> same as IMMUTABLE?

"The same as IMMUTABLE" would be to reduce the function to a constant at
plan time, which would be the wrong thing.  It would be valid to execute
it only once at query start, but there's no built-in mechanism for that.

​I'm feeling a bit dense here but even after having read a number of these kinds of interchanges I still can't get it to stick.  I think part of the problem is this sentence from the docs:


(Stable): "​This category allows the optimizer to optimize multiple calls of the function to a single call"

I read that sentence (and the surrounding paragraph) and wonder why then doesn't it do so in this case.

If PostgreSQL cannot execute it only once at query start then all this talk about optimization seems misleading.  At worse there should be an sentence explaining when the optimizations noted in that paragraph cannot occur - and probably examples of both as well since its not clear when it can occur.

Some TLC to the docs here would be welcomed.

David J.

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

Предыдущее
От: Karl Czajkowski
Дата:
Сообщение: Re: [PERFORM] optimizing immutable vs. stable function calls?
Следующее
От: Tom Lane
Дата:
Сообщение: Re: [PERFORM] optimizing immutable vs. stable function calls?