都有索引的情况下不走索引的原因,数据库表字段编码类型不同

记一次不走索引的异常情况

 explain select   * from t_proof p   
 left join t_item_detail t  on p.item_unique=t.unique_code
 left join t_capital_detail c on p.cap_unique=c.unique_code  
where p.batch_no='批次号1' and  check_type=1  and error_type=1 

t_item_detail 表的unique_code字段上有建立索引
t_proof表的 item_unique字段上也有索引
但是 事实上,发现 t_item_detail表并没有走索引
在这里插入图片描述

经过排查发现
都有索引的情况下不走索引的原因,数据库表字段编码类型不同_第1张图片
t_item_detail的唯一键的编码类型为utf8_general_ci

然后
t_proof表的 item_unique字段编码类型为utf8_bin

将类型改成一致为utf8_bin之后,就走索引了
都有索引的情况下不走索引的原因,数据库表字段编码类型不同_第2张图片

你可能感兴趣的:(不走索引,索引,mysql,debug)