【发布时间】:2014-07-06 04:58:50
【问题描述】:
当我们使用 mysql-client 登录我们的数据库并启动这些查询时:
第一个测试查询:
select a.*
from ads a
inner join searchs_titles s on s.id_ad = a.id
where match(s.label) against ('"bmw serie 3"' in boolean mode)
order by a.ranking asc limit 0, 10;
结果是:
10 rows in set (1 min 5.37 sec)
第二次测试查询:
select a.*
from ads a
inner join searchs_titles s on s.id_ad = a.id
where match(s.label) against ('"ford mondeo"' in boolean mode)
order by a.ranking asc limit 0, 10;
结果是:
10 rows in set (2 min 13.88 sec)
这些查询太慢了。有什么办法可以改善吗?
“广告”表包含 200 万行,触发器设置为将数据复制到搜索标题中。搜索标题包含广告中每一行的 id、标题和标签。 表 'ads' 由 innoDB 提供支持,而 myISAM 为 'searchs_titles' 提供支持,标签字段上有全文索引。
我们的列太多了吗?索引太多?行数太多? 这是一个错误的查询吗?
非常感谢您花时间帮助我们!
编辑:添加解释
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
| 1 | SIMPLE | s | fulltext | id_ad,label | label | 0 | | 1 | Using where; Using temporary; Using filesort |
| 1 | SIMPLE | a | eq_ref | PRIMARY,id,id_2,id_3 | PRIMARY | 4 | XXXXXX.s.id_ad | 1 | |
【问题讨论】:
-
你的意思是我们应该请求 a.the specifics indexed columns 而不是请求 a.*?
-
截图不可读。你有关于 searchs_titles.label 的全文索引吗?
-
你能给出查询的解释计划吗?由于这是一个优化问题,因此此信息很重要。
标签: mysql indexing full-text-search sql-order-by query-optimization