CS122B: Projects in Databases and Web Applications Winter 2019 Professor Chen Li Department of Computer Science UC Irvine Notes 12: User-Defined Functions (UDF) in MySQL
Purpose SQL has its own limitations Enhance DB using functions implemented in C
Example: edit distance Edit distance between two strings is the minimum number of single-character operations (insert/delete/substitute) to transform one to the other Also known as Levenshtein distance Example: ed(”schwazeneger”, ”schwarzenegger”) = 2
Dynamic programming for edit distance
Example ed(”elephant”, ”relevant”) = 3
Supporting Edit Distance as UDF Compile Edit distance Function in C: ed.c Shared library libed.so CREATE FUNCTION ed RETURNS INTEGER SONAME 'libed.so'; SELECT ed('abc', 'ad'); MySQL
Example: using ed as a UDF select * from stars where name = ’Arnold schwarzenegger' limit 5 select * from stars where ed(name, 'Arnold Schwarzeneger') <= 2 limit 5