Merlin Moncure <mmoncure@xxxxxxxxx> writes: > On Thu, Apr 16, 2009 at 2:02 AM, Lists <lists@xxxxxxxxxxx> wrote: >> select comment_date >> from user_comments >> where user_comments.uid=1 >> order by comment_date desc limit 1 > try this: > create index comment_data_uid_idx on user_comments(uid, comment_date); > select * from user_comments where (uid, comment_date) < (1, high_date) > order by uid desc, comment_date desc limit 1; You don't really need to complicate your queries like that. Having the two-column index will suffice to make the given query work fine, at least in reasonably modern PG versions (since 8.1 I think). regards, tom lane -- Sent via pgsql-performance mailing list (pgsql-performance@xxxxxxxxxxxxxx) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance