pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
[Fwd: performance: view or function?]
4+ messages / 4 participants
[nested] [flat]

* [Fwd: performance: view or function?]
@ 2008-05-08 10:16  Julius Tuskenis <julius@nsoft.lt>
  0 siblings, 3 replies; 4+ messages in thread

From: Julius Tuskenis @ 2008-05-08 10:16 UTC (permalink / raw)
  To: pgsql-admin

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.

Thank you in advance.

-- 
Julius Tuskenis
Programavimo skyriaus vadovas
UAB nSoft
mob. +37068233050




-- 
Julius Tuskenis
Programavimo skyriaus vadovas
UAB nSoft
mob. +37068233050




^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: [Fwd: performance: view or function?]
@ 2008-05-08 15:00  Robert Treat <robert@omniti.com>
  parent: Julius Tuskenis <julius@nsoft.lt>
  2 siblings, 0 replies; 4+ messages in thread

From: Robert Treat @ 2008-05-08 15:00 UTC (permalink / raw)
  To: pgsql-admin; +Cc: Julius Tuskenis <julius@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



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: [Fwd: performance: view or function?]
@ 2008-05-08 16:42  Scott Marlowe <scott.marlowe@gmail.com>
  parent: Julius Tuskenis <julius@nsoft.lt>
  2 siblings, 0 replies; 4+ messages in thread

From: Scott Marlowe @ 2008-05-08 16:42 UTC (permalink / raw)
  To: Julius Tuskenis <julius@nsoft.lt>; +Cc: pgsql-admin

On Thu, May 8, 2008 at 4:16 AM, Julius Tuskenis <julius@nsoft.lt> 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.

Note that functional indexes may be a good choice for certain actions.
 If you always look up tuples based on something like "where
a*80+b<100 or something then a functional index on ((a*80+b)) might be
more useful than a view.  You can also create a custom immutable
function and index on that to make it a bit cleaner.



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: [Fwd: performance: view or function?]
@ 2008-05-09 06:23  Giorgio Valoti <giorgio_v@mac.com>
  parent: Julius Tuskenis <julius@nsoft.lt>
  2 siblings, 0 replies; 4+ messages in thread

From: Giorgio Valoti @ 2008-05-09 06:23 UTC (permalink / raw)
  To: pgsql-admin


On 08/mag/08, at 12:16, 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.
>

Take a look at this thread: <http://archives.postgresql.org/pgsql- 
performance/2008-03/msg00428.php>


Hope this helps
--
Giorgio Valoti









^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2008-05-09 06:23 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2008-05-08 10:16 [Fwd: performance: view or function?] Julius Tuskenis <julius@nsoft.lt>
2008-05-08 15:00 ` Robert Treat <robert@omniti.com>
2008-05-08 16:42 ` Scott Marlowe <scott.marlowe@gmail.com>
2008-05-09 06:23 ` Giorgio Valoti <giorgio_v@mac.com>

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