记一次不走索引的异常情况
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表并没有走索引

经过排查发现

t_item_detail的唯一键的编码类型为utf8_general_ci
然后
t_proof表的 item_unique字段编码类型为utf8_bin
将类型改成一致为utf8_bin之后,就走索引了


本文探讨了一次数据库查询中未按预期使用索引的问题。在连接t_proof与t_item_detail表时,因字段编码类型不一致(utf8_general_ci与utf8_bin),导致t_item_detail表上的索引未被利用。通过将编码类型统一为utf8_bin,成功解决了这一问题,提升了查询效率。
2061

被折叠的 条评论
为什么被折叠?



