MySQL--------SQL优化审核工具实战
# cat sql.cnfusername=root
password=123
host=127.0.0.1
port=3306
dbname=test1
sqls=select * from user where name = 'lisea'
# ./sqladvisor -f sql.cnf -v 1
2017-10-27 05:40:14 34070 第1步: 对SQL解析优化之后得到的SQL:select `*` AS `*` from `test1`.`user` where (`name` = 'lisea')
2017-10-27 05:40:14 34070 第2步:开始解析where中的条件:(`name` = 'lisea')
2017-10-27 05:40:14 34070 show index from user
2017-10-27 05:40:14 34070 show table status like 'user'
2017-10-27 05:40:14 34070 select count(*) from ( select `name` from `user` FORCE INDEX( PRIMARY ) order by id DESC limit 1024) `user` where (`name` = 'lisea')
2017-10-27 05:40:14 34070 第3步:表user的行数:2048,limit行数:1024,得到where条件中(`name` = 'lisea')的选择度:1024
2017-10-27 05:40:14 34070 第4步:开始验证 字段name是不是主键。表名:user
2017-10-27 05:40:14 34070 show index from user where Key_name = 'PRIMARY' and Column_name ='name' and Seq_in_index = 1
2017-10-27 05:40:14 34070 第5步:字段name不是主键。表名:user
2017-10-27 05:40:14 34070 第6步:开始验证 字段name是不是主键。表名:user
2017-10-27 05:40:14 34070 show index from user where Key_name = 'PRIMARY' and Column_name ='name' and Seq_in_index = 1
2017-10-27 05:40:14 34070 第7步:字段name不是主键。表名:user
2017-10-27 05:40:14 34070 第8步:开始验证表中是否已存在相关索引。表名:user, 字段名:name, 在索引中的位置:1
2017-10-27 05:40:14 34070 show index from user where Column_name ='name' and Seq_in_index =1
2017-10-27 05:40:14 34070 第9步:开始输出表user索引优化建议:
2017-10-27 05:40:14 34070 Create_Index_SQL:alter table user add index idx_name(name)
2017-10-27 05:40:14 34070 第10步: SQLAdvisor结束!
页:
[1]