pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Chris Ruprecht <chris@cdrbill.com>
To: Evgeny Shishkin <itparanoia@gmail.com>
Cc: pgsql-performance@postgresql.org <pgsql-performance@postgresql.org>
Subject: Re: Have: Seq Scan - Want: Index Scan - what am I doing wrong?
Date: Tue, 16 Oct 2012 20:19:43 -0400
Message-ID: <2A64CF51-CC89-4A0A-89CC-49D7ABFD4603@cdrbill.com> (raw)
In-Reply-To: <9BB26B73-2824-4C97-92B5-5E059108C071@gmail.com>
References: <91417DD6-C9FF-40EA-8EA9-87DF7E696927@cdrbill.com>
	<9BB26B73-2824-4C97-92B5-5E059108C071@gmail.com>


On Oct 16, 2012, at 20:01 , Evgeny Shishkin <itparanoia@gmail.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.



view thread (5+ messages)  latest in thread

Message-ID: <2A64CF51-CC89-4A0A-89CC-49D7ABFD4603@cdrbill.com>
Permalink:  ../2A64CF51-CC89-4A0A-89CC-49D7ABFD4603@cdrbill.com/
Also on:    postgresql.org/message-id/2A64CF51-CC89-4A0A-89CC-49D7ABFD4603@cdrbill.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: chris@cdrbill.com, itparanoia@gmail.com
  Subject: Re: Have: Seq Scan - Want: Index Scan - what am I doing wrong?
  In-Reply-To: <2A64CF51-CC89-4A0A-89CC-49D7ABFD4603@cdrbill.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox