X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 291865E40BA for ; Tue, 7 Sep 2004 14:47:50 +0100 (BST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 01492-06 for ; Tue, 7 Sep 2004 13:47:46 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id AC5255E47C4 for ; Tue, 7 Sep 2004 14:47:42 +0100 (BST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.11/8.12.11) with ESMTP id i87Dlld3029693; Tue, 7 Sep 2004 09:47:48 -0400 (EDT) To: =?iso-8859-15?Q?Pierre-Fr=E9d=E9ric_Caillaud?= Cc: pgsql-performance@postgresql.org Subject: Re: The usual sequential scan, but with LIMIT ! In-reply-to: References: <4134BF36.3000504@syscor.com> <413BA104.1040508@geizhals.at> <14846.1094488841@sss.pgh.pa.us> Comments: In-reply-to =?iso-8859-15?Q?Pierre-Fr=E9d=E9ric_Caillaud?= message dated "Tue, 07 Sep 2004 08:51:54 +0200" Date: Tue, 07 Sep 2004 09:47:47 -0400 Message-ID: <29692.1094564867@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200409/44 X-Sequence-Number: 8172 =?iso-8859-15?Q?Pierre-Fr=E9d=E9ric_Caillaud?= 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