Re: BUG #5293: constant function (date_trunc) is repeatedly evaluated inside loop

Поиск
Список
Период
Сортировка
От Kevin Grittner
Тема Re: BUG #5293: constant function (date_trunc) is repeatedly evaluated inside loop
Дата
Msg-id 4B56E329020000250002E88E@gw.wicourts.gov
обсуждение исходный текст
Ответ на BUG #5293: constant function (date_trunc) is repeatedly evaluated inside loop  ("Richard Neill" <rn214@cam.ac.uk>)
Список pgsql-bugs
Richard Neill <rn214@cam.ac.uk> wrote:

> #fast
> WHERE column <  '2010-010-20 00:00:00'
>
> #fast
> WHERE column <  date_trunc('day', timestamp with time zone
>                               '2010-01-20 10:16:55')
>
> #slow
> WHERE column <  date_trunc('day', timestamp
>                               '2010-01-20 10:16:55')
>
>
> Why is that, I wonder?

The column is timestamp with time zone, and the fast options
generate a value of the same type (the first because the literal is
treated as UNKNOWN type until the comparison).  It's generally a
good idea to use literals which match the type of the column.  How
much work it would be to optimize the slow case to insert a cast of
the date_trunc function return value to a different type before
entering the loop where the value is tested, I don't know offhand.

-Kevin

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

Предыдущее
От: "Kevin Grittner"
Дата:
Сообщение: Re: BUG #5292: Corrupted installer
Следующее
От: Richard Neill
Дата:
Сообщение: Re: BUG #5293: constant function (date_trunc) is repeatedly evaluated inside loop