Re: index scan on =, but not < ? - Mailing list pgsql-performance

From Dennis Bjorklund
Subject Re: index scan on =, but not < ?
Date
Msg-id Pine.LNX.4.44.0503082001170.2297-100000@zigo.dhs.org
Whole thread Raw
In response to index scan on =, but not < ?  ("Rick Schumeyer" <rschumeyer@ieee.org>)
List pgsql-performance
On Tue, 8 Mar 2005, Rick Schumeyer wrote:

> =# explain select * from data where x = 0;
> -------------------------------------------------------------------------
>  Index Scan using data_x_ix on data  (cost=0.00..78.25 rows=19 width=34)
>    Index Cond: (x = 0::double precision)
>
> But this command, in which the only difference if > instead of =, is a
> sequential scan.
>
> =# explain select * from data where x > 0;
> ------------------------------------------------------------------
>  Seq Scan on data  (cost=0.00..1722605.20 rows=62350411 width=34)
>    Filter: (x > 0::double precision)
>
> Why is this?

That is because it's faster to execute the x>0 query with a seq. scan then
a index scan. Postgresql is doing the right thing here.

Pg estimates that the first query will return 19 rows and that the second
query will return 62350411 rows. To return 62350411 rows it's faster to
just scan the table and not use the index.

--
/Dennis Björklund


pgsql-performance by date:

Previous
From: "Rick Schumeyer"
Date:
Subject: Re: index scan on =, but not < ?
Next
From: Richard Huxton
Date:
Subject: Re: bad plan