Bug #39190 Feature request (not a bug)
Submitted: 2 Sep 2008 14:44 Modified: 4 Oct 2008 13:03
Reporter: Eugen Schülter Email Updates:
Status: No Feedback Impact on me:
None 
Category:MySQL Server: Stored Routines Severity:S4 (Feature request)
Version: OS:Any
Assigned to: CPU Architecture:Any
Tags: Built in function

[2 Sep 2008 14:44] Eugen Schülter
Description:
Will there be a plug-in-interface for providing stored functions (or 'built in' functions in native (C) language? I know it's possible to compile the server but this solution is not possible for us.

If not:
It would be very nice to include a Damerau Levenshtein distance function (http://en.wikipedia.org/wiki/Damerau-Levenshtein_distance). The algorithm is published and I imagine that we are not the only ones that could make good use of this function. In our case we have the problem to deal with names from people from different countries (Europe, Africa). The Damerau Levenshtein distance is very useful to catch spelling errors and the usual soundex algorithms are useless in this case.

Here is a C implementation with a inconsequential memory limitation:

UINT32 OS_API DamerauLevenDist(char* s1, char* s2)
{
   int n, m, i, j, cost;
   UCHAR *d;
   n = strlen(s1);
   m = strlen(s2);
   if (n==0 || m==0 || n*m > 2500) return(999);
   ++n, ++m;
   if ((d = malloc(n*m)) == 0) return(999);
   for(i=0; i<n; d[i]  =i, ++i);
   for(i=0; i<m; d[i*n]=i, ++i);
   for (i=1; i<n; ++i)
   {
      for (j=1; j<m; ++j)
      {
         cost = (s1[i-1] != s2[j-1]); //0 if eq, -1 if ne
         
         d[i+j*n] = d[i-1+j*n] + 1;    // insertion
         
         if(d[i+j*n-n]+1 < d[i+j*n])      d[i+j*n] = d[i+j*n-n]+1;      //deletion
         
         if(d[i-1+j*n-n]+cost < d[i+j*n]) d[i+j*n] = d[i-1+j*n-n]+cost; // substitution
         if ( i > 1  &&  j > 1 &&
              s1[i-1] == s2[j-2] &&
              s1[i-2] == s2[j-1] )
         {
            if(d[i-2+(j-2)*n] + cost < d[i+j*n])
               d[i+j*n] = d[i-2+(j-2)*n] + cost;
         }
      }
   }
   i = (int)(d[n*m-1]);
   free(d);
   return(i);
}

How to repeat:
Not a bug
[4 Sep 2008 13:03] Valeriy Kravchuk
What about http://dev.mysql.com/doc/refman/5.0/en/create-function-udf.html? Do you need anything else?
[4 Oct 2008 23:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".