| От | Tom Lane |
|---|---|
| Тема | Re: function not called if part of aggregate |
| Дата | |
| Msg-id | 18419.1150047570@sss.pgh.pa.us обсуждение исходный текст |
| Ответ на | function not called if part of aggregate ("Craig A. James" <cjames@modgraph-usa.com>) |
| Список | pgsql-performance |
"Craig A. James" <cjames@modgraph-usa.com> writes:
> select count(1) from (select foo_init(value) from foo_init_table order by value_id) as foo;
> And indeed, it count() returns 800, as expected. But my function foo_init() never gets called!
Really? With the ORDER BY in there, it does get called, in my
experiments. What PG version is this exactly?
However, the short answer to your question is that PG does not guarantee
to evaluate parts of the query not needed to determine the result. You
could do something like
select count(x) from (select foo_init(value) as x from foo_init_table order by value_id) as foo;
to ensure that foo_init() must be evaluated.
regards, tom lane
В списке pgsql-performance по дате отправления:
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера