Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id A58C89FBD73 for ; Fri, 30 Mar 2007 07:46:28 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 08651-03 for ; Fri, 30 Mar 2007 07:46:25 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by postgresql.org (Postfix) with ESMTP id 3018E9FBD1B for ; Fri, 30 Mar 2007 07:46:25 -0300 (ADT) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.8/8.13.8) with ESMTP id l2UAkCoN000568 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 30 Mar 2007 04:46:16 -0600 (MDT) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.8/8.13.8) with ESMTP id l2UAkCYQ001643; Fri, 30 Mar 2007 04:46:12 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.8/8.13.8/Submit) id l2UAkBIw001642; Fri, 30 Mar 2007 04:46:11 -0600 (MDT) (envelope-from mfuhr) Date: Fri, 30 Mar 2007 04:46:11 -0600 From: Michael Fuhr To: Gaetano Mendola Cc: "pgsql-performance@postgresql.org" , Claus Guttesen Subject: Re: Wrong plan sequential scan instead of an index one Message-ID: <20070330104611.GA1540@winnie.fuhr.org> References: <460CD941.6080303@bigfoot.com> <460CE19A.3060909@bigfoot.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <460CE19A.3060909@bigfoot.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200703/443 X-Sequence-Number: 23848 On Fri, Mar 30, 2007 at 12:08:26PM +0200, Gaetano Mendola wrote: > Claus Guttesen wrote: > > Try changing random_page_cost from the default 4 to 2 in postgresql.conf: > > > > random_page_cost = 2 > > I have tuned that number already at 2.5, lowering it to 2 doesn't change > the plan. The following 19-fold overestimate is influencing the rest of the plan: -> Seq Scan on l_pvcp (cost=0.00..2.17 rows=19 width=4) (actual time=0.066..0.081 rows=1 loops=1) Filter: (value ~~* '%pi%'::text) Have you tried increasing the statistics target on l_pvcp.value? I ran your queries against canned data in 8.2.3 and better statistics resulted in more accurate row count estimates for this and other parts of the plan. I don't recall if estimates for non-leading-character matches in earlier versions can benefit from better statistics. -- Michael Fuhr