Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id A60489FBE2E for ; Fri, 30 Mar 2007 07:37: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 27285-05 for ; Fri, 30 Mar 2007 07:37:21 -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 E3C209FBE1E for ; Fri, 30 Mar 2007 07:37:24 -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 ED97E143B3F; Fri, 30 Mar 2007 11:33:25 +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 C95722740DF; Fri, 30 Mar 2007 11:33:25 +0100 (BST) Message-ID: <460CE775.8080908@archonet.com> Date: Fri, 30 Mar 2007 11:33:25 +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> <460CDCDC.7020901@archonet.com> <460CE359.8060208@bigfoot.com> In-Reply-To: <460CE359.8060208@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/441 X-Sequence-Number: 23846 Gaetano Mendola wrote: > > Richard Huxton wrote: >> >> 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? > > I don't know what do you mean for strange, this is the distribution: > > test=# select count(*) from t_oa_2_00_card; > count > - -------- > 877682 > (1 row) > > test=# select count(*), pvcp from t_oa_2_00_card group by pvcp; > count | pvcp > - -------+------ > (92 rows) > > > I think that estimate is something like: 877682 / 92 * 19 So if you actually had 19 matches for '%pi%' it might be a sensible plan then. I'm afraid I don't know of any way to improve PG's prediction on how many matches you'll get for a substring pattern though. -- Richard Huxton Archonet Ltd