mysql 查询优化

时间:2014-11-13 12:47:49   收藏:0   阅读:192

假设数据库建立了三个索引字段,如下图

1. 数据库栏位

bubuko.com,布布扣

2. 索引栏位

bubuko.com,布布扣

最左侧索引为“主键索引”,其他两栏为“普通索引”

3. 以下是where不同索引字段组合的查询情况

where最左侧索引字段

select * from wx_new.wxtl_log where company_id = 1

bubuko.com,布布扣

where最左侧和中间索引字段

select * from wx_new.wxtl_log where company_id = 1 and msg_type = 1

bubuko.com,布布扣

where三个索引字段

select * from wx_new.wxtl_log where company_id = 1 and msg_type = 1 and reply_type = 1

bubuko.com,布布扣

where中间索引字段

select * from wx_new.wxtl_log where msg_type = 1

bubuko.com,布布扣

where最右侧索引字段

select * from wx_new.wxtl_log where reply_type = 1

bubuko.com,布布扣

where后两个索引字段

select * from wx_new.wxtl_log where msg_type = 1 and reply_type = 1

bubuko.com,布布扣

更多优化请参考

数据库SQL优化大总结之 百万级数据库优化方案

评论(0)
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!