X-Original-To: pgsql-performance-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 894349FB2A8 for ; Fri, 15 Sep 2006 11:08:47 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 73901-06-2 for ; Fri, 15 Sep 2006 11:08:39 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 8D12B9FB2E0 for ; Fri, 15 Sep 2006 11:08:38 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.6/8.13.6) with ESMTP id k8FE8ZoX024191; Fri, 15 Sep 2006 10:08:35 -0400 (EDT) To: "Joost Kraaijeveld" cc: pgsql-performance@postgresql.org Subject: Re: Why the difference in plans ?? In-reply-to: <1158309566.30482.29.camel@panoramix> References: <1158309566.30482.29.camel@panoramix> Comments: In-reply-to "Joost Kraaijeveld" message dated "Fri, 15 Sep 2006 10:39:27 +0200" Date: Fri, 15 Sep 2006 10:08:35 -0400 Message-ID: <24190.1158329315@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.106 tagged_above=0 required=5 tests=AWL, SPF_HELO_PASS, SPF_PASS X-Spam-Level: X-Archive-Number: 200609/204 X-Sequence-Number: 20890 "Joost Kraaijeveld" writes: > Why the difference and can I influence the result so that the first > query plan (which is the fastest) is actually used in both cases (I > would expect that the limit would be done after the sort?)? It likes the second plan because 6694025.41/353 < 41812.78. It would probably be right, too, if the number of matching rows were indeed 353, but it seems there are only 7. Try increasing your statistics target and re-analyzing. regards, tom lane