Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 7867CB5DC5B for ; Tue, 12 Jul 2011 19:06:57 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 34140-05-6 for ; Tue, 12 Jul 2011 22:06:50 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from out2.mail.amis.hr (out2.mail.amis.hr [188.129.0.5]) by mail.postgresql.org (Postfix) with ESMTP id 3B290B5DCB7 for ; Tue, 12 Jul 2011 19:06:48 -0300 (ADT) Received: from out.fsec.sm.srv.amis.hr (out.fsec.sm.srv.amis.hr [192.168.106.22]) by out2.mail.amis.hr (Postfix) with ESMTP id 786C71FD25; Wed, 13 Jul 2011 00:06:47 +0200 (CEST) Received: from pps.filterd (out [127.0.0.1]) by out.fsec.sm.srv.amis.hr (8.14.3/8.14.3) with SMTP id p6CM6lgL011695; Wed, 13 Jul 2011 00:06:47 +0200 Received: from smtp.amis.hr (smtp.sm.srv.amis.hr [192.168.106.39]) by out.fsec.sm.srv.amis.hr with ESMTP id xgkdxg72b-1; Wed, 13 Jul 2011 00:06:47 +0200 A-Original-Client-UID: 188.129.65.237 splivalo Received: from [192.168.10.1] (cpe-188-129-65-237.dynamic.amis.hr [188.129.65.237]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: splivalo) by smtp.amis.hr (Postfix) with ESMTPSA id 3B7EF265; Wed, 13 Jul 2011 00:06:46 +0200 (CEST) Message-ID: <4E1CC576.2080200@megafon.hr> Date: Wed, 13 Jul 2011 00:06:46 +0200 From: Mario Splivalo User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.17) Gecko/20110424 Thunderbird/3.1.10 MIME-Version: 1.0 To: Tom Lane CC: pgsql-performance@postgresql.org Subject: Re: Planner choosing NestedLoop, although it is slower... References: <4E1C8E62.2090800@megafon.hr> <4626.1310501052@sss.pgh.pa.us> In-Reply-To: <4626.1310501052@sss.pgh.pa.us> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.4.6813, 1.0.211, 0.0.0000 definitions=2011-07-12_08:2011-07-12, 2011-07-12, 1970-01-01 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 ipscore=0 suspectscore=0 phishscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx engine=6.0.2-1012030000 definitions=main-1107120165 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 X-Spam-Level: X-Archive-Number: 201107/124 X-Sequence-Number: 44336 On 07/12/2011 10:04 PM, Tom Lane wrote: > Mario Splivalo writes: >> Limit (cost=0.00..415.91 rows=21 width=8) (actual >> time=11263.089..11263.089 rows=0 loops=1) >> -> Nested Loop (cost=0.00..186249.55 rows=9404 width=8) (actual >> time=11263.087..11263.087 rows=0 loops=1) > >> Why is planner using NestedLoops, > > Because it thinks the LIMIT will kick in and end the query when the join > is only 21/9404ths (ie, a fraction of a percent) complete. A NestLoop > results in saving a lot of work in that situation, whereas hash-and-sort > has to do the whole join despite the LIMIT. > > What you need to look into is why the estimated join size is 9400 rows > when the actual join size is zero. Are both tables ANALYZEd? Are you > intentionally selecting rows that have no join partners? Hi, Tom. Yes, both tables have been ANALYZEd. What do you mean, intentilnaly selecting rows taht have no join partners? Mario