Re: "Interesting" query planning for timestamp ranges in where clause?

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: "Interesting" query planning for timestamp ranges in where clause?
Дата
Msg-id 16816.1087359660@sss.pgh.pa.us
обсуждение исходный текст
Ответ на "Interesting" query planning for timestamp ranges in where clause?  (rvigmbdc@umail.furryterror.org (Zygo Blaxell))
Список pgsql-general
rvigmbdc@umail.furryterror.org (Zygo Blaxell) writes:
>  Column |              Type              | Modifiers | Description
> --------+--------------------------------+-----------+-------------
>  t      | timestamp(0) without time zone | not null  |
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

> ilt=# explain analyze select time_bucket(t, 32), avg(t1), avg(t2), avg(t3), avg(t4), avg(t5), avg(t6), avg(t7),
avg(t8)from temp where t between now() - interval '1 day' and now() group by time_bucket(t, 32) order by time_bucket(t,
32)desc; 

>          ->  Seq Scan on "temp"  (cost=0.00..207797.15 rows=30620 width=72) (actual time=35275.231..38323.524
rows=85360loops=1) 
>                Filter: (((t)::timestamp with time zone >= (now() - '1 day'::interval)) AND ((t)::timestamp with time
zone<= now())) 
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This is ye olde bog-standard "can't index a cross-datatype comparison"
problem.  Personally I think you probably want your t column to be
timestamp with tz --- it's highly annoying that the SQL spec says
unadorned "timestamp" must mean "timestamp without time zone".
But if you really want it without tz, cast the result of now() to
timestamp without tz, or use LOCALTIMESTAMP instead of now().

            regards, tom lane

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

Предыдущее
От: Bruce Momjian
Дата:
Сообщение: Re: building 7.4.3 on Solaris 9/Intel
Следующее
От: Jernej Kos
Дата:
Сообщение: Multicolumn indexes and ORDER BY