Re: optimize query with a maximum(date) extraction

Поиск
Список
Период
Сортировка
От hubert depesz lubaczewski
Тема Re: optimize query with a maximum(date) extraction
Дата
Msg-id 20070905132250.GA30304@depesz.com
обсуждение исходный текст
Ответ на Re: optimize query with a maximum(date) extraction  (Gregory Stark <stark@enterprisedb.com>)
Ответы Re: optimize query with a maximum(date) extraction  (Gregory Stark <stark@enterprisedb.com>)
Список pgsql-performance
On Wed, Sep 05, 2007 at 12:30:21PM +0100, Gregory Stark wrote:
> SELECT DISTINCT ON (id) id, the_date AS min_date FROM my_table ORDER BY id, the_date ASC
> SELECT DISTINCT ON (id) id, the_date AS max_date FROM my_table ORDER BY id, the_date DESC
> I think the first of these can actually use your index but the latter can't
> unless you create one for it specifically (which is not so easy -- it'll be
> easier in 8.3 though). Worse, I'm not really sure it'll be any faster than the
> query you already have.

it's easy to fix the second query (fix to use index) - just change order
by to:
order by id desc, the_date desc.

depesz

--
quicksil1er: "postgres is excellent, but like any DB it requires a
highly paid DBA.  here's my CV!" :)
http://www.depesz.com/ - blog dla ciebie (i moje CV)

В списке pgsql-performance по дате отправления:

Предыдущее
От: JS Ubei
Дата:
Сообщение: Re : optimize query with a maximum(date) extraction
Следующее
От: Gregory Stark
Дата:
Сообщение: Re: optimize query with a maximum(date) extraction