Re: Shouldn't the planner have a higher cost for reverse index scans? - Mailing list pgsql-performance

From Tom Lane
Subject Re: Shouldn't the planner have a higher cost for reverse index scans?
Date
Msg-id 18553.1239896194@sss.pgh.pa.us
Whole thread Raw
In response to Re: Shouldn't the planner have a higher cost for reverse index scans?  (Merlin Moncure <mmoncure@gmail.com>)
List pgsql-performance
Merlin Moncure <mmoncure@gmail.com> writes:
> On Thu, Apr 16, 2009 at 2:02 AM, Lists <lists@on-track.ca> 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

pgsql-performance by date:

Previous
From: Merlin Moncure
Date:
Subject: Re: Really dumb planner decision
Next
From: Tom Lane
Date:
Subject: Re: Shouldn't the planner have a higher cost for reverse index scans?