【发布时间】:2015-07-02 10:38:26
【问题描述】:
我有以下 MySQL 查询:
SELECT p.*, MATCH (p.description) AGAINST ('random text that you can use in sample web pages or typography samples') AS score
FROM posts p
WHERE p.post_id <> 23
AND MATCH (p.description) AGAINST ('random text that you can use in sample web pages or typography samples') > 0
ORDER BY score DESC LIMIT 1
108,000 行,需要 ~200ms。有 265,000 行,需要 ~500ms。
在性能测试中(~80 个并发用户)它显示 ~18sec 平均延迟。
有什么方法可以提高这个查询的性能吗?
解释输出:
更新
我们添加了一个带有post_id、description 的新镜像 MyISAM 表,并通过触发器将其与posts 表同步。现在,在这个新的 MyISAM 表上进行全文搜索~400ms(与 InnoDB 显示的相同性能负载 ~18sec.. 这是一个巨大的性能提升)看起来 MyISAM 是MySQL 中的全文比 InnoDB 快得多。你能解释一下吗?
MySQL 分析器结果:
在 AWS RDS db.t2.small 实例上测试
原 InnoDB posts 表:
带有 post_id 的 MyISAM 镜像表,仅描述:
【问题讨论】:
-
您使用的是哪个表引擎? MyISAM 还是 InnoDB?
-
您了解为什么 InnoDB 查询需要 18 秒而分析信息加起来不到 0.5 秒吗?
标签: mysql sql full-text-search