mysql 查询优化
假设数据库建立了三个索引字段,如下图
1. 数据库栏位

2. 索引栏位

最左侧索引为“主键索引”,其他两栏为“普通索引”
3. 以下是where不同索引字段组合的查询情况
where最左侧索引字段
select * from wx_new.wxtl_log where company_id = 1

where最左侧和中间索引字段
select * from wx_new.wxtl_log where company_id = 1 and msg_type = 1

where三个索引字段
select * from wx_new.wxtl_log where company_id = 1 and msg_type = 1 and reply_type = 1

where中间索引字段
select * from wx_new.wxtl_log where msg_type = 1

where最右侧索引字段
select * from wx_new.wxtl_log where reply_type = 1

where后两个索引字段
select * from wx_new.wxtl_log where msg_type = 1 and reply_type = 1

更多优化请参考

浙公网安备 33010602011771号