Topic: Very slow search (query)
mysql> explain SELECT m.post_id FROM search_words AS w INNER JOIN search_matches AS m ON m.word_id=w.id WHERE w.word LIKE '%text%';
+----+-------------+-------+------+----------------------------+---------------------+---------+-----------------+---------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------+----------------------------+---------------------+---------+-----------------+---------+-------------+
| 1 | SIMPLE | m | ALL | search_matches_word_id_idx | NULL | NULL | NULL | 3268634 | |
| 1 | SIMPLE | w | ref | search_words_id_idx | search_words_id_idx | 3 | forum.m.word_id | 1 | Using where |
+----+-------------+-------+------+----------------------------+---------------------+---------+-----------------+---------+-------------+
This query takes about 30-40 seconds to run.
What could be wrong here?
other example, witch works fine:
mysql> explain SELECT m.post_id FROM search_words AS w INNER JOIN search_matches AS m ON m.word_id=w.id WHERE w.word LIKE 'text';
+----+-------------+-------+-------+-----------------------------+----------------------------+---------+------------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+-------+-----------------------------+----------------------------+---------+------------+------+-------------+
| 1 | SIMPLE | w | range | PRIMARY,search_words_id_idx | PRIMARY | 22 | NULL | 1 | Using where |
| 1 | SIMPLE | m | ref | search_matches_word_id_idx | search_matches_word_id_idx | 3 | forum.w.id | 17 | |
+----+-------------+-------+-------+-----------------------------+----------------------------+---------+------------+------+-------------+
2 rows in set (0.00 sec)
Notice the difference between the two "... LIKE '%text%'" and "... LIKE 'text'"