From: | Uros <uros(at)sir-mag(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Optimizing query |
Date: | 2003-11-19 12:25:46 |
Message-ID: | 1121228637937.20031119132546@sir-mag.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hello Shridhar,
I use Matthew's solution and it works. Query takes only half a second. I
didn't know that i can index function to.
Thanks
Uros
Wednesday, November 19, 2003, 1:23:26 PM, you wrote:
SD> Uros wrote:
>> Hello!
>>
>> I have some trouble getting good results from my query.
>>
>> here is structure
>>
>> stat_views
>> id | integer
>> id_zone | integer
>> created | timestamp
>>
>>
>> I have btree index on created and also id and there is 1633832 records in
>> that table
>>
>> First of all I have to manualy set seq_scan to OFF because I always get
>> seq_scan. When i set it to off my explain show:
>>
>> explain SELECT count(*) as views FROM stat_views WHERE id = 12;
>> QUERY PLAN
>> ----------------------------------------------------------------------------------------------------
>> Aggregate (cost=122734.86..122734.86 rows=1 width=0)
>> -> Index Scan using stat_views_id_idx on stat_views
>> (cost=0.00..122632.60 rows=40904 width=0)
>> Index Cond: (id = 12)
>>
>> But what I need is to count views for some day, so I use
>>
>> explain SELECT count(*) as views FROM stat_views WHERE date_part('day', created) = 18;
>>
>> QUERY PLAN
>> ------------------------------------------------------------------------------------
>> Aggregate (cost=100101618.08..100101618.08 rows=1 width=0)
>> -> Seq Scan on stat_views (cost=100000000.00..100101565.62 rows=20984 width=0)
>> Filter: (date_part('day'::text, created) = 18::double precision)
>>
>>
>> How can I make this to use index and speed the query. Now it takes about 12
>> seconds.
SD> Can you post explain analyze for the same?
SD> Shridhar
From | Date | Subject | |
---|---|---|---|
Next Message | Dave Cramer | 2003-11-19 13:32:36 | Re: Point-in-time data recovery - v.7.4 |
Previous Message | Shridhar Daithankar | 2003-11-19 12:23:26 | Re: Optimizing query |