Assignment performance in PL/pgSQL

In my post about choosing the language for stored functions I showed what impact the different languages have.

When choosing PL/pgSQL as the language, there is one performance optimization that is often overlooked: assignment of values to variables. Different approaches have a different performance.


Every now and then I see queries that use GROUP BY without any aggregates which is the same as using DISTINCT instead.

Performance of stored functions

Something that users coming from other database systems easily overlook is, that Postgres supports different languages for writing stored functions (and procedures). Choosing the right language can influence the performance of your functions.