Currently I'm using the following query: (I'm using the following implmenetation of levenshtein()
SELECT title FROM db_full WHERE MATCH (`Title`) AGAINST ('Harry Potter and the Deathly Hallows' IN BOOLEAN MODE) AND levenshtein('Harry Potter and the Deathly Hallows', `Title`) BETWEEN 0 AND 15
I was wondering if it was faster to use the combination of MySQL + PHP something like below
$testQ = "SELECT title FROM db_full WHERE MATCH (`Title`) AGAINST ('Harry Potter and the Deathly Hallows' IN BOOLEAN MODE)";
}
result = $conn->query($testQ);
while ($row = $result->fetch_assoc()) {
$distance = levenshtein($v,$row['title']);
// using the if condinational for the distance
}
Which procedure would be faster and more efficient?
In general, the correct answer to "Which is faster" is "Try it on your system and your data". In this case, that is the best answer. I do not know off-hand which system (MySQL or PHP) has a faster implementation of Levenshtein. Probably nobody does, because this depends on system configurations.
There are reasons to think that doing the work in the database would be faster:
From a maintainability (aesthetic ?) perspective, I prefer to have all logic co-located, so that is another argument for doing the work in the database. However, that has little to do with performance.
However, it is possible that the volume of data being passed back is pretty small and that PHP has a better implementation of Levenshtein than does MySQL. You should test the two approaches if marginal performance improvement is important for your application.