关于mysql:MySql-Explain-调优踩坑

5次阅读

共计 382 个字符,预计需要花费 1 分钟才能阅读完成。

事件背景

生产环境发现有查问超时,通过异样日志获取查问 sql 并进行排查,explain 后发现该 sql 应用了 filesort,导致查问效率问题

查问 sql & 索引状况

  • 查问 sql
    select * from table where column1 = ‘xxx’ and column2 in (‘a’,’b’,’c’) order by id asc limit 100
  • 现有索引
    主键索引
    联结索引 column1,column3

优化过程

通过 explain 发现,上述 sql 应用到了 column1,column3 的联结索引,然而查问中并不蕴含 column3 列,猜想可能是因为这个优化引擎应用了该索引才导致的 filesort

于是删除 column1,column3 的联结索引,并建设 column1,column2,column3 的独自索引,并再次执行 explain 查看性能,发现曾经不存在 filesort,解决了性能问题

正文完
 0