Re: Function use in query

Поиск
Список
Период
Сортировка
От David Johnston
Тема Re: Function use in query
Дата
Msg-id 1370528625081-5758159.post@n5.nabble.com
обсуждение исходный текст
Ответ на Re: Function use in query  (Ioana Danes <ioanasoftware@yahoo.ca>)
Ответы Re: Function use in query  (Ioana Danes <ioanasoftware@yahoo.ca>)
Список pgsql-general
Ioana Danes wrote
>
> If I will have to filter the  tmp_Cashdrawer table then it executes the
> function for the all the cash drawers and then filter out the result which
> again is not efficient...

Hm????

SELECT function_call(...)
FROM tbl
WHERE tbl.pk = ...;

That should only cause function_call to execute a single time.  If it is not
I'd suggest providing the actual query as well as the "EXPLAIN" plan for it.
It is possible that making the function "cost more" might be necessary but
doubtful.

You can force the table filter to be executed first by using a simple
sub-select:

SELECT function_call(...)
FROM (SELECT * FROM tbl WHERE tbl.pk = ...) filtered_tbl;

Though it is possible the planner would re-arrange this to the simple form
and still cause a problem.  Explain is your friend.

Combine that with the "WITH" if you need to expand the results of
function_call without causing it to execute multiple times - once for each
column being expanded.

David J.






--
View this message in context: http://postgresql.1045698.n5.nabble.com/Function-use-in-query-tp5758051p5758159.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.


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

Предыдущее
От: Ioana Danes
Дата:
Сообщение: Re: Function use in query
Следующее
От: François Beausoleil
Дата:
Сообщение: User postgres unable to revoke privileges?