pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Robert Treat <robert@omniti.com>
To: pgsql-admin@postgresql.org
Cc: Julius Tuskenis <julius@nsoft.lt>
Subject: Re: [Fwd: performance: view or function?]
Date: Thu, 8 May 2008 11:00:56 -0400
Message-ID: <200805081100.56595.robert@omniti.com> (raw)
In-Reply-To: <4822D2E6.2090004@nsoft.lt>
References: <4822D2E6.2090004@nsoft.lt>

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



view thread (4+ messages)  latest in thread

Message-ID: <200805081100.56595.robert@omniti.com>
Permalink:  ../200805081100.56595.robert@omniti.com/
Also on:    postgresql.org/message-id/200805081100.56595.robert@omniti.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-admin@postgresql.org
  Cc: robert@omniti.com, julius@nsoft.lt
  Subject: Re: [Fwd: performance: view or function?]
  In-Reply-To: <200805081100.56595.robert@omniti.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox