Re: Lack of use of indexes - Mailing list pgsql-general

From Stephan Szabo
Subject Re: Lack of use of indexes
Date
Msg-id 20021122074034.A11910-100000@megazone23.bigpanda.com
Whole thread Raw
In response to Lack of use of indexes  (Don Isgitt <djisgitt@soundenergy.com>)
List pgsql-general
On Fri, 22 Nov 2002, Don Isgitt wrote:

> gds2=# select count(*) from lg;
>  count
> --------
>  138459
> (1 row)
>
> gds2=# explain select * from lg where state='NM';
> NOTICE:  QUERY PLAN:
>
> Seq Scan on lg  (cost=0.00..5885.77 rows=14890 width=73)
>
> EXPLAIN
>
> gds2=# explain select * from lg where section=14;
> NOTICE:  QUERY PLAN:
>
> Seq Scan on lg  (cost=0.00..5885.77 rows=3836 width=73)

My guess would be that if you turned off seq_scan (enable_seqscan=off)
and explained, you'd get a larger estimate for the cost of the index
scan.  Assuming those row estimates are correct and the width is around
73 and that the data isn't very clustered, it's probably guessing that
it's going to be reading most of the datafile anyway and so the sequence
scan is faster. If it gives a higher estimate, but a lower real time with
enable_seqscan=off your data might be more clustered than it seems to be
expecting or maybe the default cost for random page reads is higher than
necessary on your machine (there are some settings in postgresql.conf that
you can play with)


pgsql-general by date:

Previous
From: Scott Lamb
Date:
Subject: Re: View and primary key
Next
From: Brandon Craig Rhodes
Date:
Subject: Re: improving a badly optimized query