Re: [PERFORM] Efficiently query for the most recent record for a given user

2013-08-08 Thread Claudio Freire
On Thu, Aug 8, 2013 at 5:01 PM, Kevin Grittner wrote: > Claudio Freire wrote: >> On Wed, Aug 7, 2013 at 4:04 PM, Tom Lane wrote: 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 backwa

Re: [PERFORM] Efficiently query for the most recent record for a given user

2013-08-07 Thread Claudio Freire
On Wed, Aug 7, 2013 at 4:04 PM, Tom Lane wrote: >> 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. > > Color me ske

Re: [PERFORM] Efficiently query for the most recent record for a given user

2013-08-07 Thread Alvaro Herrera
Claudio Freire escribió: > On Wed, Aug 7, 2013 at 3:34 PM, Tom Lane wrote: > > 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 d

Re: [PERFORM] Efficiently query for the most recent record for a given user

2013-08-07 Thread Tom Lane
Claudio Freire writes: > On Wed, Aug 7, 2013 at 3:34 PM, Tom Lane wrote: >> 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 directio

Re: [PERFORM] Efficiently query for the most recent record for a given user

2013-08-07 Thread Claudio Freire
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 u

Re: [PERFORM] Efficiently query for the most recent record for a given user

2013-08-07 Thread Robert DiFalco
M > > To: Robert DiFalco > > Cc: pgsql-performance@postgresql.org > > Subject: Re: [PERFORM] Efficiently query for the most recent record for a > > given user > > > > On Wed, Aug 7, 2013 at 3:12 PM, Robert DiFalco > > > wrote: > > > Let'

Re: [PERFORM] Efficiently query for the most recent record for a given user

2013-08-07 Thread Igor Neyman
[PERFORM] Efficiently query for the most recent record for a > given user > > On Wed, Aug 7, 2013 at 3:12 PM, Robert DiFalco > wrote: > > Let's say I have a table something like this: > > > >create table call_activity ( > > id int8 not null, &

Re: [PERFORM] Efficiently query for the most recent record for a given user

2013-08-07 Thread Tom Lane
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 th

Re: [PERFORM] Efficiently query for the most recent record for a given user

2013-08-07 Thread Claudio Freire
On Wed, Aug 7, 2013 at 3:12 PM, Robert DiFalco wrote: > 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 m

[PERFORM] Efficiently query for the most recent record for a given user

2013-08-07 Thread Robert DiFalco
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 sing