Re: BUG #2150: PL/Python function delcared STABLE gets run repeatedly

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: BUG #2150: PL/Python function delcared STABLE gets run repeatedly
Дата
Msg-id 24773.1136569386@sss.pgh.pa.us
обсуждение исходный текст
Ответ на BUG #2150: PL/Python function delcared STABLE gets run repeatedly  ("Aaron Swartz" <me@aaronsw.com>)
Ответы Re: BUG #2150: PL/Python function delcared STABLE gets run repeatedly  ("Jim C. Nasby" <jnasby@pervasive.com>)
Список pgsql-bugs
Aaron Swartz <me@aaronsw.com> writes:
> The function we're running returns an array, and it is non-trivial to
> compute. We do a simple query with it like "SELECT * FROM
> tablename WHERE id = any(foo(21))").

> When the function is STABLE (or VOLATILE) the function is run
> to generate the array every time. If the function is IMMUTABLE,
> the array is computed only once for this query, as we'd expect,
> and the query is fast.

Oh, you are misunderstanding the point of IMMUTABLE/STABLE.
STABLE essentially gives the planner permission to use the function
in an indexscan qualification.  It does *not* cause any caching of
the function result in other contexts, which is what you seem to be
wishing would happen.

IMMUTABLE/STABLE/VOLATILE are promises from you to the system about
the behavior of the function, not promises from the system about
how it will choose to evaluate the function.

What I'd suggest is recasting the function to return a SETOF result
instead of an array, and then writing

SELECT * FROM tablename WHERE id IN (select * from foo(21))

This should get you a plan that will work reasonably well for you.

            regards, tom lane

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

Предыдущее
От: Jaime Casanova
Дата:
Сообщение: Re: BUG #2152: psql crash reproducible
Следующее
От: Tom Lane
Дата:
Сообщение: Re: [GENERAL] Problems building pg 8.1.1