很早之前就听别人说in 不走索引,但是一直没证实过,昨天在工作中用到了in所以在上班的时候突发奇想,使用mysql 的explain 关键字看下一条sql走不走索引,sql 如下所示:
- explain SELECT
- *
- FROM
- lg_order
- WHERE
- logistics_number IN (
- '03245100007990077',
- '0324510000799007',
- '0323920000077348500001',
- '0329660000077348501001',
- '0322340000799007734',
- '0283920000799009498',
- '132902052979900773485',
- '03215700007998558001',
- '132284314879900s779001',
- '1329080973077348560001',
- '13292709257990077348561001',
- '1321640241777348562s001',
- '1324100421799007734ss8563001',
- '13224702197990077348561',
- '0326200000799007734s86001',
- '1327550457799007767001',
- '132836013379900768001',
- '132760071979900',
- '132249127779900')
如上图所示,这里用到了in,但是这条sql 还是走了索引,如下图:
explain 关键字不懂,参考这篇文章: