views:

529

answers:

3

Besides the syntactic sugar and expressiveness power what are the differences in runtime efficiency. I mean, plpgsql can be faster than, lets say plpythonu or pljava? Or are they all approximately equals?

We are using stored procedures for the task of detecting nearly-duplicates records of people in a moderately sized database (around 10M of records)

+5  A: 

plpgsql provides greater type safety I believe, you have to perform explicit casts if you want to perform operations using two different columns of similar type, like varchar and text or int4 and int8. This is important because if you need to have your stored proc use indexes, postgres requires that the types match exactly between join conditions (edit: for equality checks too I think).

There may be a facility for this in the other languages though, I haven't used them. In any case, I hope this gives you a better starting point for your investigation.

Dana the Sane
+2  A: 

Without doing actual testing, I would expect plpgsql to be somewhat more efficient than other languages, because it's small. Having said that, remember that SQL functions are likely to be even faster than plpgsql, if a function is simple enough that you can write it in just SQL.

decibel
In my testing using plperl or something other than plpgsql works well when it's not SQL related logic. For instance looping or doing computations plperl has always smoked plpgsql in my limited testing.
StarShip3000
+3  A: 

plpgsql is very well integrated with SQL - the source code should be very clean and readable. For SQL languages like PLJava or PLPython, SQL statements have to be isolated - SQL isn't part of language. So you have to write little bit more code. If your procedure has lot of SQL statements, then plpgsql procedure should be cleaner, shorter and little bit faster. When your procedure hasn't SQL statements, then procedures from external languages can be faster - but external languages (interprets) needs some time for initialisation - so for simple task, procedures in SQL or plpgsql language should be faster.

External languages are used when you need some functionality like access to net, access to filesystem - http://www.postgres.cz/index.php/PL/Perlu%5F-%5FUntrusted%5FPerl%5F%28en%29

What I know - people usually use a combination of PL languages - (SQL,plpgsql, plperl) or (SQL, plpgsql, plpython).

Pavel Stehule