From: Tom Lane <tgl@sss.pgh.pa.us>
To: Claudio Freire <klaussfreire@gmail.com>
Cc: Robert DiFalco <robert.difalco@gmail.com>
Cc: pgsql-performance@postgresql.org <pgsql-performance@postgresql.org>
Subject: Re: Efficiently query for the most recent record for a given user
Date: Wed, 07 Aug 2013 14:34:12 -0400
Message-ID: <9813.1375900452@sss.pgh.pa.us> (raw)
In-Reply-To: <CAGTBQpY5pDZBgpo+huLzUpi6zve69V7KKWUVeLaSBpr6ZvOLwQ@mail.gmail.com>
References: <CAAXGW-yF4urbcPHRj2DwcmkzE66DeJfKQQ+sTmZX-BD_FXKecw@mail.gmail.com>
<CAGTBQpY5pDZBgpo+huLzUpi6zve69V7KKWUVeLaSBpr6ZvOLwQ@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-performance>
Claudio Freire <klaussfreire@gmail.com> writes:
> On Wed, Aug 7, 2013 at 3:12 PM, Robert DiFalco <robert.difalco@gmail.com> 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.
regards, tom lane
--
Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-performance
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: tgl@sss.pgh.pa.us, klaussfreire@gmail.com, robert.difalco@gmail.com
Subject: Re: Efficiently query for the most recent record for a given user
In-Reply-To: <9813.1375900452@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox