MySQL Tips
Compiling Maatkit fnv_udf.cc and murmur_udf.cc
The instructions for compiling the Maatkit user defined functions (UDF) are missing a key detail that prevents them from being added to and used by MySQL. This applies to Maatkit 6224, the current release when this was written.
Problem
There are two user defined functions (UDF) that can be added to MySQL to improve performance of certain operations, such as mk-table-checksum. The two UDFs are:
- fnv_64
- murmur_hash
The UDF files are, respectively:
- fnv_udf.cc
- murmur_udf.cc
The instructions for compiling each UDF is included at the top of each file, and work in so far as they create a shared object file (.so) without generating any errors or warnings. The CREATE FUNCTION statement to add the UDF to MySQL generates the following error:
ERROR 1126 (HY000): Can't open shared library 'fnv_udf.so' (errno: 22 /usr/mysql/lib/mysql/plugin/fnv_udf.so: undefined symbol)
This problem was repeatable on a fresh CentOS 5.4 Linux installation using Percona-XtraDB-5.1.45-1.0.6-10.2 as well as on OpenSolaris with multiple releases of MySQL.
Solution
It seems the stdc++ library is not automatically linked into the final shared object with the provided instructions.
The following instructions compiled both fnv_udf.cc and murmur_udf.cc for use on 64-bit systems, allowing them to be used by MySQL. These instructions are for MySQL 5.1.x, with a basedir of /usr/mysql, that maatkit-6224 has been untarred into ~/build and has been built and installed.
cd ~/build/maatkit-6224/udf/
gcc -fPIC -lstdc++ -m64 -Wall -I/usr/mysql/include/mysql -shared -o fnv_udf.so fnv_udf.cc
gcc -fPIC -lstdc++ -m64 -Wall -I/usr/mysql/include/mysql -shared -o murmur_udf.so murmur_udf.cc
sudo cp fnv_udf.so murmur_udf.so /usr/mysql/lib/mysql/plugin/
mysql -u root -p "CREATE FUNCTION fnv_64 RETURNS INTEGER SONAME 'fnv_udf.so'"
mysql -u root -p "CREATE FUNCTION murmur_hash RETURNS INTEGER SONAME 'murmur_udf.so'"
Remember to adjust the include (-I/usr/mysql/include/mysql) and MySQL 5.1 plugin (/usr/mysql/lib/mysql/plugin) paths accordingly.
