Received: from localhost (unknown [200.46.204.183]) by developer.postgresql.org (Postfix) with ESMTP id CBE112E0082 for ; Wed, 16 Apr 2008 17:24:41 -0300 (ADT) Received: from developer.postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 99279-08 for ; Wed, 16 Apr 2008 17:24:34 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by developer.postgresql.org (Postfix) with ESMTP id BA9292E005F for ; Wed, 16 Apr 2008 17:24:34 -0300 (ADT) 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 m3GKOWED018100; Wed, 16 Apr 2008 16:24:32 -0400 (EDT) To: "Gavin M. Roy" cc: pgsql-performance@postgresql.org Subject: Re: SQL Function Slowness, 8.3.0 In-reply-to: References: <8328.1208358587@sss.pgh.pa.us> Comments: In-reply-to "Gavin M. Roy" message dated "Wed, 16 Apr 2008 14:44:40 -0400" Date: Wed, 16 Apr 2008 16:24:32 -0400 Message-ID: <18099.1208377472@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200804/215 X-Sequence-Number: 29708 "Gavin M. Roy" writes: > After detailed examination of pg_stat_user_indexes usage, it's clear that > the functions don't use the same indexes. I've casted everything to match > the indexes in the SQL function, to no success. Any suggestions on next > steps? Maybe for 8.4 we could find a way to explain analyze function > internals ;-) Yeah, this could be easier, but it's certainly possible to examine the plan generated for a function's parameterized statement. For instance, say you're wondering about the plan for create function foo(int, text) ... as $$ select * from bar where f1 = $1 and f2 = $2 $$ language sql What you do is prepare p(int, text) as select * from bar where f1 = $1 and f2 = $2 ; explain analyze execute p(42, 'hello world'); It works exactly the same for statements in plpgsql functions, remembering that both parameters and local variables of the function have to become $n placeholders. Remember to make the parameters of the prepared statement have the same declared types as the function's parameters and variables. regards, tom lane