Efficiently query for the most recent record for a given user

Поиск
Список
Период
Сортировка
От Robert DiFalco
Тема Efficiently query for the most recent record for a given user
Дата
Msg-id CAAXGW-yF4urbcPHRj2DwcmkzE66DeJfKQQ+sTmZX-BD_FXKecw@mail.gmail.com
обсуждение исходный текст
Ответы Re: Efficiently query for the most recent record for a given user  (Claudio Freire <klaussfreire@gmail.com>)
Список pgsql-performance
Let's say I have a table something like this:

   create table call_activity (
        id int8 not null,
        called timestamp,
        user_id int8 not null,
        primary key (id)
        foreign key (user_id) references my_users
    )


I want to get the last call_activity record for a single user.  Is there ANY way to efficiently retrieve the last record for a specified user_id, or do I need to de-normalize and update a table with a single row for each user each time a new call_activity record is inserted? I know I how to do the query without the summary table (subquery or GROUP BY with MAX) but that seems like it will never perform well for large data sets. Or am I full of beans and it should perform just fine for a huge data set as long as I have an index on "called"? 

Thanks in advance!

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

Предыдущее
От: Alexis Lê-Quôc
Дата:
Сообщение: Re: Better performance possible for a pathological query?
Следующее
От: Claudio Freire
Дата:
Сообщение: Re: Efficiently query for the most recent record for a given user