Re: Doesn't use index, why? - Mailing list pgsql-general

From Tom Lane
Subject Re: Doesn't use index, why?
Date
Msg-id 22047.978628338@sss.pgh.pa.us
Whole thread Raw
In response to Doesn't use index, why?  (Marco Catunda <catunda@pobox.com>)
List pgsql-general
Marco Catunda <catunda@pobox.com> writes:
>     naslog=# explain select * from desconexao where time = '2000-12-01';
>     NOTICE:  QUERY PLAN:

>     Index Scan using time_idx on desconexao  (cost=0.00..20.18 rows=5
>     width=103)

>     naslog=# explain select * from desconexao where time > '2000-12-01';
>     NOTICE:  QUERY PLAN:

>     Seq Scan on desconexao  (cost=0.00..19547.71 rows=657958 width=103)

> Why postgresql didn't use the time_idx index? I only changed the
> operator "=" to ">" in clause "where".

Because the '>' condition is much less restrictive (notice the
difference in estimated row counts: 5 versus 657958).  Unless the
planner's row count estimates are way off, it very likely *is* faster
to do the second query by sequential scan.

            regards, tom lane

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Time Zone Query
Next
From: "Nathan Barnett"
Date:
Subject: Index on Date_Trunc