Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 1C356633492 for ; Tue, 7 Sep 2010 13:55:02 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 09154-05 for ; Tue, 7 Sep 2010 16:54:54 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from gw.wicourts.gov (gwmta.wicourts.gov [165.219.244.99]) by mail.postgresql.org (Postfix) with ESMTP id 9B0286333B9 for ; Tue, 7 Sep 2010 13:54:54 -0300 (ADT) Received: from Courts-MTA by gw.wicourts.gov with Novell_GroupWise; Tue, 07 Sep 2010 11:54:53 -0500 Message-Id: <4C86280C02000025000352AF@gw.wicourts.gov> X-Mailer: Novell GroupWise Internet Agent 8.0.1 Date: Tue, 07 Sep 2010 11:54:52 -0500 From: "Kevin Grittner" To: , Subject: Re: Question about LEFT JOIN and query plan References: <4C811F68.9060601@digsys.bg> <4C80E73402000025000351AF@gw.wicourts.gov> <4C85E774.7090204@digsys.bg> In-Reply-To: <4C85E774.7090204@digsys.bg> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-4.21 tagged_above=-10 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201009/27 X-Sequence-Number: 40230 >Kaloyan Iliev Iliev wrote: > Kevin Grittner wrote: >> Out of curiosity, what happens if you consistently use JOIN >> clauses, rather than mixing that with commas?: > The plan improves. So can you explain why? Commas in a FROM clause bind more loosely than JOIN clauses, rearrangement from one side of an outer join to the other is a bit tricky, and the *_collapse_limit settings (which you have not shown) can affect how much JOIN rearrangement is done for a complex query. On a quick scan over your query it didn't appear that the rearrangement would break anything, so I wondered whether the planner might do better if you made its job a bit easier by putting the inner joins all on the left to start with and putting the tables closer to the order of efficient access. If you still see this difference with very high collapse limits, your example might be a good one to support further work on the optimizer; but it would be more useful for that if you could create a synthetic case to demonstrate the problem -- starting with creation of tables, data, and indexes on which the different forms of the query yielded different plans. -Kevin