Performance: sql functions v. plpgsql v. plperl - Mailing list pgsql-general

From Joel Burton
Subject Performance: sql functions v. plpgsql v. plperl
Date
Msg-id Pine.LNX.4.21.0104240944170.11638-100000@olympus.scw.org
Whole thread Raw
Responses Re: Performance: sql functions v. plpgsql v. plperl
List pgsql-general
Last night, I was doing some amateurish benchmarking and found that,
contrary to my (admittedly uninformed) expectation, sql functions seem
*slower* than plsql functions. Even for very simple things, like

'SELECT CASE WHEN $1 RETURN $1 ELSE $2 END'

were slower than the plsql

begin
  if $1 then
    return $1;
  else
    return $2;
  end if;
end;

by about 15%.

However, my benchmarking was the type usually dreaded: a single person,
playing around in a scripting language, running the test one a time
seqeuentially, and just timing the results.

Is there any real data on this?



I also tried plperl v plpgsql, and found that, probably not surprisingly,
there was about a 15% advantage to plpgsql. Of course, many things can be
written much simpler in perl (such as string handling functions). Even so,
though, a find-the-first-letter-of-all-significant-words function written
about 1.5 years ago in plpgsql (a pretty awful, nested, letter-by-letter
parser) was only about twice as slow as the perl
split() replacement. Looks like our little plpgsql is quite a speed demon.

(as always, IANAPB [ I am not a professional benchmarker ], YMMV)


--
Joel Burton   <jburton@scw.org>
Director of Information Systems, Support Center of Washington


pgsql-general by date:

Previous
From: Joel Burton
Date:
Subject: Re: Re: BETWEEN clause
Next
From: Peter Keller
Date:
Subject: indices are crashed after installation of rpm