Re: SQL Help - Finding Next Lowest Value of Current Row Value

Поиск
Список
Период
Сортировка
От Chris Travers
Тема Re: SQL Help - Finding Next Lowest Value of Current Row Value
Дата
Msg-id CAKt_Zfs-FE9m=hgPwgS2mLXOC117NaWrMkrNZkfE8adxkKnryw@mail.gmail.com
обсуждение исходный текст
Ответ на SQL Help - Finding Next Lowest Value of Current Row Value  (Jeff Adams <Jeff.Adams@noaa.gov>)
Список pgsql-general
On Sat, Oct 1, 2011 at 2:30 PM, Jeff Adams <Jeff.Adams@noaa.gov> wrote:
> Greetings,
>
> I have a large table (~19 million records). Records contains a field
> identifying a vessel and a field containing an time (epoch). Using the
> current rows vessel and time values, I need to be able to find the next
> lowest time value for the vessel and use it to compute how much time has
> elapsed between the records. I have tried a scalar subquery in the SELECT,
> which works, but it runs quite slowly. Is there an alternative approach that
> might perform better for this type of query. Any information would be
> greatly appreciated. Thanks...
>
How many rows per vessel?

Either way it seems to me we are talking about selecting the current
record, and then selecting the max of another record within a
timeframe.  I would probably use a plpgsql function that would do this
in two stages, ideally being able to do an index scan twice....

Best Wishes,
Chris Travers

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

Предыдущее
От: Andreas
Дата:
Сообщение: Log-Info Replication
Следующее
От: "Reuven M. Lerner"
Дата:
Сообщение: Searching for "bare" letters