Skip site navigation (1) Skip section navigation (2)

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 (view raw or flat)
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

pgsql-performance by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group