Re: bad estimates / non-scanning aggregates

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Ken Geis <kgeis(at)speakeasy(dot)org>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: bad estimates / non-scanning aggregates
Date: 2003-08-29 03:01:56
Message-ID: 20030829030156.GF4373@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

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

For it to be fast you need an index on (stock_id, price_date) so that
you can use an index scan.

The answers are guarenteed to be correct. See:
http://developer.postgresql.org/docs/postgres/sql-select.html#SQL-DISTINCT

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Ron Johnson 2003-08-29 03:20:10 Re: Replication Ideas
Previous Message Ken Geis 2003-08-29 03:00:32 Re: bad estimates / non-scanning aggregates