Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id DDC149FBC1D for ; Fri, 30 Mar 2007 08:33:51 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 33714-01 for ; Fri, 30 Mar 2007 08:33:43 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from pns.mm.eutelsat.org (pns.mm.eutelsat.org [194.214.173.227]) by postgresql.org (Postfix) with ESMTP id 3143B9FB8E2 for ; Fri, 30 Mar 2007 08:33:48 -0300 (ADT) Received: from mail.mm.eutelsat.org (localhost [127.0.0.1]) by pns.mm.eutelsat.org (8.11.6/linuxconf) with ESMTP id l2UBWF707022; Fri, 30 Mar 2007 13:32:18 +0200 Received: from [127.0.0.1] (accesspoint.mm.eutelsat.org [194.214.173.4]) by mail.mm.eutelsat.org (8.13.1/8.13.1) with ESMTP id l2UBa1g1012847; Fri, 30 Mar 2007 13:36:02 +0200 Message-ID: <460CF552.5000903@bigfoot.com> Date: Fri, 30 Mar 2007 13:32:34 +0200 From: Gaetano Mendola User-Agent: Thunderbird 2.0.0.0pre (Windows/20070328) MIME-Version: 1.0 To: "pgsql-performance@postgresql.org" CC: Michael Fuhr Subject: Re: Wrong plan sequential scan instead of an index one References: <460CD941.6080303@bigfoot.com> <460CE19A.3060909@bigfoot.com> <20070330104611.GA1540@winnie.fuhr.org> In-Reply-To: <20070330104611.GA1540@winnie.fuhr.org> X-Enigmail-Version: 0.95b Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: ClamAV version 0.88.7, clamav-milter version 0.88.7 on mail.mm.eutelsat.org X-Virus-Status: Clean X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200703/445 X-Sequence-Number: 23850 -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Michael Fuhr wrote: > 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. > test=# alter table l_pvcp alter column value set statistics 1000; ALTER TABLE test=# analyze l_pvcp; ANALYZE test=# explain analyze SELECT COUNT(id) FROM t_oa_2_00_card WHERE pvcp in (select id from l_pvcp where value ilike '%pi%'); QUERY PLAN - --------------------------------------------------------------------------------------------------------------------------------------- Aggregate (cost=154321.83..154321.84 rows=1 width=8) (actual time=4948.627..4948.628 rows=1 loops=1) -> Hash IN Join (cost=2.22..153877.08 rows=177898 width=8) (actual time=2.262..4940.395 rows=7801 loops=1) Hash Cond: ("outer".pvcp = "inner".id) -> Seq Scan on t_oa_2_00_card (cost=0.00..147695.25 rows=880125 width=12) (actual time=0.040..3850.074 rows=877682 loops=1) -> Hash (cost=2.17..2.17 rows=19 width=4) (actual time=0.073..0.073 rows=1 loops=1) -> Seq Scan on l_pvcp (cost=0.00..2.17 rows=19 width=4) (actual time=0.052..0.067 rows=1 loops=1) Filter: (value ~~* '%pi%'::text) Total runtime: 4948.717 ms (8 rows) and nothing changed. Regards Gaetano Mendola -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.5 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFGDPVS7UpzwH2SGd4RAp+DAJ9Z5HdDcKx9rOQDbm+uAdb8uEc8OgCgjGmM Z351j5icCHT4yMOLEu3ZcJY= =CY1c -----END PGP SIGNATURE-----