X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id D4DB89DC981 for ; Sat, 18 Feb 2006 01:53:07 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 63977-08 for ; Sat, 18 Feb 2006 01:53:07 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 9ED8D9DC94C for ; Sat, 18 Feb 2006 01:53:05 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k1I5r49u015894; Sat, 18 Feb 2006 00:53:04 -0500 (EST) To: Adam Alkins cc: pgsql-performance@postgresql.org Subject: Re: Index Choice Problem In-reply-to: References: Comments: In-reply-to Adam Alkins message dated "Thu, 16 Feb 2006 13:03:29 -0400" Date: Sat, 18 Feb 2006 00:53:04 -0500 Message-ID: <15893.1140241984@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.11 required=5 tests=[AWL=0.110] X-Spam-Score: 0.11 X-Spam-Level: X-Archive-Number: 200602/304 X-Sequence-Number: 17290 Adam Alkins writes: > SELECT t.topic_id > FROM phpbb_topics AS t > WHERE t.forum_id = 71 > AND t.topic_id NOT IN (205026, 29046, 144569, 59780, 187424, > 138635, 184973, 170551, 22419, 181690, 197254, 205130) > ORDER BY t.topic_last_post_time DESC > LIMIT 23 OFFSET 0 If you're using 8.1, you'd probably find that an index on (forum_id, topic_last_post_time) would work nicely for this. You could use it in prior versions too, but you'd have to spell the ORDER BY rather strangely: ORDER BY forum_id desc, topic_last_post_time desc The reason for this trickery is to get the planner to realize that the index order matches the ORDER BY ... regards, tom lane