Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 9B1F563392C for ; Fri, 8 Jan 2010 15:24:10 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 70748-06 for ; Fri, 8 Jan 2010 19:24:00 +0000 (UTC) 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 mail.postgresql.org (Postfix) with ESMTP id 081D46338E0 for ; Fri, 8 Jan 2010 15:23:58 -0400 (AST) 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 o08JNoV8010917; Fri, 8 Jan 2010 14:23:50 -0500 (EST) To: Robert Haas cc: Kaloyan Iliev Iliev , pgsql-performance@postgresql.org Subject: Re: Change query join order In-reply-to: <603c8f071001081101t5c7b26fci407edd8523a7f4a@mail.gmail.com> References: <4B47722A.4010502@digsys.bg> <9969.1262975223@sss.pgh.pa.us> <603c8f071001081101t5c7b26fci407edd8523a7f4a@mail.gmail.com> Comments: In-reply-to Robert Haas message dated "Fri, 08 Jan 2010 14:01:18 -0500" Date: Fri, 08 Jan 2010 14:23:50 -0500 Message-ID: <10916.1262978630@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.589 tagged_above=-10 required=5 tests=BAYES_00=-2.599, FH_DATE_PAST_20XX=3.188 X-Spam-Level: X-Archive-Number: 201001/154 X-Sequence-Number: 37034 Robert Haas writes: > On Fri, Jan 8, 2010 at 1:27 PM, Tom Lane wrote: >> 11000 index probes aren't exactly free.  If they take more than about >> 1msec apiece, the planner picked the right plan. > The OP could try setting enable_hashjoin to false (just for testing, > never for production) and do EXPLAIN ANALYZE again. That might > generate the desired plan, and we could see which one is actually > faster. Right, sorry for the overly brief response. It might switch to a merge join next, in which case try enable_mergejoin = off as well. > If the other plan does turn out to be faster (and I agree with Tom > that there is no guarantee of that), then one thing to check is > whether seq_page_cost and random_page_cost are set too high. If the > data is all cached, the default values of 4 and 1 are three orders of > magnitude too large, and they should also be set to equal rather than > unequal values. Tweaking the cost parameters to suit your local situation is the recommended cure for planner misjudgments; but I'd recommend against changing them on the basis of only one example. You could easily find yourself making other cases worse. Get a collection of common queries for your app and look at the overall effects. regards, tom lane