Received: from localhost (unknown [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id E7AF39FB3F6 for ; Thu, 4 Oct 2007 15:00:46 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 21436-03 for ; Thu, 4 Oct 2007 15:00:36 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from newmail.silentmedia.com (earth.silentmedia.com [216.254.19.12]) by postgresql.org (Postfix) with ESMTP id E34059FB28E for ; Thu, 4 Oct 2007 15:00:37 -0300 (ADT) Received: by newmail.silentmedia.com (Postfix, from userid 99) id 6B10C35E3C6; Thu, 4 Oct 2007 11:00:31 -0700 (PDT) Received: from GRD (GRD [10.125.42.6]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by newmail.silentmedia.com (Postfix) with ESMTP id E07B535E3C4 for ; Thu, 4 Oct 2007 11:00:30 -0700 (PDT) Date: Thu, 4 Oct 2007 11:00:30 -0700 (PDT) From: Ben X-X-Sender: bench@localhost.localdomain To: pgsql-performance@postgresql.org Subject: quickly getting the top N rows Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200710/35 X-Sequence-Number: 27057 If I have this: create table foo (bar int primary key); ...then in my ideal world, Postgres would be able to use that index on bar to help me with this: select bar from foo order by bar desc limit 20; But in my experience, PG8.2 is doing a full table scan on foo, then sorting it, then doing the limit. I have a more complex primary key, but I was hoping the same concept would still apply. Am I doing something wrong, or just expecting something that doesn't exist?