Unix Technical Forum

function performance vs in-line sql

This is a discussion on function performance vs in-line sql within the Pgsql Performance forums, part of the PostgreSQL category; --> I am having a performance problem with a query implemented within a server side function. If I use an ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql Performance

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-19-2008, 10:21 AM
Schwarz, Karl
 
Posts: n/a
Default function performance vs in-line sql

I am having a performance problem with a query implemented within a
server side function. If I use an SQL client(EMS Postgres) and manually
generate the sql query I get about 100 times performance improvement
over using the function.

I've also tried using a prepared statement from my application and
observed a similar performance improvement over the the function.

The table I am quering against has several hundred thousand records. I
have indexes defined and I've run vacuum several times.

Is there something basic I am missing here with the use of a function. I
am no database expert, but my assumption was that a function would give
me better results than in-line sql.

I've seen a mailing list entry in another list that implied that the
query planner for a function behaves differently than in-line sql.


Thanks
Karl

---------------------------(end of broadcast)---------------------------
TIP 7: You can help support the PostgreSQL project by donating at

http://www.postgresql.org/about/donate

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-19-2008, 10:21 AM
Richard Huxton
 
Posts: n/a
Default Re: function performance vs in-line sql

Schwarz, Karl wrote:
> Is there something basic I am missing here with the use of a function. I
> am no database expert, but my assumption was that a function would give
> me better results than in-line sql.


Not necessarily. Usually it means the planner has less information to go on.

We'll need more information though - table definitions, queries, how is
the function called etc.

--
Richard Huxton
Archonet Ltd

---------------------------(end of broadcast)---------------------------
TIP 7: You can help support the PostgreSQL project by donating at

http://www.postgresql.org/about/donate

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-19-2008, 10:21 AM
Heikki Linnakangas
 
Posts: n/a
Default Re: function performance vs in-line sql

Schwarz, Karl wrote:
> I am having a performance problem with a query implemented within a
> server side function. If I use an SQL client(EMS Postgres) and manually
> generate the sql query I get about 100 times performance improvement
> over using the function.
>
> I've also tried using a prepared statement from my application and
> observed a similar performance improvement over the the function.
>
> The table I am quering against has several hundred thousand records. I
> have indexes defined and I've run vacuum several times.
>
> Is there something basic I am missing here with the use of a function. I
> am no database expert, but my assumption was that a function would give
> me better results than in-line sql.
>
> I've seen a mailing list entry in another list that implied that the
> query planner for a function behaves differently than in-line sql.


For starters, can you show us the function, the manual sql query and the
schema, please?

--
Heikki Linnakangas
EnterpriseDB http://www.enterprisedb.com

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-19-2008, 10:21 AM
Schwarz, Karl
 
Posts: n/a
Default Re: function performance vs in-line sql

Thanks. I was not looking for help with the query just wanted to know
that I didn't overlook some basic
configuration setting.

Karl

-----Original Message-----
From: Richard Huxton [mailto:dev@archonet.com]
Sent: Thursday, March 08, 2007 12:50 PM
To: Schwarz, Karl
Cc: pgsql-performance@postgresql.org
Subject: Re: [PERFORM] function performance vs in-line sql

Schwarz, Karl wrote:
> Is there something basic I am missing here with the use of a function.


> I am no database expert, but my assumption was that a function would
> give me better results than in-line sql.


Not necessarily. Usually it means the planner has less information to go
on.

We'll need more information though - table definitions, queries, how is
the function called etc.

--
Richard Huxton
Archonet Ltd

---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 05:09 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com