SQL timestamp to date cast - Mailing list pgsql-sql

From Andrei Bintintan
Subject SQL timestamp to date cast
Date
Msg-id 006b01c4fecd$6d37c9e0$0b00a8c0@forge
Whole thread Raw
Responses Re: SQL timestamp to date cast
List 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 by date:

Previous
From: "Benjamin Wragg"
Date:
Subject: Query performance and understanding explain analzye
Next
From: Michael Fuhr
Date:
Subject: Re: SQL timestamp to date cast