Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id A723E9FB46A for ; Fri, 4 May 2007 21:57:13 -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 34243-04 for ; Fri, 4 May 2007 21:57:04 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 0FD809FB446 for ; Fri, 4 May 2007 21:57:08 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.6/8.13.6) with ESMTP id l450v7kA012823; Fri, 4 May 2007 20:57:07 -0400 (EDT) To: Gary Stainburn cc: pgsql-sql@postgresql.org Subject: Re: select slows from 3 seconds to 30 seconds In-reply-to: <200705041649.54193.gary.stainburn@ringways.co.uk> References: <200705041649.54193.gary.stainburn@ringways.co.uk> Comments: In-reply-to Gary Stainburn message dated "Fri, 04 May 2007 16:49:54 +0100" Date: Fri, 04 May 2007 20:57:07 -0400 Message-ID: <12822.1178326627@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200705/24 X-Sequence-Number: 28305 Gary Stainburn writes: > I have the query below which when run takes approx 3 seconds. However when I > add the condition 'and w_ws_id = 10' onto the end changes to 30+ seconds. > Can anyone see why? I've included the explain for the long select. You really ought to provide EXPLAIN ANALYZE output for both versions if you want intelligent commentary --- otherwise we're just guessing. But I would guess the problem is that the planner is way off about the number of rows satisfying the joint condition --- it thinks two: > -> Index Scan using walon_hide_index on walon (cost=0.00..85.04 rows=2 width=140) > Index Cond: (w_hide = 0) > Filter: (w_ws_id = 10) This plan is good if there really are only a couple rows, but degrades quickly if there are many... regards, tom lane