Re: The usual sequential scan, but with LIMIT ! - Mailing list pgsql-performance

From Tom Lane
Subject Re: The usual sequential scan, but with LIMIT !
Date
Msg-id 29692.1094564867@sss.pgh.pa.us
Whole thread Raw
In response to Re: The usual sequential scan, but with LIMIT !  (Pierre-Frédéric Caillaud<lists@boutiquenumerique.com>)
Responses Re: The usual sequential scan, but with LIMIT !
List pgsql-performance
=?iso-8859-15?Q?Pierre-Fr=E9d=E9ric_Caillaud?= <lists@boutiquenumerique.com> writes:
>     suppose I SELECT WHERE topic_id=2 ORDER BY topic_id ASC,id DESC.
>     Postgres does a seq scan, but it could think a bit more and start at
> "first index node which has topic_id>2" (simple to find in a btree) then
> go backwards in the index.

If you write it as
    SELECT WHERE topic_id=2 ORDER BY topic_id DESC,id DESC.
then an index on (topic_id, id) will work fine.  The mixed ASC/DESC
ordering is not compatible with the index.

            regards, tom lane

pgsql-performance by date:

Previous
From: G u i d o B a r o s i o
Date:
Subject: Re: [ADMIN] TOAST tables, cannot truncate
Next
From: Tom Lane
Date:
Subject: Re: [ADMIN] TOAST tables, cannot truncate