Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id E17209FB1CC for ; Tue, 16 Jan 2007 18:21:12 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-new, port 10024) with ESMTP id 98166-01 for ; Tue, 16 Jan 2007 18:20:45 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from out4.smtp.messagingengine.com (out4.smtp.messagingengine.com [66.111.4.28]) by postgresql.org (Postfix) with ESMTP id 6D6B29FB32B for ; Tue, 16 Jan 2007 18:20:54 -0400 (AST) Received: from out1.internal (unknown [10.202.2.149]) by out1.messagingengine.com (Postfix) with ESMTP id 7862A7DB43; Tue, 16 Jan 2007 17:20:53 -0500 (EST) Received: from web2.messagingengine.com ([10.202.2.211]) by out1.internal (MEProxy); Tue, 16 Jan 2007 17:20:53 -0500 Received: by web2.messagingengine.com (Postfix, from userid 99) id 3BFC8D68C; Tue, 16 Jan 2007 17:20:53 -0500 (EST) Message-Id: <1168986053.16393.1169598917@webmail.messagingengine.com> X-Sasl-Enc: R/OaQ7diQMbY/ooj9NPgCyhqzb5FSPmnXuK+NxQW9HO/ 1168986053 From: "Jeremy Haile" To: "Tom Lane" Cc: pgsql-performance@postgresql.org Content-Disposition: inline Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="ISO-8859-1" MIME-Version: 1.0 X-Mailer: MessagingEngine.com Webmail Interface References: <1168982580.8275.1169588211@webmail.messagingengine.com> <26412.1168983547@sss.pgh.pa.us> Subject: Re: PG8.2.1 choosing slow seqscan over idx scan In-Reply-To: <26412.1168983547@sss.pgh.pa.us> Date: Tue, 16 Jan 2007 17:20:53 -0500 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200701/246 X-Sequence-Number: 22847 Thanks Tom! Reducing random_page_cost to 2 did the trick for this query. It now favors the index scan. Even if this is a cached situation, I wouldn't expect a difference of 3 min vs 3 seconds. Even if unrelated, do you think disk fragmentation would have negative effects? Is it worth trying to defragment the drive on a regular basis in Windows? Jeremy Haile On Tue, 16 Jan 2007 16:39:07 -0500, "Tom Lane" said: > "Jeremy Haile" writes: > > Running PostgreSQL 8.2.1 on Win32. The query planner is choosing a seq > > scan over index scan even though index scan is faster (as shown by > > disabling seqscan). Table is recently analyzed and row count estimates > > seem to be in the ballpark. > > Try reducing random_page_cost a bit. Keep in mind that you are probably > measuring a fully-cached situation here, if you repeated the test case. > If your database fits into memory reasonably well then that's fine and > you want to optimize for that case ... but otherwise you may find > yourself pessimizing the actual behavior. > > regards, tom lane