Re: plperl vs plpgsql

From: Christopher Browne <cbbrowne(at)acm(dot)org>
To: pgsql-performance(at)postgresql(dot)org
Subject: Re: plperl vs plpgsql
Date: 2005-04-17 23:17:18
Message-ID: m3sm1pyow1.fsf@knuth.cbbrowne.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

After a long battle with technology, alex(at)meerkatsoft(dot)com (Alex), an earthling, wrote:
> Christopher Browne wrote:
>>After takin a swig o' Arrakan spice grog, alex(at)meerkatsoft(dot)com (Alex) belched out:
>>>i am thinking about swiching to plperl as it seems to me much more
>>>flexible and easier to create functions.
>>>
>>>what is the recommended PL for postgres? or which one is most widely
>>>used / most popular?
>>>is there a performance difference between plpgsql and plperl ?
>>>
>>>
>>
>>If what you're trying to do is "munge text," pl/perl will be a whole
>>lot more suitable than pl/pgsql because it has a rich set of text
>>mungeing tools and string functions which pl/pgsql lacks.
>>
>>If you intend to do a lot of work involving reading unmunged tuples
>>from this table and that, pl/pgsql provides a much more natural
>>syntax, and will probably be a bit faster as the query processor may
>>even be able to expand some of the actions, rather than needing to
>>treat Perl code as an "opaque blob."
>>
>>I would definitely be inclined to use the more natural language for
>>the given task...

> Is there a performance difference between the two?
> which of the PL is most widely used. One problem i have with the
> plpgsql is that the quoting is really a pain.

You seem to be inclined to play the mistaken game of "Which language
is the fastest?" which encourages myopic use of bad benchmarks.

In 8.0, quoting in pl/pgsql is less of a pain, as you can use $$ as
the begin/end indicators.

Performance will always depend on what you're doing.

- If you doing heavy amounts of "text munging," Perl has highly
optimized library routines that you're likely to be taking
advantage of which will likely be way faster than any pl/pgsql
equivalent.

- If you are writing "set operations," operating on table data,
the fact that pl/pgsql won't need to 'context switch' between
language mode and 'accessing data from the database' mode will
probably make it a bit quicker than pl/Perl.

- If you need some sort of "ultimate fastness," then you might look to
writing in a language that compiles to assembler so that your loops
will run as quick and tight as possible, which would encourage
writing stored procedures in C. Alas, this is _way_ harder to debug
and deploy, and errors could pretty readily destroy your database
instance if they were sufficiently awful.

pl/pgsql is almost certainly the most widely used procedural language,
if you're into "popularity contests."

I would be very much inclined to start with whichever language makes
it the easiest to write and maintain the algorithms you plan to write.
I would only move to another language if the initial choice proved to
_systematically_ be a conspicuous bottleneck.
--
output = ("cbbrowne" "@" "gmail.com")
http://linuxdatabases.info/info/linuxdistributions.html
"One of the most dangerous things in the universe is an ignorant
people with real grievances. That is nowhere near as dangerous,
however, as an informed and intelligent society with grievances. The
damage that vengeful intelligence can wreak, you cannot even imagine."
-- Miles Teg, Heretics of Dune

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Nurlan Mukhanov (AL/EKZ) 2005-04-18 04:50:55 Postgresql works too slow
Previous Message Rdiger Herrmann 2005-04-17 20:05:29 refcurosr vs. setof