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

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Claudio Freire <klaussfreire(at)gmail(dot)com>
Cc: Robert DiFalco <robert(dot)difalco(at)gmail(dot)com>, "pgsql-performance(at)postgresql(dot)org" <pgsql-performance(at)postgresql(dot)org>
Subject: Re: Efficiently query for the most recent record for a given user
Date: 2013-08-07 19:04:09
Message-ID: 10453.1375902249@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Claudio Freire <klaussfreire(at)gmail(dot)com> writes:
> On Wed, Aug 7, 2013 at 3:34 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> 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 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 skeptical. Index searches are seldom purely sequential block
accesses. Maybe if you had a freshly built index that'd never yet
suffered any inserts/updates, but in practice any advantage would
disappear very quickly after a few index page splits.

> Though... true... for a limit 1... it wouldn't matter that much.

That's the other point.

regards, tom lane

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Alvaro Herrera 2013-08-07 19:05:48 Re: Efficiently query for the most recent record for a given user
Previous Message Claudio Freire 2013-08-07 18:39:45 Re: Efficiently query for the most recent record for a given user