Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TlTuX-0002Hs-S1 for pgsql-performance@arkaria.postgresql.org; Thu, 20 Dec 2012 00:22:53 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1TlTuX-0001N4-4I for pgsql-performance@arkaria.postgresql.org; Thu, 20 Dec 2012 00:22:53 +0000 Received: from magus.postgresql.org ([87.238.57.229]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TlTuW-0001Mz-D1 for pgsql-performance@postgresql.org; Thu, 20 Dec 2012 00:22:52 +0000 Received: from www.ruo3.org ([87.194.171.29] helo=chocolate.ruo3.org) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TlTuU-0002Vf-Q7 for pgsql-performance@postgresql.org; Thu, 20 Dec 2012 00:22:52 +0000 Received: from [127.0.0.1] (chocolate.ruo3.org [127.0.0.1]) by chocolate.ruo3.org (Postfix) with ESMTP id 046A7560A53; Thu, 20 Dec 2012 00:22:50 +0000 (GMT) Message-ID: <50D25A59.3060105@richardneill.org> Date: Thu, 20 Dec 2012 00:22:49 +0000 From: Richard Neill User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121010 Thunderbird/16.0.1 MIME-Version: 1.0 To: Sergey Konoplev CC: "pgsql-performance@postgresql.org" Subject: Re: Why does the query planner use two full indexes, when a dedicated partial index exists? References: <50D22DE2.4090301@richardneill.org> <50D2528E.7000800@richardneill.org> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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 Thanks for your help, On 20/12/12 00:08, Sergey Konoplev wrote: > On Wed, Dec 19, 2012 at 3:49 PM, Richard Neill wrote: >> * The reindex solution doesn't work. I just tried it, and the query planner >> is still using the wrong indexes. > > Can you show the explain analyze with tbl_tracker_performance_1_idx > straight after reindex (eg. before it has been bloated again)? Sure. Just done it now... the system has been fairly lightly loaded for the last few hours - though I did have to change the specific number of the parcel_id_code in the query. fsc_log=> explain analyse select * from tbl_tracker where parcel_id_code=92223 and exit_state is null; QUERY PLAN ----------------------------------------------------------- Index Scan using tbl_tracker_exit_state_idx on tbl_tracker (cost=0.00..6.34 rows=1 width=174) (actual time=0.321..1.871 rows=1 loops=1) Index Cond: (exit_state IS NULL) Filter: (parcel_id_code = 92223) Total runtime: 1.905 ms (4 rows) And now, force it, by dropping the other index (temporarily): fsc_log=> drop index tbl_tracker_exit_state_idx; DROP INDEX fsc_log=> explain analyse select * from tbl_tracker where parcel_id_code=92223 and exit_state is null; QUERY PLAN --------------------------------------------------------------------- Index Scan using tbl_tracker_performance_1_idx on tbl_tracker (cost=0.00..7.78 rows=1 width=174) (actual time=0.040..0.041 rows=1 loops=1) Index Cond: (parcel_id_code = 92223) Total runtime: 0.077 ms (3 rows) As far as I can tell, the query planner really is just getting it wrong. BTW, there is a significant effect on speed caused by running the same query twice (it pulls stuff from disk into the OS disk-cache), but I've already accounted for this. Richard -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance