mysql> show index from play_movie;
+------------+------------+---------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment |
+------------+------------+---------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| play_movie | 0 | PRIMARY | 1 | id | A | 42782 | NULL | NULL | | BTREE | |
| play_movie | 0 | name | 1 | name | A | 42782 | NULL | NULL | | BTREE | |
| play_movie | 1 | play_movie_ec9d726c | 1 | describe | A | 1944 | 333 | NULL | | BTREE | |
| play_movie | 1 | name_2 | 1 | name | NULL | 42782 | NULL | NULL | | FULLTEXT | |
+------------+------------+---------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
mysql> select name from play_movie where match(name) against ('约会规则');
+------------------------+
| name |
+------------------------+
| 约会规则 第二季 |
| 约会规则 第一季 |
+------------------------+
2 rows in set (0.00 sec)
mysql> select name from play_movie where name like '%约会规则%';
+------------------------------------+
| name |
+------------------------------------+
| 恋爱法则/约会规则第四季 |
| 约会规则 第一季 |
| 约会规则 第二季 |
| 约会规则第三季 |
| 约会规则第六季 |
+------------------------------------+
5 rows in set (0.04 sec)
mysql> explain select name from play_movie where match(name) against ('约会规则');
+----+-------------+------------+----------+---------------+--------+---------+------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+------------+----------+---------------+--------+---------+------+------+-------------+
| 1 | SIMPLE | play_movie | fulltext | name_2 | name_2 | 0 | | 1 | Using where |
+----+-------------+------------+----------+---------------+--------+---------+------+------+-------------+
mysql> explain select name from play_movie where name like '%约会规则%';
+----+-------------+------------+-------+---------------+------+---------+------+-------+--------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+------------+-------+---------------+------+---------+------+-------+--------------------------+
| 1 | SIMPLE | play_movie | index | NULL | name | 767 | NULL | 42782 | Using where; Using index |
+----+-------------+------------+-------+---------------+------+---------+------+-------+--------------------------+
答案 0 :(得分:1)
在match against
查询中,您正在查找包含完全字约会规则的行。但是,在like
查询中,您正在查找包含约会规则 一词的行,包括其他单词。您可以在boolean mode中使用全文搜索,这样您就可以使用星号作为通配符:
SELECT name FROM play_movie WHERE MATCH(name)
AGAINST ('约会规则*' IN BOOLEAN MODE);