SQL timestamp to date cast

Поиск
Список
Период
Сортировка
От Andrei Bintintan
Тема SQL timestamp to date cast
Дата
Msg-id 006b01c4fecd$6d37c9e0$0b00a8c0@forge
обсуждение исходный текст
Ответы Re: SQL timestamp to date cast  (Michael Fuhr <mike@fuhr.org>)
Список pgsql-sql
Hi,
 
I have the following query:
 
SELECT DISTINCT(nummer) FROM user_action WHERE datetime::date='11/11/2004' AND id_action IN (5,6,9)
 
Now, datetime has the type timestamp. How can I make an index or write different this query so that it runs faster? It really takes some time sometimes. Usually about 3-4secs. user_action has about 300k rows and increasing ~ 5-10k a day.
 
 
Explain analyze SELECT DISTINCT(nummer) FROM user_action WHERE datetime::date='11/11/2004' AND id_action IN (5,6,9)
 
Unique  (cost=18141.71..18143.72 rows=45 width=4) (actual time=418.122..418.340 rows=85 loops=1)
  ->  Sort  (cost=18141.71..18142.72 rows=402 width=4) (actual time=418.119..418.194 rows=192 loops=1)
        Sort Key: nummer
        ->  Seq Scan on user_action  (cost=0.00..18124.33 rows=402 width=4) (actual time=366.240..417.890 rows=192 loops=1)
              Filter: (((datetime)::date = '2004-11-11'::date) AND ((id_action = 5) OR (id_action = 6) OR (id_action = 9)))
Total runtime: 418.419 ms
 
Best regards.
Andy.

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

Предыдущее
От: "Benjamin Wragg"
Дата:
Сообщение: Query performance and understanding explain analzye
Следующее
От: Michael Fuhr
Дата:
Сообщение: Re: SQL timestamp to date cast