Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 9208296C49C for ; Sat, 18 Feb 2012 12:41:50 -0400 (AST) Received: from relay4-d.mail.gandi.net ([217.70.183.196]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1RynM3-0002To-10 for pgsql-performance@postgresql.org; Sat, 18 Feb 2012 16:41:49 +0000 X-Originating-IP: 217.70.178.144 Received: from mfilter16-d.gandi.net (mfilter16-d.gandi.net [217.70.178.144]) by relay4-d.mail.gandi.net (Postfix) with ESMTP id 9BC0A172097; Sat, 18 Feb 2012 17:41:23 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at mfilter16-d.gandi.net Received: from relay4-d.mail.gandi.net ([217.70.183.196]) by mfilter16-d.gandi.net (mfilter16-d.gandi.net [10.0.15.180]) (amavisd-new, port 10024) with ESMTP id 6WSX8EkaZi7A; Sat, 18 Feb 2012 17:41:22 +0100 (CET) X-Originating-IP: 98.27.54.176 Received: from [192.168.10.146] (cpe-098-027-054-176.nc.res.rr.com [98.27.54.176]) (Authenticated sender: adsend@dunslane.net) by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id 2078D172067; Sat, 18 Feb 2012 17:41:19 +0100 (CET) Message-ID: <4F3FD4AE.30908@dunslane.net> Date: Sat, 18 Feb 2012 11:41:18 -0500 From: Andrew Dunstan User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0) Gecko/20120131 Thunderbird/10.0 MIME-Version: 1.0 To: Tom Lane CC: Andreas Kretschmer , Steve Horn , pgsql-performance@postgresql.org Subject: Re: Query slow as Function References: <20120218160244.GA23315@tux> <27854.1329583042@sss.pgh.pa.us> In-Reply-To: <27854.1329583042@sss.pgh.pa.us> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201202/133 X-Sequence-Number: 46305 On 02/18/2012 11:37 AM, Tom Lane wrote: > Andreas Kretschmer writes: >> You can check the plan with the auto_explain - Extension, and you can >> force the planner to create a plan based on the actual input-value by >> using dynamic SQL (EXECUTE 'your query string' inside the function) > Steve *is* using EXECUTE, so that doesn't seem to be the answer. I'm > wondering about datatype mismatches myself --- the function form is > forcing the parameter to be char(9), which is not a constraint imposed > in the written-out query. There are lots of other possibilities > though. It would be hard to say much without a self-contained example > to try. > > He's using EXECUTE ... USING. Does that plan with the used parameter? cheers andrew