Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 15A8964FEBD for ; Fri, 14 Nov 2008 08:37:33 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 85999-01 for ; Fri, 14 Nov 2008 08:37:29 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from vilnius.balt.net (vilnius.balt.net [195.14.170.14]) by mail.postgresql.org (Postfix) with ESMTP id C6EA564FEA5 for ; Fri, 14 Nov 2008 08:37:29 -0400 (AST) Received: from nSoft.lt (unknown [217.117.29.29]) by vilnius.balt.net (Postfix) with ESMTP id 8534D3B9DAA for ; Fri, 14 Nov 2008 14:37:25 +0200 (EET) Received: from [192.168.16.113] (unknown [192.168.16.113]) by nSoft.lt (Postfix) with ESMTP id C741EBF060 for ; Fri, 14 Nov 2008 15:35:18 +0000 (GMT) Message-ID: <491D7103.7000105@nsoft.lt> Date: Fri, 14 Nov 2008 14:37:23 +0200 From: Julius Tuskenis User-Agent: Thunderbird 2.0.0.17 (Windows/20080914) MIME-Version: 1.0 To: "pgsql-admin@postgresql.org" Subject: Re: function executes sql 100 times longer it should References: <491AE3F2.601@nsoft.lt> <1226500247.2221.2.camel@lin-it1.eaglepress.local> <491BE279.50702@nsoft.lt> <9b1af80e0811130345o37666c5dob841d93954826357@mail.gmail.com> <491C2BA5.7080401@nsoft.lt> <9b1af80e0811130744o7421d79bue68d58b04167a929@mail.gmail.com> In-Reply-To: <9b1af80e0811130744o7421d79bue68d58b04167a929@mail.gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200811/75 X-Sequence-Number: 30729 once again - thank you Vyacheslav for your quick answer. I have to ask you one more question - is it possible to make a planer act according to passed parameters, or is the plan predefined on creating the function? Vyacheslav Kalinin rašė: > Apparently your problem starts here: > > > -> Function Scan on filter_b_preke_matoma (cost=0.00..267.50 > rows=5 width=126) (actual time=6.580..11.766 rows=2820 loops=1) > > Filter: > (((prek_pavadinimas)::text ~~* (('%'::text || ($3)::text) || > '%'::text)) OR ($3 IS NULL)) > > Planner expects to see only somewhat 5 rows after function scan with > the filter but get ~3000, which is not a surprise if one looks at your > plain SQL query, corresponding WHERE part: > > AND ((prek_pavadinimas ILIKE ('%'||null||'%')) OR null is NULL) > > As I mentioned conditions like this get wrapped (to TRUE in your > case), so with plain SQL planner does not even try to estimate ILIKE > filter effect. > > -- Julius Tuskenis Programavimo skyriaus vadovas UAB nSoft mob. +37068233050