Mysql复合索引,条件中有or时使用不到

建表语句的sql片段:

      KEY `c_d_e_f` (`c`,`d`,`e`,`f`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='XXXXXXX';

查询语句

select
c1,
c2,
c3
from
t1
WHERE (a = 'xxa'  or b = 'xxb' )
and c='xxc'
and d = 'xxd'
and e = 'xxe'
and f ='xxf'
ORDER BY b desc

结果:

用到索引:c_d_e_f

修改语句1:

        alter table t1 drop index c_d_e_f

        create index a_c_d_e_f on
        t1(`a`,`c`,`d`,`e`,`f`)

结果:

用不到索引:a_c_d_e_f

修改语句2:

        alter table t1 drop index a_c_d_e_f

        create index b_c_d_e_f on
        t1(`b`,`c`,`d`,`e`,`f`)

结果:

用不到索引:b_c_d_e_f

你可能感兴趣的:(Mybatis,Mysql)