Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 32CB59FB6A7 for ; Fri, 31 Aug 2007 18:38:30 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 91791-09 for ; Fri, 31 Aug 2007 18:38:20 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from mtai02.charter.net (mtai02.charter.net [209.225.8.182]) by postgresql.org (Postfix) with ESMTP id 6CDE19FB691 for ; Fri, 31 Aug 2007 18:38:25 -0300 (ADT) Received: from aa03.charter.net ([10.20.200.155]) by mtai02.charter.net (InterMail vM.7.08.02.00 201-2186-121-20061213) with ESMTP id <20070831213822.EWQH20157.mtai02.charter.net@aa03.charter.net>; Fri, 31 Aug 2007 17:38:22 -0400 Received: from [10.0.1.3] (really [66.188.165.91]) by aa03.charter.net with ESMTP id <20070831213821.EOMG7864.aa03.charter.net@[10.0.1.3]>; Fri, 31 Aug 2007 17:38:21 -0400 In-Reply-To: References: <373D2F52-E9CD-485A-9BF1-B019349FA5EC@seespotcode.net> Mime-Version: 1.0 (Apple Message framework v752.2) Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: Cc: pgsql-sql@postgresql.org Content-Transfer-Encoding: 7bit From: Michael Glaesemann Subject: Re: How to influence the planner Date: Fri, 31 Aug 2007 16:38:20 -0500 To: Richard Ray X-Mailer: Apple Mail (2.752.2) X-Chzlrs: 0 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200708/272 X-Sequence-Number: 29210 On Aug 31, 2007, at 16:07 , Richard Ray wrote: > Total runtime: 2349614.258 ms > (3 rows) Wow. Nearly 40 minutes! What are your work_mem set at? You may want to increase work_mem, as it might help with the sort. > The index for foo on t1 is the primary index t1_pkey > Why is it slower using the index Using an index requires first scanning the index and then looking up the value in the table, so depending on the number of rows that need to be returned, using an index might have more overhead than just reading every row of the table (i.e., a sequential scan). >> Have you recently ANALYZEd t1? > > I run vacuum analyze nightly That might not be often enough. Looking at the number of rows in the cost estimate (60K rows) and the actual number of rows (~30K rows), it looks like there's a factor of two difference. >> If length(bar) = 0 is a common operation on this table, you might >> consider using an expression index on t1: >> >> create index t1_length_bar_idx on t1 (length(bar)); > > This is a one time procedure to fix some data but I've had this > problem before Depending on the time it takes to build the index, it might prove worthwhile even for a one-off query. You're pretty much doing this by using a temporary table though. > I'm running PostgreSQL 8.1.0 on Fedora Core 6 You should upgrade 8.1.9, the latest in the 8.1.x series. This may not help your performance issues, but there have been 9 point releases since the version you're running which include bug and security fixes. Even better, upgrade to 8.2.4, as there may very well be performance improvements in 8.2 which help you. You could look through the 8.2 release notes to see if any might apply. Hope this helps. Michael Glaesemann grzm seespotcode net