Re: Postgres inconsistent use of Index vs. Seq Scan - Mailing list pgsql-performance

From Tom Lane
Subject Re: Postgres inconsistent use of Index vs. Seq Scan
Date
Msg-id 25960.1426284246@sss.pgh.pa.us
Whole thread Raw
In response to Postgres inconsistent use of Index vs. Seq Scan  ("Jim Carroll" <jim@carroll.com>)
List 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 by date:

Previous
From: Varadharajan Mukundan
Date:
Subject: Re: Performance issues
Next
From: Scott Marlowe
Date:
Subject: Re: Performance issues