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

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search archives
  Advanced Search

Re: plpgsql functions vs. embedded queries


  • From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
  • To: "Wright, George" <George(dot)Wright(at)infimatic(dot)com>
  • Cc: "John DeSoi" <desoi(at)pgedit(dot)com>, pgsql-novice(at)postgresql(dot)org
  • Subject: Re: plpgsql functions vs. embedded queries
  • Date: Mon, 29 Sep 2008 19:07:11 -0400
  • Message-id: <25540.1222729631@sss.pgh.pa.us> <text/plain>

"Wright, George" <George(dot)Wright(at)infimatic(dot)com> writes:
>> Are funtions in plpgsql always slower than embedding sql queries in  
>> string form in code like PHP?
> The functions took on average more than 10 times as long.

That suggests that you're getting a radically different, less efficient
plan for the "same" query inside a function.  The exact reasons why are
hard to diagnose without a concrete example, but usually the story has
to do with comparing parameterized queries inside a function to
not-parameterized queries elsewhere.  There are various workarounds
but the best choice depends on details you've not shown us.

			regards, tom lane



Home | Main Index | Thread Index

Privacy Policy | About PostgreSQL
Copyright © 1996 – 2012 PostgreSQL Global Development Group