Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 1150C96C49C for ; Sat, 18 Feb 2012 12:37:39 -0400 (AST) Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1RynHz-0002PD-U3 for pgsql-performance@postgresql.org; Sat, 18 Feb 2012 16:37:38 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id q1IGbMgq027855; Sat, 18 Feb 2012 11:37:22 -0500 (EST) To: Andreas Kretschmer cc: Steve Horn , pgsql-performance@postgresql.org Subject: Re: Query slow as Function In-reply-to: <20120218160244.GA23315@tux> References: <20120218160244.GA23315@tux> Comments: In-reply-to Andreas Kretschmer message dated "Sat, 18 Feb 2012 17:02:44 +0100" Date: Sat, 18 Feb 2012 11:37:22 -0500 Message-ID: <27854.1329583042@sss.pgh.pa.us> From: Tom Lane X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201202/132 X-Sequence-Number: 46304 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. regards, tom lane