Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 44986650258 for ; Thu, 28 Aug 2008 20:01:11 -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 92680-02 for ; Thu, 28 Aug 2008 20:01:03 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.172]) by postgresql.org (Postfix) with ESMTP id 9E6A26500D5 for ; Thu, 28 Aug 2008 20:01:07 -0300 (ADT) Received: by ug-out-1314.google.com with SMTP id 29so1299497ugo.7 for ; Thu, 28 Aug 2008 16:01:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:cc:subject:date :message-id:mime-version:content-type:content-transfer-encoding :x-priority:x-msmail-priority:x-mailer:in-reply-to:x-mimeole :thread-index:importance; bh=5GqYVeht//9hITboasSgZ1vAg6HqHa5TERUuJmpivCo=; b=CPuabJb6hq857u0QVWnsjRmwNUcKNbnn/tC1EafneIouBph67JaL4L6sNCungxkQvb K0oS0DQJ++/TJfIR4ZPjBPewjeut5X3DQlLfTH8yd2KjfZdSqtn+eiuLbTb/Yfb1tJX0 c3dSAn71bB+K7mmXIpBDdTeZ8uTSrlz8q6+C8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:mime-version:content-type :content-transfer-encoding:x-priority:x-msmail-priority:x-mailer :in-reply-to:x-mimeole:thread-index:importance; b=Q2KK2OPjD9DhhtnOBfDD9OXk2e5Exi8HD4b8xgd0kH/TBDW0Z8nxgayx+Mrb7hES2I 22Lm2b50y0qHdN9Tveu6D1Xx/gOIxOh2jkS7RCvhSOAKPBMREasItmd91c/85K9oQBqg lcpej7I8LO1wz9753Z1tpRWvNHI/hnFhw5QyI= Received: by 10.67.119.8 with SMTP id w8mr3959656ugm.20.1219964464884; Thu, 28 Aug 2008 16:01:04 -0700 (PDT) Received: from amd64 ( [83.104.138.235]) by mx.google.com with ESMTPS id 25sm1270690ugn.19.2008.08.28.16.01.03 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 28 Aug 2008 16:01:04 -0700 (PDT) From: "David Rowley" To: "'Brad Ediger'" Cc: Subject: Re: Nested Loop join being improperly chosen Date: Fri, 29 Aug 2008 00:01:05 +0100 Message-ID: <2F2B8795E8584EEB97AF9FE82CA1D7A5@amd64> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.6838 In-Reply-To: X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579 thread-index: AckEcR4gr4eZs+HcR4ii5ra+0DDF9AE8DTOw Importance: Normal 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/397 X-Sequence-Number: 31278 I had a similar problem here: http://archives.postgresql.org/pgsql-bugs/2008-07/msg00026.php Is the nested loop performing a LEFT join with yours? It's a little difficult to tell just from the query plan you showed. A work around for mine was to use a full outer join and eliminate the extra rows in the where clause. A bit of a hack but it changed a 2 min query into one that ran in under a second. Of course this is not helping with your problem but at least may trigger some more feedback. David. -----Original Message----- From: pgsql-performance-owner@postgresql.org [mailto:pgsql-performance-owner@postgresql.org] On Behalf Of Brad Ediger Sent: 22 August 2008 16:26 To: pgsql-performance@postgresql.org Subject: [PERFORM] Nested Loop join being improperly chosen Hello, I'm having trouble with a Nested Loop being selected for a rather complex query; it turns out this is a pretty bad plan as the nested loop's row estimates are quite off (1 estimated / 1207881 actual). If I disable enable_nestloop, the query executes much faster (42 seconds instead of 605). The tables in the query have all been ANALYZEd just before generating these plans. Here are the plans with and without enable_nestloop: http://pastie.org/258043 The inventory table is huge; it currently has about 1.3 x 10^9 tuples. The items table has around 10,000 tuples, and the other tables in the query are tiny. Any ideas or suggestions would be greatly appreciated. Thanks! -- Brad Ediger