Re: Picking out the most recent row using a time stamp column

Поиск
Список
Период
Сортировка
От Dave Crooke
Тема Re: Picking out the most recent row using a time stamp column
Дата
Msg-id AANLkTimSmjGrCqwZWRXU1_=FW0adbWdxLXMK0n=Vw+Cc@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Picking out the most recent row using a time stamp column  ("Kevin Grittner" <Kevin.Grittner@wicourts.gov>)
Ответы Re: Picking out the most recent row using a time stamp column  (Josh Berkus <josh@agliodbs.com>)
Re: Picking out the most recent row using a time stamp column  (Dave Johansen <davejohansen@gmail.com>)
Список pgsql-performance
Thanks to all .... I had a tickling feeling at the back of my mind that there was a neater answer here. For the record, times (all from in-memory cached data, averaged over a bunch of runs):

Dependent subquery = 117.9 seconds
Join to temp table = 2.7 sec
DISTINCT ON = 2.7 sec

So the DISTINCT ON may not be quicker, but it sure is tidier.

Cheers
Dave

On Thu, Feb 24, 2011 at 2:24 PM, Kevin Grittner <Kevin.Grittner@wicourts.gov> wrote:
Michael Glaesemann <grzm@seespotcode.net> wrote:

> SELECT DISTINCT ON (data.id_key)
>        data.id_key, data.time_stamp, data.value
>   FROM data
>   ORDER BY data.id_key, data.time_stamp DESC;

Dang!  I forgot the DESC in my post!  Thanks for showing the
*correct* version.

-Kevin

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

Предыдущее
От: Merlin Moncure
Дата:
Сообщение: Re: Picking out the most recent row using a time stamp column
Следующее
От: Dave Crooke
Дата:
Сообщение: Possible parser bug? .... Re: Picking out the most recent row using a time stamp column