I’m making a dictionary webapp. The user will search for words. Would it be faster to do this?
SELECT * from definition WHERE word LIKE "house";
or…
SELECT * from definition WHERE word_hash LIKE md5("house");
In the second example, I store the md5() value of words in the word_hash field. Of course, “word” and “word_hash” are indexes.
Update: sometimes, the word field could be more than 1 word. Example: Sacré Bleu
Skipping LIKE completely would be faster. Added the lower case version of
wordasword_lc, indexword_lc, and then do:Using LIKE without any
%or_wildcards is just a case insensitive equality test so you should go straight to a case insensitive comparison that can and will take advantage of an index. Also, as usual, say what you mean so the computer can do what you want it to do.