Mysql高级索引优化案例----单表(七)

Mysql高级索引优化案例----单表(七)Mysql高级索引优化案例----单表(七)

Mysql高级索引优化案例----单表(七)

单表:

      先建表:

Mysql高级索引优化案例----单表(七)

Mysql高级索引优化案例----单表(七)

案例:查询category_id 为1且comments大于1的情况下,views最多的article_id

Mysql高级索引优化案例----单表(七)

Mysql高级索引优化案例----单表(七)

开始优化:创建索引create index idx_article_ccv on article(category_id,comments,views)

Mysql高级索引优化案例----单表(七)

如果把comments>1变为comments=1

Mysql高级索引优化案例----单表(七)

Mysql高级索引优化案例----单表(七)

优化2:先删除原来建立的索引:DROP INDEX idx_article_ccv ON article;

          再建立新的索引create  index idx_article_cv on article(category_id,views);======避开comments>1这个

Mysql高级索引优化案例----单表(七)

结论:可以看到type变为ref,Extra的using filesort也不见了,结果非常理想,