Received: from localhost (unknown [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 566859FB3E6 for ; Thu, 4 Oct 2007 15:52:25 -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 48281-03 for ; Thu, 4 Oct 2007 15:52:16 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 915B79FB313 for ; Thu, 4 Oct 2007 15:52:18 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.1/8.14.1) with ESMTP id l94IqAa5003786; Thu, 4 Oct 2007 14:52:10 -0400 (EDT) To: Ben cc: Bill Moran , pgsql-performance@postgresql.org Subject: Re: quickly getting the top N rows In-reply-to: References: <20071004141411.9509fe66.wmoran@collaborativefusion.com> Comments: In-reply-to Ben message dated "Thu, 04 Oct 2007 11:33:39 -0700" Date: Thu, 04 Oct 2007 14:52:10 -0400 Message-ID: <3785.1191523930@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200710/40 X-Sequence-Number: 27062 Ben writes: > No, the tables are recently analyzed and there are a couple hundred > thousand rows in there. But I think I just figured it out.... it's a > 3-column index, and two columns of that index are the same for every row. > When I drop those two columns from the ordering restriction, the index > gets used and things speed up 5 orders of magnitude. > Maybe the planner is smart enough to think that if a column in the order > by clause is identical for most rows, then using an index won't help.... > but not smart enough to realize that if said column is at the *end* of the > order by arguments, after columns which do sort quite well, then it should > use an index after all. You're being about as clear as mud here, except that you obviously lied about what you were doing in your first message. If you have a planner problem, show us the *exact* query, the *exact* table definition, and unfaked EXPLAIN ANALYZE output. regards, tom lane