| From: | Bruce Momjian <bruce(at)momjian(dot)us> | 
|---|---|
| To: | Chris Ruprecht <chris(at)cdrbill(dot)com> | 
| Cc: | Evgeny Shishkin <itparanoia(at)gmail(dot)com>, "pgsql-performance(at)postgresql(dot)org" <pgsql-performance(at)postgresql(dot)org> | 
| Subject: | Re: Have: Seq Scan - Want: Index Scan - what am I doing wrong? | 
| Date: | 2012-10-17 00:31:06 | 
| Message-ID: | 20121017003106.GI7480@momjian.us | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-performance | 
On Tue, Oct 16, 2012 at 08:19:43PM -0400, Chris Ruprecht wrote:
> 
> On Oct 16, 2012, at 20:01 , Evgeny Shishkin <itparanoia(at)gmail(dot)com> wrote:
> 
> > Selecting 5 yours of data is not selective at all, so postgres decides it is cheaper to do seqscan. 
> > 
> > Do you have an index on patient.dnsortpersonnumber? Can you post a result from 
> > select count(*) from patient where dnsortpersonnumber = '347450'; ?
> > 
> 
> Yes, there is an index:
> 
> "Aggregate  (cost=6427.06..6427.07 rows=1 width=0)"
> "  ->  Index Scan using patient_pracsortpatientnumber on patient  (cost=0.00..6427.06 rows=1 width=0)"
> "        Index Cond: (dnsortpersonnumber = '347450'::text)"
> 
> 
> In fact, all the other criteria is picked using an index. I fear that the >= and <= on the timestamp is causing the issue. If I do a "=" of just one of them, I get an index scan. But I need to scan the entire range. I get queries like "give me everything that was entered into the system for this patient between these two dates". A single date wouldn't work.
Have you read our FAQ on this matter?
http://wiki.postgresql.org/wiki/FAQ#Why_are_my_queries_slow.3F_Why_don.27t_they_use_my_indexes.3F
-- 
  Bruce Momjian  <bruce(at)momjian(dot)us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com
+ It's impossible for everything to be true. +
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Chris Ruprecht | 2012-10-17 00:43:00 | Re: Have: Seq Scan - Want: Index Scan - what am I doing wrong? | 
| Previous Message | Chris Ruprecht | 2012-10-17 00:19:43 | Re: Have: Seq Scan - Want: Index Scan - what am I doing wrong? |