Re: Short-circuit boolean evaluation

Поиск
Список
Период
Сортировка
От Jasen Betts
Тема Re: Short-circuit boolean evaluation
Дата
Msg-id ipjjjv$a9t$1@reversiblemaps.ath.cx
обсуждение исходный текст
Ответ на Short-circuit boolean evaluation  (Jon Smark <jon.smark@yahoo.com>)
Список pgsql-general
On 2011-04-30, Jon Smark <jon.smark@yahoo.com> wrote:
> Hi,
>
> Does Postgresql perform short-circuit boolean evaluation both in SQL
> and PL/pgSQL functions?

sometimes.

the planner will rearrange what you write,

for this reason it is very likely that

>  SELECT count(*) FROM foobar WHERE foobar.id = $1 AND do_stuff (foobar.name);

will perform as well as

   SELECT count(*) FROM foobar WHERE do_stuff (foobar.name) and foobar.id = $1;

because the planner will rewrite this 'bad version' to execute the
same as the good version.

If you have an index on foobar.id or on do_stuff(foobar.name) or on
both it might be used to speed up the query.

You can give the planner a hint as to how expensive each function is
when you define the function.

in general the planner will take care of it for you

if you want to control when the function gets called with a boolean
test consider using case.

--
⚂⚃ 100% natural

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

Предыдущее
От: Jasen Betts
Дата:
Сообщение: Re: Postgresql, PSN hack and table limits
Следующее
От: Stefan Keller
Дата:
Сообщение: Re: Values larger than 1/3 of a buffer page cannot be indexed (hstore)