Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 37DC91FBF228 for ; Tue, 27 Dec 2011 19:12:17 -0400 (AST) Received: from relay4-d.mail.gandi.net ([217.70.183.196]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1RfgBr-0005gn-Lu for pgsql-performance@postgresql.org; Tue, 27 Dec 2011 23:12:17 +0000 X-Originating-IP: 217.70.178.139 Received: from mfilter10-d.gandi.net (mfilter10-d.gandi.net [217.70.178.139]) by relay4-d.mail.gandi.net (Postfix) with ESMTP id D5F76172089; Wed, 28 Dec 2011 00:11:52 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at mfilter10-d.gandi.net Received: from relay4-d.mail.gandi.net ([217.70.183.196]) by mfilter10-d.gandi.net (mfilter10-d.gandi.net [10.0.15.180]) (amavisd-new, port 10024) with ESMTP id uhmX8C+dzE60; Wed, 28 Dec 2011 00:11:51 +0100 (CET) X-Originating-IP: 98.27.54.176 Received: from [192.168.10.146] (cpe-098-027-054-176.nc.res.rr.com [98.27.54.176]) (Authenticated sender: adsend@dunslane.net) by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id 2C61E172067; Wed, 28 Dec 2011 00:11:48 +0100 (CET) Message-ID: <4EFA50B3.4010800@dunslane.net> Date: Tue, 27 Dec 2011 18:11:47 -0500 From: Andrew Dunstan User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:8.0) Gecko/20111115 Thunderbird/8.0 MIME-Version: 1.0 To: Merlin Moncure CC: Pavel Stehule , Carlo Stonebanks , pgsql-performance@postgresql.org Subject: Re: Performance costs of various PL languages References: <4BFE8F4F0200002500031BA2@gw.wicourts.gov> <295DF03C1B134B0BBD05A8F54D985C76@CAPRICA> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201112/186 X-Sequence-Number: 45985 On 12/27/2011 05:54 PM, Merlin Moncure wrote: > On Tue, Dec 27, 2011 at 4:20 PM, Pavel Stehule wrote: >> Hello >> >> 2011/12/27 Carlo Stonebanks: >>> We are currently using pltclu as our PL of choice AFTER plpgSql. >>> >>> I'd like to know if anyone can comment on the performance costs of the >>> various PL languages BESIDES C. For example, does pltclu instantiate faster >>> than pltcl (presumably because it uses a shared interpreter?) Is Perl more >>> lightweight? >>> >>> I know that everything depends on context - what you are doing with it, e.g. >>> choose Tcl for string handling vs. Perl for number crunching - but for those >>> who know about this, is there a clear performance advantage for any of the >>> various PL languages - and if so, is it a difference so big to be worth >>> switching? >>> >>> I ask this because I had expected to see pl/pgsql as a clear winner in terms >>> of performance over pltclu, but my initial test showed the opposite. I know >>> this may be an apples vs oranges problem and I will test further, but if >>> anyone has any advice or insight, I would appreciate it so I can tailor my >>> tests accordingly. >>> >> A performance strongly depends on use case. >> >> PL/pgSQL has fast start but any expression is evaluated as simple SQL >> expression - and some repeated operation should be very expensive - >> array update, string update. PL/pgSQL is best as SQL glue. Positive to >> performance is type compatibility between plpgsql and Postgres. >> Interpret plpgsql is very simply - there are +/- zero optimizations - >> plpgsql code should be minimalistic, but when you don't do some really >> wrong, then a speed is comparable with PHP. >> >> http://www.pgsql.cz/index.php/PL/pgSQL_%28en%29#Inappropriate_use_of_the_PL.2FpgSQL_language >> >> PL/Perl has slower start - but string or array operations are very >> fast. Perl has own expression evaluator - faster than expression >> evaluation in plpgsql. On second hand - any input must be transformed >> from postgres format to perl format and any result must be transformed >> too. Perl and other languages doesn't use data type compatible with >> Postgres. > One big advantage pl/pgsql has over scripting languages is that it > understands postgresql types natively. It knows what a postgres array > is, and can manipulate one directly. pl/perl would typically have to > have the database convert it to a string, parse it into a perl > structure, do the manipulation, then send it to the database to be > parsed again. If your procedure code is mainly moving data between > tables and doing minimal intermediate heavy processing, this adds up > to a big advantage. Which pl to go with really depends on what you > need to do. pl/pgsql is always my first choice though. > > perl and tcl are not particularly fast languages in the general case > -- you are largely at the mercy of how well the language's syntax or > library features map to the particular problem you're solving. if you > need a fast general purpose language in the backend and are (very > understandably) skeptical about C, I'd look at pl/java. > PLV8, which is not yet ready for prime time, maps many common Postgres types into native JS types without the use of Input/Output functions, which means the conversion is very fast. It's work which could very well do with repeating for the other PL's. cheers andrew