Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TlWSw-0004gR-CP for pgsql-performance@arkaria.postgresql.org; Thu, 20 Dec 2012 03:06:34 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1TlWSv-0003kT-Tn for pgsql-performance@arkaria.postgresql.org; Thu, 20 Dec 2012 03:06:33 +0000 Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TlWSv-0003kO-3h for pgsql-performance@postgresql.org; Thu, 20 Dec 2012 03:06:33 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TlWSt-00013V-V5 for pgsql-performance@postgresql.org; Thu, 20 Dec 2012 03:06:32 +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 qBK36V1T028779; Wed, 19 Dec 2012 22:06:31 -0500 (EST) From: Tom Lane To: Richard Neill cc: pgsql-performance@postgresql.org Subject: Re: Why does the query planner use two full indexes, when a dedicated partial index exists? In-reply-to: <50D22DE2.4090301@richardneill.org> References: <50D22DE2.4090301@richardneill.org> Comments: In-reply-to Richard Neill message dated "Wed, 19 Dec 2012 21:13:06 +0000" Date: Wed, 19 Dec 2012 22:06:30 -0500 Message-ID: <28778.1355972790@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: > The problem is, when I now run my query, the planner ignores the > dedicated index "tbl_tracker_performance_1_idx", and instead uses both > of the full indexes... resulting in a much much slower query (9ms vs > 0.08ms). > A psql session is below. This shows that, if I force the planner to use > the partial index, by dropping the others, then it's fast. But as soon > as I put the full indexes back (which I need for other queries), the > query planner chooses them instead, and is slow. [ experiments with a similar test case ... ] I think the reason why the planner is overestimating the cost of using the partial index is that 9.1 and earlier fail to account for the partial-index predicate when estimating the number of index rows that will be visited. Because the partial-index predicate is so highly selective in this case, that results in a significant overestimate of how much of the index will be traversed. We fixed this for 9.2 in http://git.postgresql.org/gitweb/?p=postgresql.git&a=commitdiff&h=21a39de5809cd3050a37d2554323cc1d0cbeed9d but did not want to risk back-patching such a behavioral change. If you're stuck on 9.1 you might want to think about applying that as a local patch though. (BTW, the "fudge factor" change in that patch has been criticized recently; we've changed it again already for 9.3 and might choose to back-patch that into 9.2.3. But it's the rest of it that you care about anyway.) 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