Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YWXgn-0008Qh-Ry for pgsql-performance@arkaria.postgresql.org; Fri, 13 Mar 2015 22:04:17 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YWXgn-0007YA-AO for pgsql-performance@arkaria.postgresql.org; Fri, 13 Mar 2015 22:04:17 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YWXgl-0007VH-IR for pgsql-performance@postgresql.org; Fri, 13 Mar 2015 22:04:15 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YWXgi-0004hT-Ia for pgsql-performance@postgresql.org; Fri, 13 Mar 2015 22:04:13 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id t2DM46qS025961; Fri, 13 Mar 2015 18:04:06 -0400 From: Tom Lane To: "Jim Carroll" cc: pgsql-performance@postgresql.org Subject: Re: Postgres inconsistent use of Index vs. Seq Scan In-reply-to: <011801d05dd4$8226b890$867429b0$@carroll.com> References: <011801d05dd4$8226b890$867429b0$@carroll.com> Comments: In-reply-to "Jim Carroll" message dated "Fri, 13 Mar 2015 17:27:29 -0400" Date: Fri, 13 Mar 2015 18:04:06 -0400 Message-ID: <25960.1426284246@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org "Jim Carroll" 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 -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance