我有一张表tb_profilecomments:
4,3 GiB -- 总共 800 万行 -- InnoDB
有3个索引:
我运行的查询很简单:
SELECT *
FROM tb_profilecomments
WHERE profilecomment_user_id=6430
ORDER BY profilecomment_id DESC
在不到 1 秒的时间内获得结果(16.000+ 行)。当我现在添加LIMIT 1, 5
到查询中时,我必须等待超过 2 分钟才能得到结果。
不知道 mysql 后台会发生什么,为什么它会严重减慢查询速度。
当我从查询中删除ORDER BY
或删除时LIMIT
,一切都很好。
当按非索引profilecomment_date
列对其进行排序时,它很慢(7 秒),但不像使用索引主键进行排序和限制时那样的 2 分钟profilecomment_id
。
你知道有什么问题吗?可能是损坏的索引?如何发现?怎么修?ANALYZE TABLE 显示消息“ok”。
解释tb_profilecomments :
显示创建表tb_profilecomments:
结果EXPLAIN SELECT * FROM tb_profilecomments WHERE profilecomment_user_id=6430 ORDER BY profilecomment_id DESC LIMIT 1, 5
: