Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 915111337B8D for ; Fri, 4 Feb 2011 10:45:12 -0400 (AST) 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 93777-07 for ; Fri, 4 Feb 2011 14:45:07 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.17.9]) by mail.postgresql.org (Postfix) with ESMTP id BAFF0133740B for ; Fri, 4 Feb 2011 10:45:02 -0400 (AST) Received: from [192.168.1.6] (mail.highperformancepostgresql.com [71.179.240.8]) by mrelayeu.kundenserver.de (node=mreu0) with ESMTP (Nemesis) id 0LgtBS-1QXNMr3mnm-00oFPF; Fri, 04 Feb 2011 15:45:00 +0100 Message-ID: <4D4C10EA.2080901@2ndquadrant.com> Date: Fri, 04 Feb 2011 09:44:58 -0500 From: Greg Smith User-Agent: Thunderbird 2.0.0.24 (X11/20100317) MIME-Version: 1.0 To: Ivan Voras CC: pgsql-performance@postgresql.org Subject: Re: Query performance with disabled hashjoin and mergejoin References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:Vl4dg/xyRu+fCgvfnTTGF4xL4y0Q4gE8iE8jnozO8Q1 ZgshOUbC4TPLj4tDxqdhYHMn1cCx+6Es1O7jq8XYT4wTJwH2X7 /TOYFcBEMo/kTnS+WBtP4hRSif6BaE8Im2TnjhhFkAJJFt2lpc L7FWzadJcWFodIbgW4mH+Jw0xVZYWVr9pRhNy1q6A37dyrugMI inASa2ME+4PYZwVpXAWL8aBoesNAbB/k6XN4kXnLEA= X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001 X-Spam-Level: X-Archive-Number: 201102/186 X-Sequence-Number: 42324 Ivan Voras wrote: > The "vanilla" plan, with default settings is: Pause here for a second: why default settings? A default PostgreSQL configuration is suitable for systems with about 128MB of RAM. Since you say you have "good enough hardware", I'm assuming you have a bit more than that. The first things to try here are the list at http://wiki.postgresql.org/wiki/Tuning_Your_PostgreSQL_Server ; your bad query here looks like it might benefit from a large increase to effective_cache_size, and possibly an increase to work_mem as well. Your "bad" plan here is doing a lot of sequential scans instead of indexed lookups, which makes me wonder if the change in join types you're forcing isn't fixing that part as a coincidence. Note that the estimated number of rows coming out of each form of plan is off by a factor of about 200X, so it's not that the other plan type is better estimating anything. -- Greg Smith 2ndQuadrant US greg@2ndQuadrant.com Baltimore, MD PostgreSQL Training, Services, and 24x7 Support www.2ndQuadrant.us "PostgreSQL 9.0 High Performance": http://www.2ndQuadrant.com/books