Re: Doesn't use index, why?

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Doesn't use index, why?
Дата
Msg-id 22047.978628338@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Doesn't use index, why?  (Marco Catunda <catunda@pobox.com>)
Список 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 по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Time Zone Query
Следующее
От: "Nathan Barnett"
Дата:
Сообщение: Index on Date_Trunc