X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 1D2C13A4BC2 for ; Fri, 21 Jan 2005 17:27:04 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 59868-05 for ; Fri, 21 Jan 2005 17:26:47 +0000 (GMT) Received: from www.postgresql.com (unknown [200.46.204.209]) by svr1.postgresql.org (Postfix) with ESMTP id 24F4D3A4C07 for ; Fri, 21 Jan 2005 17:26:01 +0000 (GMT) Received: from anchor-post-35.mail.demon.net (anchor-post-35.mail.demon.net [194.217.242.85]) by www.postgresql.com (Postfix) with ESMTP id ADB507388F1 for ; Fri, 21 Jan 2005 17:25:59 +0000 (GMT) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-35.mail.demon.net with esmtp (Exim 4.42) id 1Cs2Rc-000Fe7-I6; Fri, 21 Jan 2005 17:19:36 +0000 Received: from [192.168.1.17] (client17.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id 97C3A168F7; Fri, 21 Jan 2005 17:20:55 +0000 (GMT) Message-ID: <41F139F7.6060904@archonet.com> Date: Fri, 21 Jan 2005 17:20:55 +0000 From: Richard Huxton User-Agent: Mozilla Thunderbird 1.0 (X11/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Robert Sanford Cc: pgsql-performance@postgresql.org Subject: Re: Profiling a function... References: <8343824939973D4FAC4AD93C1CF35944013A4147@orrtax_exchg3.nls.nlsholdings.com> In-Reply-To: <8343824939973D4FAC4AD93C1CF35944013A4147@orrtax_exchg3.nls.nlsholdings.com> Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.073 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200501/391 X-Sequence-Number: 10081 Robert Sanford wrote: > How do I profile a user-defined function so that I know which parts of the > function are the ones that are taking the biggest chunk of time? > > When I run EXPLAIN on the queries within the function none of them show up > as onerous burdens to the performance. But when they are all operating > together within the function and within the functional logic they become > really expensive. Obviously I've made a mistake somewhere but it isn't > obvious (otherwise it would be fixed already) and I'd prefer having a > profile report telling me what is taking so long rather than guessing and > possibly making things worse. > > So is there any way to get a line-by-line timing profile of a user-defined > function? Not really. What you can do is simulate the queries in functions by using PREPARE. You're probably seeing a difference because when PG plans the queries for functions/prepared queries it doesn't know the actual values. -- Richard Huxton Archonet Ltd