Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1ToGtX-00075o-MN for pgsql-performance@arkaria.postgresql.org; Thu, 27 Dec 2012 17:05:23 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1ToGtX-0005wv-6v for pgsql-performance@arkaria.postgresql.org; Thu, 27 Dec 2012 17:05:23 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1ToGtW-0005wi-9U for pgsql-performance@postgresql.org; Thu, 27 Dec 2012 17:05:22 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1ToGtT-0000us-VO for pgsql-performance@postgresql.org; Thu, 27 Dec 2012 17:05:21 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.5/8.14.5) with ESMTP id qBRH5IrL014672; Thu, 27 Dec 2012 12:05:19 -0500 (EST) From: Tom Lane To: Richard Neill cc: PostgreSQL Performance Subject: Re: Why does the query planner use two full indexes, when a dedicated partial index exists? In-reply-to: <50DC7ABA.5010109@richardneill.org> References: <50D22DE2.4090301@richardneill.org> <28778.1355972790@sss.pgh.pa.us> <50D3CAC4.3070800@richardneill.org> <50DC7ABA.5010109@richardneill.org> Comments: In-reply-to Richard Neill message dated "Thu, 27 Dec 2012 16:43:38 +0000" Date: Thu, 27 Dec 2012 12:05:18 -0500 Message-ID: <14671.1356627918@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 Richard Neill writes: > So, at the moment, I have 3 indexes: > full: parcel_id_code > full: exit_state > full: parcel_id_code where exit state is null > Am I right that when you suggest just a single, joint index > (parcel_id_code,exit_state) > instead of all 3 of the others, I think he was just recommending replacing the first and third indexes. > it will allow me to optimally run all of the following? : > 1. SELECT * from tbl_tracker WHERE parcel_id_code=22345 AND exit_state > IS NULL > 2. SELECT * from tbl_tracker where parcel_id_code=44533 > 3. SELECT * from tbl_tracker where exit_code = 2 You will need an index with exit_state as the first column to make #3 perform well --- at least, assuming that an index is going to help at all anyway. The rule of thumb is that if a query is going to fetch more than a few percent of a table, an index is not useful because it's going to be touching most table pages anyway, so a seqscan will win. I've forgotten now what you said the stats for exit_code values other than null were, but it's quite possible that an index is useless for #3. These considerations are mostly covered in the manual: http://www.postgresql.org/docs/9.2/static/indexes.html 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