X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id F3FBD9FA1B0 for ; Fri, 12 May 2006 16:12:22 -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 28331-05 for ; Fri, 12 May 2006 16:12:16 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from noel.decibel.org (noel.decibel.org [67.100.216.10]) by postgresql.org (Postfix) with ESMTP id 0F27C9F946D for ; Fri, 12 May 2006 16:12:15 -0300 (ADT) Received: by noel.decibel.org (Postfix, from userid 1001) id 1A0A956431; Fri, 12 May 2006 14:12:14 -0500 (CDT) Received: (hashcash-sendmail, from uid 1001); Fri, 12 May 2006 14:12:13 -0500 Date: Fri, 12 May 2006 14:12:13 -0500 From: "Jim C. Nasby" To: Antal Attila Cc: pgsql-performance@postgresql.org Subject: Re: Wrong plan for subSELECT with GROUP BY Message-ID: <20060512191213.GS6201@pervasive.com> References: <446482E4.6050906@ritek.hu> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <446482E4.6050906@ritek.hu> X-Operating-System: FreeBSD 6.0-RELEASE-p4 amd64 X-Distributed: Join the Effort! http://www.distributed.net User-Agent: Mutt/1.5.11 X-Hashcash: 1:20:060512:atesz@ritek.hu::QpeQ7tJlfdR7X+zk:0006tef X-Hashcash: 1:20:060512:pgsql-performance@postgresql.org::qCk/Pyh+MwExVoLz:00000 0000000000000000000000001Jhl X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200605/329 X-Sequence-Number: 19116 If you wrap the LIMIT select into a subquery in the FROM the planner might figure it out... SELECT ... FROM (SELECT blah FROM a LIMIT 10) LEFT JOIN ... Unlike some other databases that will spend huge amounts of time on trying to re-arrange queries and then hope they can effectively cache query plans, PostgreSQL prefers not to spend cycles on more esoteric cases so that query planning is fast. -- Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com Pervasive Software http://pervasive.com work: 512-231-6117 vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461