Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 93AD79FBDBB for ; Fri, 30 Mar 2007 06:56:18 -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 40979-01 for ; Fri, 30 Mar 2007 06:56:14 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from mail.metronet.co.uk (mail.metronet.co.uk [213.162.97.75]) by postgresql.org (Postfix) with ESMTP id 557DD9FBA2B for ; Fri, 30 Mar 2007 06:56:14 -0300 (ADT) Received: from server3.office.archonet.com (84-51-143-99.archon037.adsl.metronet.co.uk [84.51.143.99]) by smtp.metronet.co.uk (MetroNet Mail) with ESMTP id 70FAF143F5F; Fri, 30 Mar 2007 10:48:12 +0100 (BST) Received: from [192.168.1.36] (dell36.office.archonet.com [192.168.1.36]) by server3.office.archonet.com (Postfix) with ESMTP id 4B89527408E; Fri, 30 Mar 2007 10:48:12 +0100 (BST) Message-ID: <460CDCDC.7020901@archonet.com> Date: Fri, 30 Mar 2007 10:48:12 +0100 From: Richard Huxton User-Agent: IceDove 1.5.0.9 (X11/20061220) MIME-Version: 1.0 To: Gaetano Mendola Cc: "pgsql-performance@postgresql.org" Subject: Re: Wrong plan sequential scan instead of an index one References: <460CD941.6080303@bigfoot.com> In-Reply-To: <460CD941.6080303@bigfoot.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200703/438 X-Sequence-Number: 23843 Gaetano Mendola wrote: > -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 > > Hi all, take a look at those plans: > > > test=# explain analyze SELECT COUNT(id) FROM t_oa_2_00_card WHERE > pvcp in (select id from l_pvcp where value ilike '%pi%'); > -> Hash IN Join (cost=2.22..153835.49 rows=177404 width=8) (actual > time=2.908..4001.814 rows=7801 loops=1) Hash Cond: ("outer".pvcp = > "inner".id) > Isn't too much choose a sequential scan due to 19 estimated rows when > with 4 estimated does a correct index scan ? I don't think it's the matches on l_pvcp that's the problem, it's the fact that it thinks its getting 177404 rows matching the IN. Now, why 19 rows from the subquery should produce such a large estimate in the outer query I'm not sure. Any strange distribution of values on pvcp? -- Richard Huxton Archonet Ltd