条)记录的表,字段“id”为int类型,主键;字段“title”为varchar类型,字段“body”为text类型。“title”和“body”分别建有INDEX普通单列索引、INDEX联合索引,FULLTEXT单字段全文索引、FULLTEXT联合全文索引。
1、在字段“title”中搜索中文关键字:SELECT * FROM database.table WHERE MATCH(title) AGAINST (''朝阳区'' IN BOOLEAN MODE) limit 0,30;
30 rows in set (0.04 sec)
SELECT * FROM database.table WHERE title LIKE ''%朝阳区%'' limit 0,30;
30 rows in set (6.56 sec)
SELECT * FROM database.table WHERE MATCH(title) AGAINST (''通州区'' IN BOOLEAN MODE) ORDER BY id DESC limit 0,30;
30 rows in set (0.13 sec)
SELECT * FROM database.table WHERE title LIKE ''%通州区%'' ORDER BY id DESC limit 0,30;
30 rows in set (8.15 sec)
SELECT * FROM database.table WHERE MATCH(title) AGAINST (''建国门外'' IN BOOLEAN MODE) ORDER BY id DESC limit 0,30;
30 rows in set (0.08 sec)
SELECT * FROM database.table WHERE title LIKE ''%建国门外%'' ORDER BY id DESC limit 0,30;
30 rows in set (5.34 sec)
SELECT * FROM database.table WHERE MATCH(title) AGAINST (''靠近通惠河'' IN BOOLEAN MODE) ORDER BY id DESC limit 0,30;
4 row in set (0.06 sec)
SELECT * FROM database.table WHERE title LIKE ''%靠近通惠河%'' ORDER BY id DESC limit 0,30;
4 row in set (12.88 sec)
2、在字段“body”中搜索中文关键字:
SELECT * FROM database.table WHERE MATCH(body) AGAINST (''海淀区'' IN BOOLEAN MODE) ORDER BY id DESC limit 0,30;
30 rows in set (0.23 sec)
SELECT * FROM database.table WHERE body LIKE ''%海淀区%'' ORDER BY id DESC limit 0,30;
30 rows in set (15.71 sec)
SELECT * FROM database.table WHERE MATCH(body) AGAINST (''莱镇香格里'' IN BOOLEAN MODE) ORDER BY id DESC limit 0,30;
6 rows in set (0.18 sec)
SELECT * FROM database.table WHERE body LIKE ''%莱镇香格里%'' ORDER BY id DESC limit 0,30;
6 row in set (13.34 sec)
3、在字段“title”和“body”中,搜索同时包含“西城区”和“商场”两个关键字的记录:
SELECT * FROM database.table WHERE MATCH(title,body) AGAINST (''西城区 商场'' IN BOOLEAN MODE) ORDER BY id DESC limit 0,30;
13 rows in set (0.27 sec)
SELECT * FROM database.table WHERE title LIKE ''%西城区%商场%'' AND body LIKE ''%西城区%商场%'' ORDER BY id DESC limit 0,30;
13 rows in set (51.74 sec)