Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 34FCF9FBDA9 for ; Thu, 8 Mar 2007 13:52:49 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-new, port 10024) with ESMTP id 91747-07-2 for ; Thu, 8 Mar 2007 13:52:38 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4 Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.170]) by postgresql.org (Postfix) with ESMTP id DD1E39FBE12 for ; Thu, 8 Mar 2007 13:52:38 -0400 (AST) Received: by ug-out-1314.google.com with SMTP id k3so971707ugf for ; Thu, 08 Mar 2007 09:52:37 -0800 (PST) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:user-agent:mime-version:to:cc:subject:references:in-reply-to:content-type:content-transfer-encoding:sender; b=FjxG84XFLrHKHUske4hJUsbRLG5/TE4eTY+S49guohJfPs9tKWWJrrCrmWmXF4G/RGlZmb3rW5xzRuV029n15QXa8XdmS7S3RPvbhrt4jkoM0iCAZJZb8r4UZtfn6bEwkGw6p6QJoYCepku275ULiSNGuYBCC1kAWgIqZ69bcGQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:user-agent:mime-version:to:cc:subject:references:in-reply-to:content-type:content-transfer-encoding:sender; b=EzmEtJg9f/bwL25qYK5lwjB1R5XLzu3cUmrkveHX928k9yF27sCPujfq3wMS4yeRXbB0R4fataYiNEamlWpJCmrHHzlEnsfUa7/clcuFHr+RFfKSGkHXBdCmlk+fOeF3uBN/m0bpxpsiemGFQb1mjAaLRBrmjvEWj1x/kZWXiIU= Received: by 10.67.19.17 with SMTP id w17mr7470672ugi.1173376357289; Thu, 08 Mar 2007 09:52:37 -0800 (PST) Received: from ?192.168.1.34? ( [82.3.248.250]) by mx.google.com with ESMTP id z37sm4982712ikz.2007.03.08.09.52.32; Thu, 08 Mar 2007 09:52:33 -0800 (PST) Message-ID: <45F04D62.8090302@enterprisedb.com> Date: Thu, 08 Mar 2007 17:52:34 +0000 From: Heikki Linnakangas User-Agent: Icedove 1.5.0.8 (X11/20061116) MIME-Version: 1.0 To: "Schwarz, Karl" CC: pgsql-performance@postgresql.org Subject: Re: function performance vs in-line sql References: <9E64800D28DF264DB32B0309B6F222D5188548@xcgny105.northgrum.com> In-Reply-To: <9E64800D28DF264DB32B0309B6F222D5188548@xcgny105.northgrum.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200703/169 X-Sequence-Number: 23574 Schwarz, Karl wrote: > I am having a performance problem with a query implemented within a > server side function. If I use an SQL client(EMS Postgres) and manually > generate the sql query I get about 100 times performance improvement > over using the function. > > I've also tried using a prepared statement from my application and > observed a similar performance improvement over the the function. > > The table I am quering against has several hundred thousand records. I > have indexes defined and I've run vacuum several times. > > Is there something basic I am missing here with the use of a function. I > am no database expert, but my assumption was that a function would give > me better results than in-line sql. > > I've seen a mailing list entry in another list that implied that the > query planner for a function behaves differently than in-line sql. For starters, can you show us the function, the manual sql query and the schema, please? -- Heikki Linnakangas EnterpriseDB http://www.enterprisedb.com