Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id B719E6334E4 for ; Thu, 8 Apr 2010 12:44:10 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 46673-05 for ; Thu, 8 Apr 2010 15:44:00 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from marajade.localdomain (vcs5.camavision.com [63.228.164.252]) by mail.postgresql.org (Postfix) with ESMTP id 4B73F632A1A for ; Thu, 8 Apr 2010 12:44:00 -0300 (ADT) Received: from [192.168.10.84] (unknown [192.168.10.84]) (Authenticated sender: andy) by marajade.localdomain (Postfix) with ESMTPA id E87BC5B797; Thu, 8 Apr 2010 09:43:58 -0500 (CDT) Message-ID: <4BBDF9C9.9050504@squeakycode.net> Date: Thu, 08 Apr 2010 10:44:09 -0500 From: Andy Colson User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.9) Gecko/20100317 Lightning/1.0b1 Thunderbird/3.0.4 MIME-Version: 1.0 To: Sabin Coanda , pgsql-performance@postgresql.org Subject: Re: How check execution plan of a function References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.001 tagged_above=-10 required=5 tests=BAYES_50=0.001 X-Spam-Level: X-Archive-Number: 201004/105 X-Sequence-Number: 38355 On Wed Apr 7 2010 7:47 AM, Sabin Coanda wrote: > Hi there, > > I have a function which returns setof record based on a specific query. > I try to check the execution plan of that query, so I write EXPLAIN ANALYZE > before my select, I call the function and I see the result which shows an > actual time about 5 seconds. But when I call my function after I remove > EXPLAIN ANALYZE it takes more than 300 seconds, and I cancel it. > > What's happen, or how can I see the function execution plan to optimize it ? > > TIA, > Sabin > > I ran into the same problems, what I did was enable the logging in postgresql.conf. I dont recall exactly what I enabled, but it was something like: track_functions = pl log_statement_stats = on log_duration = on Then in the serverlog you can see each statement, and how long it took. Once I found a statement that was slow I used explain analyze on just it so I could optimize that one statement. -Andy