| От | Tom Lane |
|---|---|
| Тема | Re: Avoiding evaluating functions twice. |
| Дата | |
| Msg-id | 8569.1128439517@sss.pgh.pa.us обсуждение исходный текст |
| Ответ на | Avoiding evaluating functions twice. (han.holl@informationslogik.nl) |
| Ответы |
Re: Avoiding evaluating functions twice.
|
| Список | pgsql-general |
han.holl@informationslogik.nl writes:
> select expensive_function(table) from table
> where expensive_function(table) is not null;
> Is there a way to avoid that expensive_function is evaluated twice (if it's
> not null) ?
You can do something like this:
select f from
(select expensive_function(table) as f from table offset 0) ss
where f is not null;
The "offset 0" bit is a hack that keeps the planner from flattening the
sub-select into the upper query, which would result in two copies of the
function expression, which is what you want to avoid.
regards, tom lane
В списке pgsql-general по дате отправления:
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера