Re: [Fwd: performance: view or function?] - Mailing list pgsql-admin

From Robert Treat
Subject Re: [Fwd: performance: view or function?]
Date
Msg-id 200805081100.56595.robert@omniti.com
Whole thread Raw
In response to [Fwd: performance: view or function?]  (Julius Tuskenis <julius@nsoft.lt>)
List pgsql-admin
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

pgsql-admin by date:

Previous
From: "Eric Comeau"
Date:
Subject: Re: Converting from 7.4.19 To 8.3.1 & want to use autovacuum
Next
From: "Scott Marlowe"
Date:
Subject: Re: [Fwd: performance: view or function?]