Mysql慢速查询使用索引记录查询
我启用了慢速查询日志来记录运行时间超过2秒的查询以及不使用索引的日志查询 我注意到一些使用索引的频繁查询继续出现在日志中 示例查询Mysql慢速查询使用索引记录查询,mysql,Mysql,我启用了慢速查询日志来记录运行时间超过2秒的查询以及不使用索引的日志查询 我注意到一些使用索引的频繁查询继续出现在日志中 示例查询 SELECT `a`.`orderid`, `a`.`date`, `a`.`status`, `a`.`restname`, `a`.`admin_user`, `a`.`model_type`, `b`.`name` as cityname FROM `tk_order` AS a INNER JOIN `tk_city` AS b ON `a`.`cit
SELECT `a`.`orderid`, `a`.`date`, `a`.`status`, `a`.`restname`, `a`.`admin_user`, `a`.`model_type`, `b`.`name` as cityname
FROM `tk_order` AS a
INNER JOIN `tk_city` AS b ON `a`.`cityid` = `b`.`id`
WHERE `a`.`date` = '2012-04-09'
AND `a`.`status` = 0
AND `a`.`mode` = 3
ORDER BY `a`.`orderid` desc;
在上面的查询中,我添加了日期、状态、模式的复合索引,当我运行explain时,这就是输出
1 SIMPLE a ref cityid,date_3 date_3 4 const,const 6 Using where; Using temporary; Using filesort
1 SIMPLE b index PRIMARY,id id 52 2 Using where; Using index; Using join buffer
order表大约有100000条记录,不确定我在这里做错了什么。您在tk_order上有哪些索引?日期、状态、模式的复合索引其他索引是orderid、RestId这可能是因为您启用了日志查询,而不是使用索引,请参阅类似帖子: