3

I would like to use the hamming distance in my MySQL database (used over phpMyAdmin) but did not succeed in creating the function with the code given here.

I'm refering to this code:

CREATE FUNCTION HAMMINGDISTANCE(
A0 BIGINT, A1 BIGINT, A2 BIGINT, A3 BIGINT,
B0 BIGINT, B1 BIGINT, B2 BIGINT, B3 BIGINT
)
RETURNS INT DETERMINISTIC
RETURN
  BIT_COUNT(A0 ^ B0) +
  BIT_COUNT(A1 ^ B1) +
  BIT_COUNT(A2 ^ B2) +
  BIT_COUNT(A3 ^ B3);

The problem is that I don't have the "super privilege". I also tried putting this code between DELIMITER // (which worked for the Levenshtein distance function, see below), but also that did not solve the problem - I get a time out:

Maximum execution time of 300 seconds exceeded in /usr/share/phpmyadmin/libraries/import/sql.php on line 132

I'm quite new to MySQL anyway, so I'm wondering if anybody can help me with creating the hamming function in MySQL some other way.

Btw, I'm also using the Levenshtein distance function and the creation of this function worked fine. Yet, I saw that the Levenshtein distance should rather be used for calculating the distance between two strings and the hamming distance for numerical data.

Thanks.

Community
  • 1
  • 1
olenska
  • 31
  • 2
  • The link to code you provided points to a SO entry with multiple items of code. Please put the code for the function you're trying to define in this question. That way others of us can try it and maybe figure out how to help. – O. Jones Dec 17 '12 at 13:30

1 Answers1

0

You need the CREATE ROUTINE permission.

Undo
  • 25,519
  • 37
  • 106
  • 129
Rick James
  • 135,179
  • 13
  • 127
  • 222