Received: from sss.pgh.pa.us ([192.204.191.242]) by postgresql.org (8.11.3/8.11.4) with ESMTP id g1EF6EE79293 for ; Thu, 14 Feb 2002 10:06:14 -0500 (EST) (envelope-from tgl@sss.pgh.pa.us) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.11.4/8.11.4) with ESMTP id g1EF69f08620; Thu, 14 Feb 2002 10:06:09 -0500 (EST) To: Brian McCane cc: pg-admin Subject: Re: Useless index In-reply-to: <20020214074001.N83588-100000@fw.mccons.net> References: <20020214074001.N83588-100000@fw.mccons.net> Comments: In-reply-to Brian McCane message dated "Thu, 14 Feb 2002 07:59:54 -0600" Date: Thu, 14 Feb 2002 10:06:09 -0500 Message-ID: <8617.1013699169@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200202/176 X-Sequence-Number: 3331 Brian McCane writes: > CREATE INDEX foo_index ON foo (bazid, score desc) ; > Which would be exactly what I want, and would complete in a split second. > Instead, this thing runs FOREVER (okay, it just seems that way to my > client :). Is there any way to get the equivalent index from PostgreSQL? You don't need a funny index, you just need to get the planner to notice that that index can serve to create the desired output ordering. Try create table foo(bazid int, score int); CREATE INDEX foo_index ON foo (bazid, score) ; explain select * from foo where bazid = 123456 order by bazid desc, score desc limit 100 ; NOTICE: QUERY PLAN: Limit (cost=0.00..17.07 rows=5 width=8) -> Index Scan Backward using foo_index on foo (cost=0.00..17.07 rows=5 width=8) EXPLAIN regards, tom lane