X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 8CCE2D705A for ; Fri, 26 Aug 2005 11:18:34 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 91898-09 for ; Fri, 26 Aug 2005 14:18:33 +0000 (GMT) Received: from megazone.bigpanda.com (megazone.bigpanda.com [64.147.171.210]) by svr1.postgresql.org (Postfix) with ESMTP id DA05FD6F0C for ; Fri, 26 Aug 2005 11:18:32 -0300 (ADT) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id F334435485; Fri, 26 Aug 2005 07:18:34 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id DAAC63547A; Fri, 26 Aug 2005 07:18:34 -0700 (PDT) Date: Fri, 26 Aug 2005 07:18:30 -0700 (PDT) From: Stephan Szabo To: Mark Kirkwood Cc: Tobias Brox , pgsql-performance@postgresql.org Subject: Re: Limit + group + join In-Reply-To: <430E85ED.60109@paradise.net.nz> Message-ID: <20050826071621.P12124@megazone.bigpanda.com> References: <20050826002709.GK10328@tobias.lan> <430E85ED.60109@paradise.net.nz> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006] X-Spam-Level: X-Archive-Number: 200508/437 X-Sequence-Number: 14184 On Fri, 26 Aug 2005, Mark Kirkwood wrote: > However being a bit brutal: > > set enable_mergejoin=false; > set enable_hashjoin=false; > > explain select c.id from c join b on c_id=c.id group by c.id order by > c.id desc limit 5; > QUERY PLAN > > -------------------------------------------------------------------------------------------------- > Limit (cost=0.00..15.24 rows=5 width=4) > -> Group (cost=0.00..243798.00 rows=80000 width=4) > -> Nested Loop (cost=0.00..243598.00 rows=80000 width=4) > -> Index Scan Backward using c_pkey on c > (cost=0.00..1518.00 rows=80000 width=4) > -> Index Scan using b_on_c on b (cost=0.00..3.01 > rows=1 width=4) > Index Cond: (b.c_id = "outer".id) > (6 rows) > > What is interesting is why this plan is being rejected... Well, it expects 80000 probles into b_on_c to be more expensive than the hash join and sort. I wonder what explain analyze shows for the original and the version with the enables changed.