pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ken Geis <kgeis@speakeasy.org>
To: Bruno Wolff III <bruno@wolff.to>
Cc: pgsql-performance@postgresql.org
Subject: Re: bad estimates / non-scanning aggregates
Date: Thu, 28 Aug 2003 19:50:38 -0700
Message-ID: <3F4EBF7E.8020602@speakeasy.org> (raw)
In-Reply-To: <20030829025109.GD4373@wolff.to>
References: <3F4E99F7.7080604@speakeasy.org>
	<20030829025109.GD4373@wolff.to>

Bruno Wolff III wrote:
> On Thu, Aug 28, 2003 at 17:10:31 -0700,
>   Ken Geis <kgeis@speakeasy.org> 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)





view thread (6+ messages)  latest in thread

Message-ID: <3F4EBF7E.8020602@speakeasy.org>
Permalink:  ../3F4EBF7E.8020602@speakeasy.org/
Also on:    postgresql.org/message-id/3F4EBF7E.8020602@speakeasy.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: kgeis@speakeasy.org, bruno@wolff.to
  Subject: Re: bad estimates / non-scanning aggregates
  In-Reply-To: <3F4EBF7E.8020602@speakeasy.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox