玩龙天子 发表于 2018-10-19 10:42:07

SQL索引优化工具SQLAdvisor介绍

# ./sqladvisor -f test.cnf -v 1  2018-06-14 18:15:09 1348 第1步: 对SQL解析优化之后得到的SQL:select `*` AS `*` from `zhangyou`.`test_table01` where ((`zoneid` = 42) and (`views` = 198))
  2018-06-14 18:15:09 1348 第2步:开始解析where中的条件:(`zoneid` = 42)
  2018-06-14 18:15:09 1348 show index from test_table01
  2018-06-14 18:15:09 1348 show table status like 'test_table01'
  2018-06-14 18:15:09 1348 select count(*) from ( select `zoneid` from `test_table01` FORCE INDEX( day ) order by day DESC,planid DESC,uid DESC,siteid DESC,zoneid DESC,adstypeid DESC limit 10000) `test_table01` where (`zoneid` = 42)
  2018-06-14 18:15:09 1348 第3步:表test_table01的行数:120201,limit行数:10000,得到where条件中(`zoneid` = 42)的选择度:10000
  2018-06-14 18:15:09 1348 第4步:开始解析where中的条件:(`views` = 198)
  2018-06-14 18:15:09 1348 show index from test_table01
  2018-06-14 18:15:09 1348 show table status like 'test_table01'
  2018-06-14 18:15:09 1348 select count(*) from ( select `views` from `test_table01` FORCE INDEX( day ) order by day DESC,planid DESC,uid DESC,siteid DESC,zoneid DESC,adstypeid DESC limit 10000) `test_table01` where (`views` = 198)
  2018-06-14 18:15:09 1348 第5步:表test_table01的行数:120201,limit行数:10000,得到where条件中(`views` = 198)的选择度:2000
  2018-06-14 18:15:09 1348 第6步:开始验证 字段zoneid是不是主键。表名:test_table01
  2018-06-14 18:15:09 1348 show index from test_table01 where Key_name = 'PRIMARY' and Column_name ='zoneid' and Seq_in_index = 1
  2018-06-14 18:15:09 1348 第7步:字段zoneid不是主键。表名:test_table01
  2018-06-14 18:15:09 1348 第8步:开始验证 字段zoneid是不是主键。表名:test_table01
  2018-06-14 18:15:09 1348 show index from test_table01 where Key_name = 'PRIMARY' and Column_name ='zoneid' and Seq_in_index = 1
  2018-06-14 18:15:09 1348 第9步:字段zoneid不是主键。表名:test_table01
  2018-06-14 18:15:09 1348 第10步:开始验证表中是否已存在相关索引。表名:test_table01, 字段名:zoneid, 在索引中的位置:1
  2018-06-14 18:15:09 1348 show index from test_table01 where Column_name ='zoneid' and Seq_in_index =1
  2018-06-14 18:15:09 1348 第11步:开始验证 字段views是不是主键。表名:test_table01
  2018-06-14 18:15:09 1348 show index from test_table01 where Key_name = 'PRIMARY' and Column_name ='views' and Seq_in_index = 1
  2018-06-14 18:15:09 1348 第12步:字段views不是主键。表名:test_table01
  2018-06-14 18:15:09 1348 第13步:开始验证表中是否已存在相关索引。表名:test_table01, 字段名:views, 在索引中的位置:2
  2018-06-14 18:15:09 1348 show index from test_table01 where Column_name ='views' and Seq_in_index =2
  2018-06-14 18:15:09 1348 第14步:开始输出表test_table01索引优化建议:

  ~~*2018-06-14 18:15:09 1348 CreateIndexSQL:alter table testtable01 add index>  2018-06-14 18:15:09 1348 第15步: SQLAdvisor结束!

页: [1]
查看完整版本: SQL索引优化工具SQLAdvisor介绍