Re: optimize query with a maximum(date) extraction

From: Gregory Stark <stark(at)enterprisedb(dot)com>
To: "Peter Childs" <peterachilds(at)gmail(dot)com>
Cc: <pgsql-performance(at)postgresql(dot)org>
Subject: Re: optimize query with a maximum(date) extraction
Date: 2007-09-05 14:23:23
Message-ID: 87tzq9p4x0.fsf@oxford.xeocode.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

"Peter Childs" <peterachilds(at)gmail(dot)com> writes:

> My personal reaction is why are you using distinct at all?
>
> why not
>
> select id,
> min(the_date) as min_date,
> max(the_date) as max_date
> from my_table group by id;
>
> Since 8.0 or was it earlier this will use an index should a reasonable one
> exist.

That's not true for this query. In fact that was precisely the original query
he as looking to optimize.

--
Gregory Stark
EnterpriseDB http://www.enterprisedb.com

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Gregory Stark 2007-09-05 14:28:53 Re: optimize query with a maximum(date) extraction
Previous Message Gregory Stark 2007-09-05 14:14:00 Re: optimize query with a maximum(date) extraction