Received: from localhost (unknown [200.46.204.183]) by developer.postgresql.org (Postfix) with ESMTP id 7F33E2E00B5 for ; Thu, 8 May 2008 12:21:37 -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 71210-07-3 for ; Thu, 8 May 2008 12:21:30 -0300 (ADT) X-Greylist: delayed 00:20:00.846706 by SQLgrey-1.7.6 Received: from edge.omniti.com (smtp.omniti.com [8.8.38.6]) by developer.postgresql.org (Postfix) with ESMTP id CDC3F2E00B6 for ; Thu, 8 May 2008 12:21:30 -0300 (ADT) DKIM-Signature: v=1; a=rsa-sha256; d=omniti.com; s=s1024; c=simple/simple; q=dns/txt; i=@omniti.com; t=1210258888; h=From:Subject:Date:To; bh=7LGwx3y9sHz27BfWHTVDLajFNkv0499xCbTMXnSQ1Dc=; b=PXvCAosGD6yWWNv+Zg5Ztmq/FdHh8+lDue0EeY8Kggl+V2mXRXqxLnL/a+XnVdoC OUXbhfOHxbFRvdLT0dENsLtc23nJKyi3zFHdPbLA1iiJM2qPheVOUfOaO1onQ2Cs tJVOmOd541nLx2IQJTqDlOpdkYyrj0ATQParD3lhMW4=; Authentication-Results: edge smtp.user=robert@omniti.com; auth=pass (LOGIN) Received: from [72.81.136.83] ([72.81.136.83:35522] helo=ridley.home) by edge (envelope-from ) (ecelerity 2.2.2.30 r(24091M)) with ESMTPSA (cipher=AES256-SHA) id C9/49-16490-8C513284; Thu, 08 May 2008 11:01:28 -0400 From: Robert Treat To: pgsql-admin@postgresql.org Subject: Re: [Fwd: performance: view or function?] Date: Thu, 8 May 2008 11:00:56 -0400 User-Agent: KMail/1.9.9 Cc: Julius Tuskenis References: <4822D2E6.2090004@nsoft.lt> In-Reply-To: <4822D2E6.2090004@nsoft.lt> Organization: OmniTI MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200805081100.56595.robert@omniti.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200805/64 X-Sequence-Number: 29148 On Thursday 08 May 2008 06:16:06 Julius Tuskenis wrote: > Hello, > > I have one question - what is the difference between the view and a > function returning a data set? I mean the performance. Which is better > to use? If its the same, I would use functions, because I could use > other languages not just SQL to get the results I want. > If the sql you need to run is simple enough to work as a view, then most of the time a view will be faster. Generally the cases where functions are faster involve some type of complex operation, which you can use code in the function to cut down on processing. This get's less effective if you use an external procedural language, since the overhead of things like plperl or plphp is much more than that of plpgsql. Again, if you have some really complex operation that these languages make simple, it's often worth the tradeoffs. Note that for average use, all of this is pretty minimal anyway, so I'd probably recommend just doing it in whichever way you find most comfortable, and worry about optimizing things later if you find it's too slow. -- Robert Treat http://www.omniti.com Internet Scalability Consulting