X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 2D8269F931E for ; Wed, 10 May 2006 22:20:23 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 62055-08 for ; Wed, 10 May 2006 22:20:14 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 5EE669FA3A3 for ; Wed, 10 May 2006 22:20:12 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.6/8.13.6) with ESMTP id k4B1K58V025819; Wed, 10 May 2006 21:20:05 -0400 (EDT) To: Brian Wipf cc: pgsql-performance@postgresql.org Subject: Re: Same query - Slow in production In-reply-to: <18620DA0-DE55-4A2C-9DDC-BCF5F478E886@clickspace.com> References: <18620DA0-DE55-4A2C-9DDC-BCF5F478E886@clickspace.com> Comments: In-reply-to Brian Wipf message dated "Wed, 10 May 2006 16:39:14 -0600" Date: Wed, 10 May 2006 21:20:05 -0400 Message-ID: <25818.1147310405@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200605/284 X-Sequence-Number: 19071 Brian Wipf writes: > I'm trying to determine why an identical query is running > approximately 500 to 1000 times slower on our production database > compared to our backup database server. It looks to me like it's pure luck that the query is fast on the backup server. The outer side of the EXISTS' join is being badly misestimated: > -> Index Scan using > category_product__category_id_is_active_and_status_idx on > category_product cp (cost=0.00..4362.64 rows=1103 width=4) (actual > time=0.013..0.015 rows=2 loops=5) > Index Cond: ((category_id = $1) AND > ((product_is_active)::text = 'true'::text) AND > ((product_status_code)::text = 'complete'::text)) If there actually had been 1100 matching rows instead of 2, the query would have run 550 times slower, putting it in the same ballpark as the other plan. So what I'm guessing is that the planner sees these two plans as being nearly the same cost, and small differences in the stats between the two databases are enough to tip its choice in one direction or the other. So what you want, of course, is to improve that rowcount estimate. I suppose the reason it's so bad is that we don't have multicolumn statistics ... is there a strong correlation between product_is_active and product_status_code? If so, it might be worth your while to find a way to merge them into one column. regards, tom lane