MySQL has User Defined Functions. These are loadable modules, written in C, that can be loaded into a running MySQL server, and used like a "native" built-in function.
A UDF can be an aggregate function. An aggregate function is one that takes in multiple rows, but emits only one result. For example, SUM() is a built-in aggregate function.
I just proved to myself via testing and benchmarking that user defined aggregate functions are about three times slower than the call interface to the built-in functions.
THREE TIMES SLOWER!
In about twelve hours I am supposed to be presenting a talk titled Using User-defined Functions and Aggregates to Speed Up Your Data Warehouse Processing
It turns out to be a MacOS thing. On Linux, the performance penalty is less than 10%. Further research will surely be done.
The talk itself went reasonably well.