Re: Efficiently query for the most recent record for a given user
От
Claudio Freire
Тема
Re: Efficiently query for the most recent record for a
given user
Дата
Msg-id
CAGTBQpZUUOqF6adjmt62Hmc_OYRo3meaoNY9tn93sULRoovO_w@mail.gmail.com
Ответ на
Список
Дерево обсуждения
Efficiently query for the most recent record for a given user Robert DiFalco <robert.difalco@gmail.com>
Re: Efficiently query for the most recent record for a
given user Claudio Freire <klaussfreire@gmail.com>
Re: Efficiently query for the most recent record for a given user Tom Lane <tgl@sss.pgh.pa.us>
Re: Efficiently query for the most recent record for a
given user Claudio Freire <klaussfreire@gmail.com>
Re: Efficiently query for the most recent record for a given user Tom Lane <tgl@sss.pgh.pa.us>
Re: Efficiently query for the most recent record for a
given user Claudio Freire <klaussfreire@gmail.com>
Re: Efficiently query for the most recent record for a
given user Alvaro Herrera <alvherre@2ndquadrant.com>
Re: Efficiently query for the most recent record for a
given user Igor Neyman <ineyman@perceptron.com>
Re: Efficiently query for the most recent record for a
given user Robert DiFalco <robert.difalco@gmail.com>
On Wed, Aug 7, 2013 at 3:34 PM, Tom Lane wrote: > Claudio Freire writes: >> On Wed, Aug 7, 2013 at 3:12 PM, Robert DiFalco wrote: >>> I want to get the last call_activity record for a single user. > >> Create an index over (user_id, called desc), and do >> select * from call_activity where user_id = blarg order by called desc limit 1 > > Note that there's no particular need to specify "desc" in the index > definition. This same index can support searches in either direction > on the "called" column. Yeah, but it's faster if it's in the same direction, because the kernel read-ahead code detects sequential reads, whereas it doesn't when it goes backwards. The difference can be up to a factor of 10 for long index scans. Though... true... for a limit 1... it wouldn't matter that much. But it's become habit to match index sort order by now.
В списке pgsql-performance по дате отправления
От: Robert DiFalco
Дата:
От: Tom Lane
Дата: