Re: Postgres inconsistent use of Index vs. Seq Scan

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Postgres inconsistent use of Index vs. Seq Scan
Дата
Msg-id 25960.1426284246@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Postgres inconsistent use of Index vs. Seq Scan  ("Jim Carroll" <jim@carroll.com>)
Список pgsql-performance
"Jim Carroll" <jim@carroll.com> writes:
> I'm having difficulty understanding what I perceive as an inconsistency in
> how the postgres parser chooses to use indices. We have a query based on NOT
> IN against an indexed column that the parser  executes sequentially, but
> when we perform the same query as IN, it uses the index.

What you've got here is a query that asks for all rows with vid <> 1.
Not-equals is not an indexable operator according to Postgres, and there
would not be much point in making it one, since it generally implies
having to scan the majority of the table.

If, indeed, 99% of your table has vid = 1, then there would be some point
in trying to use an index to find the other 1%; but you'll have to
formulate the query differently (perhaps "vid > 1" would do?) or else
use a properly-designed partial index.

            regards, tom lane


В списке pgsql-performance по дате отправления:

Предыдущее
От: Varadharajan Mukundan
Дата:
Сообщение: Re: Performance issues
Следующее
От: Scott Marlowe
Дата:
Сообщение: Re: Performance issues