Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 1912E9FB2C7 for ; Fri, 21 Sep 2007 08:29:15 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 03578-03-3 for ; Fri, 21 Sep 2007 08:29:09 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from mail3.ecircle.de (mail3.ecircle.de [195.140.186.206]) by postgresql.org (Postfix) with ESMTP id AEFBD9FA479 for ; Fri, 21 Sep 2007 08:29:09 -0300 (ADT) Received: from einstein.muc.ecircle.de (einstein.muc.ecircle.de [192.168.1.7]) by mail3.ecircle.de (READY) with ESMTP id 5337B11C02B; Fri, 21 Sep 2007 13:29:05 +0200 (CEST) Received: from [192.168.1.91] ([192.168.1.91]) by einstein.muc.ecircle.de with Microsoft SMTPSVC(6.0.3790.1830); Fri, 21 Sep 2007 13:28:50 +0200 Subject: Re: Searching for the cause of a bad plan From: Csaba Nagy To: Simon Riggs Cc: postgres performance list In-Reply-To: <1190372365.4202.14.camel@ebony.site> References: <1190369024.4661.173.camel@PCD12478> <1190372365.4202.14.camel@ebony.site> Content-Type: text/plain Date: Fri, 21 Sep 2007 13:29:26 +0200 Message-Id: <1190374166.4661.194.camel@PCD12478> Mime-Version: 1.0 X-Mailer: Evolution 2.10.1 Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 21 Sep 2007 11:28:50.0034 (UTC) FILETIME=[94F2F520:01C7FC42] X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200709/357 X-Sequence-Number: 26902 On Fri, 2007-09-21 at 11:59 +0100, Simon Riggs wrote: > Please re-run everything on clean tables without frigging the stats. We > need to be able to trust what is happening is normal. I did, the plan fiddling happened after getting the plans after a fresh analyze, and I did run the plan again with fresh analyze just before sending the mail and the plan was the same. In fact I spent almost 2 days playing with the query which is triggering this behavior, until I tracked it down to this join. Thing is that we have many queries which rely on this join, so it is fairly important that we understand what happens there. > Plan2 sees that b1 is wider, which will require more heap blocks to be > retrieved. It also sees b1 is less correlated than b2, so again will > require more database blocks to retrieve. Try increasing > effective_cache_size. effective_cach_size is set to ~2.7G, the box has 4G memory. I increased it now to 3,5G but it makes no difference. I increased it further to 4G, no difference again. > Can you plans with/without LIMIT and with/without cursor, for both b1 > and b2? The limit is unfortunately absolutely needed part of the query, it makes no sense to try without. If it would be acceptable to do it without the limit, then it is entirely possible that the plan I get now would be indeed better... but it is not acceptable. Thanks, Csaba.