Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id D9C619F9862 for ; Mon, 24 Sep 2007 14:56:54 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 56590-09 for ; Mon, 24 Sep 2007 14:56:36 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from outmail129157.authsmtp.co.uk (outmail129157.authsmtp.co.uk [62.13.129.157]) by postgresql.org (Postfix) with ESMTP id 9FFDB9F9D67 for ; Mon, 24 Sep 2007 14:56:47 -0300 (ADT) Received: from outmail128177.authsmtp.com (outmail128177.authsmtp.com [62.13.128.177]) by punt2.authsmtp.com (8.13.8/8.13.8/Kp) with ESMTP id l8OHuhnD059328; Mon, 24 Sep 2007 18:56:44 +0100 (BST) Received: from [192.168.0.3] (85-211-149-22.dyn.gotadsl.co.uk [85.211.149.22]) (authenticated bits=0) by mail.authsmtp.com (8.13.8/8.13.8/Kp) with ESMTP id l8OHuelj085653; Mon, 24 Sep 2007 18:56:40 +0100 (BST) Subject: Re: Searching for the cause of a bad plan From: Simon Riggs To: Csaba Nagy Cc: postgres performance list In-Reply-To: <1190642682.4661.247.camel@PCD12478> 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> <1190642682.4661.247.camel@PCD12478> Content-Type: text/plain Date: Mon, 24 Sep 2007 18:55:22 +0100 Message-Id: <1190656522.4181.228.camel@ebony.site> Mime-Version: 1.0 X-Mailer: Evolution 2.8.2 Content-Transfer-Encoding: 7bit X-Server-Quench: 8114e6bc-6ac7-11dc-b86a-001185d377ca X-AuthRoute: OCdxZQATClZOTQEd DAteCiNZVAwpPBRK HVkIKg5MJUcNSQVJ NksadBtFagFbflxB HGQLW1NEUVV7XGV/ bwsfZQBDYEtPQQRu WVZLQE1QERpoT0AJ eWZbB0Uodw1Dfntz K0drXXUVVEV7cRN7 EB1JEzxVYnphaTRM TRJQcVJJcANLfxdA PlN4UyBcLwdSbGoL JyIJERcLGAAXEylc WAoNLFQdCUgMBHYg Rx1KFjwyBkBNQCt7 JlQsI1JUBEIYNC0A X-Authentic-SMTP: 61633235383639.squirrel.dmpriest.net.uk:752/Kp X-Report-SPAM: If SPAM / abuse - report it at: http://www.authsmtp.com/abuse X-Virus-Status: No virus detected - but ensure you scan with your own anti-virus system! X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200709/429 X-Sequence-Number: 26974 On Mon, 2007-09-24 at 16:04 +0200, Csaba Nagy wrote: > 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) There's no such code I'm aware of. Sounds a good idea though. I'm sure we could do something with the histogram values, but we don't in the default selectivity functions. -- Simon Riggs 2ndQuadrant http://www.2ndQuadrant.com