记录一个问题,mysql查询的时候如果有隐式转换会导致索引失效
如执行计划:
带有隐式转换的查询:
desc select * from xx_product where sn=4486466;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE xx_product ALL sn 467235 10.00 Using where
type为all,索引失效,走的全表扫描
没有隐式转换的查询:
desc select * from xx_product where sn='4486466';
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE xx_product const sn sn 302 const 1 100.00
因为我的的表的sn字段是唯一键,所以type为const,说明索引成功