Skip site navigation (1) Skip section navigation (2)

Re: On the performance of views

From: Shridhar Daithankar <shridhar(at)frodo(dot)hserus(dot)net>
To: pgsql-performance(at)postgresql(dot)org
Subject: Re: On the performance of views
Date: 2004-01-26 15:29:46
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-performancepgsql-sql
Bill Moran wrote:

> I have an application that I'm porting from MSSQL to PostgreSQL.  Part 
> of this
> application consists of hundreds of stored procedures that I need to 
> convert
> to Postgres functions ... or views?
> At first I was going to just convert all MSSQL procedures to Postgres 
> functions.
> But now that I'm looking at it, a lot of them may be candidates for 
> views.  A
> lot of them take on the format of:
> SELECT a.cola, b.colb, c.colc
> WHERE a.prikey=$1

Make sure that you typecase correctly. It makes a differnce of order of 
magnitude when you say 'where intpkey=<somevalue>::int' rather than 'where 

It is called typecasting and highly recommened in postgresql for correctly 
choosing indexes.

I remember another post on some list, which said pl/pgsql seems to be very 
strongly typed language compared to MSSQL counterpart. So watch for that as well.

> (this is slightly oversimplified, but as a generalization of hundreds of
> functions, it's pretty accurate)
> Now, I know this questions is pretty generalized, and I intend to test 
> before
> actually commiting to a particular course of action, but I'm very early 
> in the
> conversion and I'm curious as to whether people with more experience than I
> think that views will provide better performance than functions containing
> SQL statements like the above.  The client is _very_ interested in 

To my understanding, views are expanded at runtime and considered while 
preparing plan for the complete (and possibly bigger) query(Consider a view 
joined with something else). That is not as easy/possible if at all, when it is 
function. For postgresql query planner, the function is a black box(rightly so, 
I would say).

So using views opens possibility of changing query plans if required. Most of 
the times that should be faster than using them as functions.

Of course, the standard disclaimer, YMMV. Try yourself.

Correct me if I am wrong.



In response to


pgsql-performance by date

Next:From: Greg StarkDate: 2004-01-26 16:16:28
Subject: Re: High Performance/High Reliability File system on SuSE64
Previous:From: Bill MoranDate: 2004-01-26 15:19:14
Subject: On the performance of views

pgsql-sql by date

Next:From: Tom LaneDate: 2004-01-26 16:43:37
Subject: Re: On the performance of views
Previous:From: Bill MoranDate: 2004-01-26 15:19:14
Subject: On the performance of views

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group