Hi,

I'm trying to add a UDF to mysql server 5.1.37-1ubuntu5 (ubuntu 9.10 x86_64), levenshtein distance function to be exact. I've built the so using the following

gcc -shared -I/usr/include/mysql/ -fPIC -o /usr/lib/mysql/plugin/distance.so distance.c

I then attempt to add the UDF with mysql client via the following:

CREATE FUNCTION distance RETURNS INT soname "distance.so";

which produces the following error:

ERROR 1126 (HY000): Can't open shared library 'distance.so' (errno: 22 /usr/lib/mysql/plugin/distance.so: failed to map segment from shared object: Permission denied)


I've not been able to find any useful information via google on this, which makes me think I'm doing something stupid. Could anyone give me some useful pointers?

The code for distance.c is

/*

################################################## ###########################
# Header from the template:
#
# MySQL :: The world's most popular open source database
################################################## ###########################
*/

#ifdef HAVE_DLOPEN

my_bool distance_init(UDF_INIT *initid, UDF_ARGS *args, char *message);
longlong distance(UDF_INIT *initid, UDF_ARGS *args, char *is_null,
char *error);
longlong distance(UDF_INIT *initid __attribute__((unused)), UDF_ARGS *args,
char *is_null __attribute__((unused)),
char *error __attribute__((unused)))

{
if (args->arg_count != 2)
return -3;

if (args->arg_type[0] != STRING_RESULT)
return -1;

if (args->arg_type[1] != STRING_RESULT)
return -2;

const char *wA = args->args[0];
const char *wB = args->args[1];
int m = args->lengths[0];
int n = args->lengths[1];
int cost =0;
int i;
int j;
longlong D[(m+1)][(n+1)];

for (i = 0; i <= m; i++){
D[i][0] = i;
}

for (i = 1; i <= n; i++){
D[0][i] = i;
}



for (i = 1; i <= m; i++){
for (j = 1; j <= n; j++){
if (wA[i-1] == wB[j-1])
cost = 0;
else
cost = 1;

if ((D[i-1][j] + 1 <= D[i][j-1] + 1) && (D[i-1][j] + 1 <= D[i-1][j-1] + cost)){ // min(D[i-1][j]+1)
D[i][j] = D[i-1][j] + 1;
}
else{
if ((D[i][j-1] + 1 <= D[i-1][j] + 1) && (D[i][j-1] + 1 <= D[i-1][j-1] + cost)) { // min(D[i][j-1]+1
D[i][j] = D[i][j-1] + 1;
}
else{
D[i][j] = D[i-1][j-1] + cost; // min(D[i-1][j-1]+1
}
}
}
}

return D[m][n];
}

my_bool distance_init(UDF_INIT *initid __attribute__((unused)),
UDF_ARGS *args __attribute__((unused)),
char *message __attribute__((unused)))

{
return 0;
}
#endif