User-defined functions are compiled as shared object files and then added to and removed from the MySQL server dynamically. I hacked up a small test to demonstrate their implementation, although I’ll only show you the results here.
So far, nothing special, but now for something completely different:
The CREATE FUNCTION loads the shared object file into the server’s address space, where it remains available until the function is dropped from the data dictionary.
During the SELECT, MySQL invokes my UDF, passing it the string argument, and I go off and search for the user in an LDAP directory tree, returning the user’s Common Name as the function’s value. That in turn is the result of the function which MySQL uses. Powerful. More on MySQL UDF.