Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 632A06500FD for ; Mon, 18 Aug 2008 12:20:15 -0300 (ADT) Received: from postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 37426-07 for ; Mon, 18 Aug 2008 12:20:11 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 8825F650078 for ; Mon, 18 Aug 2008 12:20:09 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id m7IFK0he028903; Mon, 18 Aug 2008 11:20:00 -0400 (EDT) To: "Gauri Kanekar" cc: pgsql-performance@postgreSQL.org Subject: Re: Cross Join Problem In-reply-to: <7e4ba9550808180706l4f595729h102cbc2bb3e1bfa@mail.gmail.com> References: <7e4ba9550808180637v382ce149sf0577849b03d955@mail.gmail.com> <18370.1219068149@sss.pgh.pa.us> <7e4ba9550808180706l4f595729h102cbc2bb3e1bfa@mail.gmail.com> Comments: In-reply-to "Gauri Kanekar" message dated "Mon, 18 Aug 2008 19:36:21 +0530" Date: Mon, 18 Aug 2008 11:20:00 -0400 Message-ID: <28902.1219072800@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200808/195 X-Sequence-Number: 31076 [ please keep the list cc'd for the archives' sake ] "Gauri Kanekar" writes: > On Mon, Aug 18, 2008 at 7:32 PM, Tom Lane wrote: >> No PG release since 7.3 would have voluntarily planned that query that >> way. Maybe you were using join_collapse_limit = 1 to force the join >> order? > Yes, We have set join_collapse_limit set to 1. Ah, so really your question is why join_collapse_limit isn't working as you expect. That code changed quite a bit in 8.2, and the way it works now is that the critical decision occurs while deciding whether to fold the cross-join (a sub-problem of size 2) into the top-level join problem. Which is a decision that's going to be driven by from_collapse_limit not join_collapse_limit. So one way you could make it work is to reduce from_collapse_limit to less than 3, but I suspect you'd find that that has too many bad consequences for other queries. What's probably best is to write the problem query like this: FROM table1 a cross join ( table2 b cross join table3 c ) which will cause join_collapse_limit to be the relevant number at both steps. regards, tom lane