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