Re: index scan on =, but not < ?

From: Dennis Bjorklund <db(at)zigo(dot)dhs(dot)org>
To: Rick Schumeyer <rschumeyer(at)ieee(dot)org>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: index scan on =, but not < ?
Date: 2005-03-08 19:04:55
Message-ID: Pine.LNX.4.44.0503082001170.2297-100000@zigo.dhs.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Richard Huxton 2005-03-08 19:20:22 Re: bad plan
Previous Message Rick Schumeyer 2005-03-08 19:02:50 Re: index scan on =, but not < ?