Re: Seq scan vs. Index scan with different query conditions

From: Richard Huxton <dev(at)archonet(dot)com>
To: eleven(at)ludojad(dot)itpp(dot)pl
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: Seq scan vs. Index scan with different query conditions
Date: 2004-07-05 11:41:16
Message-ID: 40E93E5C.1000907@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

eleven(at)ludojad(dot)itpp(dot)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

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Andrew McMillan 2004-07-05 11:44:13 Re: Seq scan vs. Index scan with different query
Previous Message eleven 2004-07-05 10:15:15 Seq scan vs. Index scan with different query conditions