Received: from localhost (uranus.hub.org [200.46.204.60]) by postgresql.org (Postfix) with ESMTP id 423D19FA8EF for ; Mon, 6 Nov 2006 10:33:10 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.60]) (amavisd-new, port 10024) with ESMTP id 70612-07 for ; Mon, 6 Nov 2006 10:33:06 -0400 (AST) 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 4A34D9F9D99 for ; Mon, 6 Nov 2006 10:33:06 -0400 (AST) 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 kA6EX3YS010615; Mon, 6 Nov 2006 09:33:03 -0500 (EST) To: "Heikki Linnakangas" cc: "Hannes Dorbath" , pgsql-performance@postgresql.org Subject: Re: Yet another question on LIMIT performance :/ In-reply-to: <454F42FF.3070901@enterprisedb.com> References: <454F42FF.3070901@enterprisedb.com> Comments: In-reply-to "Heikki Linnakangas" message dated "Mon, 06 Nov 2006 14:13:19 +0000" Date: Mon, 06 Nov 2006 09:33:02 -0500 Message-ID: <10614.1162823582@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200611/68 X-Sequence-Number: 21838 "Heikki Linnakangas" writes: > Hannes Dorbath wrote: >> Though it should only have to join a few rows it seems to scan all rows. > What makes you think that's the case? What it looks like to me is that the range of keys present in pk_revisions_active corresponds to just the upper end of the range of keys present in pk_revisions (somehow not too surprising). So the mergejoin isn't the most effective plan possible for this case --- it has to scan through much of pk_revisions before it starts getting matches. The planner doesn't have any model for that though, and is costing the plan on the assumption of uniformly-distributed matches. A nestloop plan would be faster for this specific case, but much slower if a large number of rows were requested. regards, tom lane