Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 43892B5DC1C for ; Fri, 28 Oct 2011 02:02:58 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 72219-01-7 for ; Fri, 28 Oct 2011 05:02:52 +0000 (UTC) X-Greylist: delayed 00:06:01.411839 by SQLgrey-1.8.0-rc2 Received: from mail-yw0-f46.google.com (mail-yw0-f46.google.com [209.85.213.46]) by mail.postgresql.org (Postfix) with ESMTP id 44AA0B5DE2E for ; Fri, 28 Oct 2011 02:00:52 -0300 (ADT) Received: by ywm3 with SMTP id 3so3341026ywm.19 for ; Thu, 27 Oct 2011 22:00:51 -0700 (PDT) Received: by 10.68.12.105 with SMTP id x9mr2371689pbb.109.1319777689924; Thu, 27 Oct 2011 21:54:49 -0700 (PDT) Received: from issac.consistentstate.com (c-67-165-192-103.hsd1.co.comcast.net. [67.165.192.103]) by mx.google.com with ESMTPS id d8sm20539482pbb.6.2011.10.27.21.54.48 (version=SSLv3 cipher=OTHER); Thu, 27 Oct 2011 21:54:48 -0700 (PDT) Message-ID: <4EAA3597.3020202@consistentstate.com> Date: Thu, 27 Oct 2011 22:54:47 -0600 From: CS DBA User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.23) Gecko/20110928 Fedora/3.1.15-1.fc14 Lightning/1.0b2 Thunderbird/3.1.15 MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: function slower than the same code in an sql file 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=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201110/241 X-Sequence-Number: 45463 Hi All ; I have code that drops a table, re-create's it (based on a long set of joins) and then re-creates the indexes. It runs via psql in about 10 seconds. I took the code and simply wrapped it into a plpgsql function and the function version takes almost 60 seconds to run. I always thought that functions should run faster than psql... am I wrong? Thanks in advance -- --------------------------------------------- Kevin Kempter - Constent State A PostgreSQL Professional Services Company www.consistentstate.com ---------------------------------------------