Received: from localhost (unknown [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 2E8B19F9FF3 for ; Mon, 24 Sep 2007 11:04:02 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 31721-02-2 for ; Mon, 24 Sep 2007 11:03:49 -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 F41CB9F9F85 for ; Mon, 24 Sep 2007 11:03:55 -0300 (ADT) Received: from einstein.muc.ecircle.de (einstein.muc.ecircle.de [192.168.1.7]) by mail3.ecircle.de (READY) with ESMTP id AC83F11C089; Mon, 24 Sep 2007 16:03:53 +0200 (CEST) Received: from [192.168.1.91] ([192.168.1.91]) by einstein.muc.ecircle.de with Microsoft SMTPSVC(6.0.3790.1830); Mon, 24 Sep 2007 16:03:52 +0200 Subject: Re: Searching for the cause of a bad plan From: Csaba Nagy To: Simon Riggs Cc: postgres performance list In-Reply-To: <1190640429.4181.165.camel@ebony.site> References: <1190369024.4661.173.camel@PCD12478> <6175.1190390913@sss.pgh.pa.us> <1190396352.4202.109.camel@ebony.site> <13644.1190397220@sss.pgh.pa.us> <1190399879.4202.127.camel@ebony.site> <27857.1190417434@sss.pgh.pa.us> <1190640429.4181.165.camel@ebony.site> Content-Type: text/plain Date: Mon, 24 Sep 2007 16:04:42 +0200 Message-Id: <1190642682.4661.247.camel@PCD12478> Mime-Version: 1.0 X-Mailer: Evolution 2.10.1 Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 24 Sep 2007 14:03:52.0928 (UTC) FILETIME=[BD252E00:01C7FEB3] X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200709/415 X-Sequence-Number: 26960 On Mon, 2007-09-24 at 14:27 +0100, Simon Riggs wrote: > Csaba, please can you copy that data into fresh tables, re-ANALYZE and > then re-post the EXPLAINs, with stats data. Well, I can of course. I actually tried to generate some random data with similar record count and relations between the tables (which I'm not sure I succeeded at), without the extra columns, but it was happily yielding the nested loop plan. So I guess I really have to copy the whole data (several tens of GB). But from my very limited understanding of what information is available for the planner, I thought that the record count estimated for the join between table_a and table_b1 on column b should be something like (estimated record count in table_a for value "a") * (weight of "b" range covered by table_b1 and table_a in common) / (weight of "b" range covered by table_a) This is if the "b" values in table_a wouldn't be correlated at all with the content of table_b2. The reality is that they are, but the planner has no information about that. I have no idea how the planner works though, so this might be totally off... I will copy the data and send the results (not promising though that it will be today). Cheers, Csaba.