X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id C14D1D1B960 for ; Fri, 29 Aug 2003 02:51:11 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 69829-08 for ; Thu, 28 Aug 2003 23:50:43 -0300 (ADT) Received: from mail.speakeasy.net (mail15.speakeasy.net [216.254.0.215]) by svr1.postgresql.org (Postfix) with ESMTP id D2B60D1B8C6 for ; Thu, 28 Aug 2003 23:50:37 -0300 (ADT) Received: (qmail 25478 invoked by uid 64014); 29 Aug 2003 02:50:42 -0000 Received: from kgeis@speakeasy.org by mail15.speakeasy.net with AmikaGuardian-Server-2.0.0 (Processed in 0.214208 secs); 29 Aug 2003 02:50:42 -0000 X-AmikaGuardian-Id: mail15.speakeasy.net106212544223625473 X-AmikaGuardian-Category: AN:Urgency : 0.01 X-AmikaGuardian-Category: AN:Vectored : 1.7 X-AmikaGuardian-Category: AN:Spam Language : 0.01 X-AmikaGuardian-Category: AN:Forwarded Mail : 1.7 X-AmikaGuardian-Category: AN:Override : 1.7 X-AmikaGuardian-Category: AN:Junk Mail : 0.01 X-AmikaGuardian-Category: AN:Exception : 1.7 X-AmikaGuardian-Category: AN:Spam : 0.01 X-AmikaGuardian-Action: Do Nothing() Received: from unknown (HELO speakeasy.org) (kgeis@[67.113.18.226]) (envelope-sender ) by mail15.speakeasy.net (qmail-ldap-1.03) with AES256-SHA encrypted SMTP for ; 29 Aug 2003 02:50:42 -0000 Message-ID: <3F4EBF7E.8020602@speakeasy.org> Date: Thu, 28 Aug 2003 19:50:38 -0700 From: Ken Geis User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4) Gecko/20030624 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Bruno Wolff III Cc: pgsql-performance@postgresql.org Subject: Re: bad estimates / non-scanning aggregates References: <3F4E99F7.7080604@speakeasy.org> <20030829025109.GD4373@wolff.to> In-Reply-To: <20030829025109.GD4373@wolff.to> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/459 X-Sequence-Number: 3275 Bruno Wolff III wrote: > On Thu, Aug 28, 2003 at 17:10:31 -0700, > Ken Geis wrote: > >>The query I want to run is >> >>select stock_id, min(price_date) from day_ends group by stock_id; > > The fast way to do this is: > > select distinct on (stock_id) stock_id, price_date > order by stock_id, price_date; Not according to the optimizer! Plus, this is not guaranteed to return the correct results. Unique (cost=3711244.30..3795942.42 rows=6366 width=8) -> Sort (cost=3711244.30..3753593.36 rows=16939624 width=8) Sort Key: stock_id, price_date -> Seq Scan on day_ends (cost=0.00..361892.24 rows=16939624 width=8)