pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Richard Huxton <dev@archonet.com>
To: eleven@ludojad.itpp.pl
Cc: pgsql-performance@postgresql.org
Subject: Re: Seq scan vs. Index scan with different query conditions
Date: Mon, 05 Jul 2004 12:41:16 +0100
Message-ID: <40E93E5C.1000907@archonet.com> (raw)
In-Reply-To: <20040705101515.GA12879@ludojad.itpp.pl>
References: <20040705101515.GA12879@ludojad.itpp.pl>

eleven@ludojad.itpp.pl wrote:

> ->  Index Scan using "DateTimeIndex" on "tablex"  (cost=0.00..298272.66 rows=89903 width=8)

> ->  Seq Scan on "tablex"  (cost=0.00..307137.34 rows=97900 width=8)

> Basically, the difference is in upper "Time" value (as you can see, it's
> 18:01:00 in the first query and 19:01:00 in the other one). 
> The question is - why does it use index in first case and 
> it tries to do full sequential scan when the upper "Time" value
> is different?

Look at the rows, and more importantly the cost. PG thinks the cost in 
the second case (seq scan) is only slightly more than in the first case 
(index), so presumably the index scan worked out more expensive.

You can test this by issuing "SET ENABLE_SEQSCAN=OFF;" and re-running 
the second explain.

Now, the question is whether PG is right in these cost estimates. You'll 
need to run "EXPLAIN ANALYSE" rather than just EXPLAIN to see what it 
actually costs.

PS - all the usual questions: make sure you've vacuumed, have you read 
the tuning document on varlena.com?

-- 
   Richard Huxton
   Archonet Ltd



view thread (5+ messages)  latest in thread

Message-ID: <40E93E5C.1000907@archonet.com>
Permalink:  ../40E93E5C.1000907@archonet.com/
Also on:    postgresql.org/message-id/40E93E5C.1000907@archonet.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: dev@archonet.com, eleven@ludojad.itpp.pl
  Subject: Re: Seq scan vs. Index scan with different query conditions
  In-Reply-To: <40E93E5C.1000907@archonet.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