From: | "Andrei Bintintan" <klodoma(at)ar-sd(dot)net> |
---|---|
To: | <pgsql-sql(at)postgresql(dot)org> |
Subject: | SQL timestamp to date cast |
Date: | 2005-01-20 08:52:50 |
Message-ID: | 006b01c4fecd$6d37c9e0$0b00a8c0@forge |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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.
From | Date | Subject | |
---|---|---|---|
Next Message | Michael Fuhr | 2005-01-20 09:33:31 | Re: SQL timestamp to date cast |
Previous Message | Benjamin Wragg | 2005-01-20 04:05:09 | Query performance and understanding explain analzye |