Heim  >  Artikel  >  Datenbank  >  MySQL中,为什么索引失效?

MySQL中,为什么索引失效?

WBOY
WBOYOriginal
2016-06-07 16:42:061320Durchsuche

1、 如果条件中有or,即使其中有条件带索引也不会使用(这也是为什么尽量少用or的原因); 2、 对于多列索引,不是使用的第一部分,则不会使用索引; 3、 like查询是以%开头; 4、 如果列类型是字符串,那一定要在条件中将数据使用引号引用起来,否则不使用索引

1、如果条件中有or,即使其中有条件带索引也不会使用(这也是为什么尽量少用or的原因);

2、对于多列索引,不是使用的第一部分,则不会使用索引;

3、like查询是以%开头;

4、如果列类型是字符串,那一定要在条件中将数据使用引号引用起来,否则不使用索引;

5、如果mysql估计使用全表扫描要比使用索引快,则不使用索引;

6、对索引列进行进行计算或用函数加以处理时;

7、条件中有not in, not exist;


此外,查看索引的使用情况

show status like ‘Handler_read%’;
大家可以注意:
handler_read_key:这个值越高越好,越高表示使用索引查询到的次数

handler_read_rnd_next:这个值越高,说明查询低效

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn