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 1331BD6E53 for ; Thu, 25 Aug 2005 23:07:30 -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 86805-03 for ; Fri, 26 Aug 2005 02:06:52 +0000 (GMT) Received: from mail.nordicbet.com (mail.nordicbet.com [193.69.167.130]) by svr1.postgresql.org (Postfix) with ESMTP id 9569AD791D for ; Thu, 25 Aug 2005 23:06:49 -0300 (ADT) Received: from [80.203.125.83] (helo=tobias.nordicbet.invalid) (Authenticated Sender=tobias@nordicbet.com) by mail.nordicbet.com with esmtpa (Exim 4.50 #1 (Debian)) id 1E8TZl-0006IO-Ly; Fri, 26 Aug 2005 04:04:23 +0200 Received: by tobias.nordicbet.invalid (Postfix, from userid 500) id 90C47DECFD; Fri, 26 Aug 2005 04:06:35 +0200 (CEST) Date: Fri, 26 Aug 2005 04:06:35 +0200 From: Tobias Brox To: "Jeffrey W. Baker" Cc: Tobias Brox , pgsql-performance@postgresql.org Subject: Re: Limit + group + join Message-ID: <20050826020635.GM10328@tobias.lan> References: <20050826002709.GK10328@tobias.lan> <1125021419.16451.0.camel@noodles> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1125021419.16451.0.camel@noodles> Organization: Group Nordicbet User-Agent: Mutt/1.5.10i X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0 required=5 tests=[none] X-Spam-Level: X-Archive-Number: 200508/429 X-Sequence-Number: 14176 [Jeffrey W. Baker - Thu at 06:56:59PM -0700] > > explain select c.id from c join b on c_id=c.id group by c.id order by c.id > > desc limit 5; > > Where's b in this join clause? "join b on c_id=c.id" It just a funny way of writing: select c.id from c,b where c_id=c.id group by c.id order by c.id desc limit 5; > It looks like a cartesian product to me. No. The query will return exactly the same as the simplest query: select c.id from c order by c.id desc limit 5; As said, this is a gross oversimplification of the production envorinment. In the production environment, I really need to use both join, group and limit. I tested a bit with subqueries, it was not a good solution (selecting really a lot of rows and aggregates from many of the tables). The next idea is to hack it up by manually finding out where the "limit" will cut, and place a restriction in the where-part of the query. -- Notice of Confidentiality: This information may be confidential, and blah-blah-blah - so please keep your eyes closed. Please delete and destroy this email. Failure to comply will cause my lawyer to yawn.