Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 4C2A683DC06 for ; Sun, 18 Dec 2011 14:31:43 -0400 (AST) Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1RcLWN-0006bH-Lj for pgsql-performance@postgresql.org; Sun, 18 Dec 2011 18:31:43 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id pBIIVQJP003089; Sun, 18 Dec 2011 13:31:26 -0500 (EST) To: Roxanne Reid-Bennett cc: pgsql-performance@postgresql.org Subject: Re: will the planner ever use an index when the condition is <> ? In-reply-to: <4EEDFE1E.9070303@tara-lu.com> References: <4EECB57F.3050208@tara-lu.com> <4EEDFE1E.9070303@tara-lu.com> Comments: In-reply-to Roxanne Reid-Bennett message dated "Sun, 18 Dec 2011 09:52:14 -0500" Date: Sun, 18 Dec 2011 13:31:26 -0500 Message-ID: <3088.1324233086@sss.pgh.pa.us> From: Tom Lane X-Pg-Spam-Score: -4.4 (----) X-Archive-Number: 201112/129 X-Sequence-Number: 45928 Roxanne Reid-Bennett 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