Re: will the planner ever use an index when the condition is <> ? - Mailing list pgsql-performance

From Tom Lane
Subject Re: will the planner ever use an index when the condition is <> ?
Date
Msg-id 3088.1324233086@sss.pgh.pa.us
Whole thread Raw
In response to Re: will the planner ever use an index when the condition is <> ?  (Roxanne Reid-Bennett <rox@tara-lu.com>)
Responses Re: will the planner ever use an index when the condition is <> ?  (Roxanne Reid-Bennett <rox@tara-lu.com>)
List pgsql-performance
Roxanne Reid-Bennett <rox@tara-lu.com> writes:
> On 12/17/2011 11:24 AM, Filip Rembiałkowski wrote:
>> Normally there is no chance it could work,
>> because (a) the planner does not know all possible values of a column,
>> and (b) btree indexes cannot search on "not equal" operator.

> Is there an index type that can check "not equal"?

There is not.  It's not so much that it's logically impossible as that
it doesn't seem worth the trouble to implement and maintain, because
most of the time a query like "where x <> constant" is going to fetch
most of the table, and so it would be better done as a seqscan anyway.

If you have a specific case where that's not true, you might consider
a partial index (CREATE INDEX ... WHERE x <> constant).  But the details
of that would depend a lot on the queries you're concerned about.

            regards, tom lane

pgsql-performance by date:

Previous
From: Roxanne Reid-Bennett
Date:
Subject: Re: will the planner ever use an index when the condition is <> ?
Next
From: Marti Raudsepp
Date:
Subject: Re: will the planner ever use an index when the condition is <> ?