Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 7A62B476564 for ; Mon, 27 Jan 2003 10:17:49 -0500 (EST) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by postgresql.org (Postfix) with ESMTP id A9618476574 for ; Mon, 27 Jan 2003 10:17:44 -0500 (EST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.6/8.12.6) with ESMTP id h0RFHd5u026517; Mon, 27 Jan 2003 10:17:39 -0500 (EST) To: Luca Fabbro Cc: pgsql-admin@postgresql.org Subject: Re: Index Scan Backward In-reply-to: <5.2.0.9.0.20030127154857.0231d078@mail.conecta.it> References: <5.2.0.9.0.20030127140822.02fe5828@mail.conecta.it> <5.2.0.9.0.20030127140822.02fe5828@mail.conecta.it> <5.2.0.9.0.20030127154857.0231d078@mail.conecta.it> Comments: In-reply-to Luca Fabbro message dated "Mon, 27 Jan 2003 15:52:03 +0100" Date: Mon, 27 Jan 2003 10:17:39 -0500 Message-ID: <26516.1043680659@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200301/285 X-Sequence-Number: 7127 Luca Fabbro writes: > Limit (cost=0.00..1003.36 rows=1 width=454) (actual time=806.78..2097.61 > rows=1 loops=1) > -> Nested Loop (cost=0.00..392651.18 rows=391 width=454) (actual > time=806.77..2097.59 rows=2 loops=1) > -> Index Scan Backward using forum_post_id_key on forum_post > p (cost=0.00..35615.95 rows=60668 width=450) (actual time=0.41..1122.09 > rows=42322 loops=1) > -> Index Scan using forum_topic_id_key on forum_topic > t (cost=0.00..5.87 rows=1 width=4) (actual time=0.02..0.02 rows=0 loops=42322) > Index Cond: ("outer".topicid = t.id) > Filter: (forumid = 44) > Total runtime: 2098.14 msec Hm. So the reason this is slow is it has to go back quite far in the id index before it finds something from forumid 44. The system is in fact estimating it as a moderately expensive query --- but not quite expensive enough. You might try raising RANDOM_PAGE_COST a little to see if that brings the cost estimates in line with reality. regards, tom lane