Home > Database > Mysql Tutorial > MySQL中,为什么索引失效?

MySQL中,为什么索引失效?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 16:42:06
Original
1398 people have browsed it

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:这个值越高,说明查询低效

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
MySQL stops process
From 1970-01-01 08:00:00
0
0
0
Error when installing mysql on linux
From 1970-01-01 08:00:00
0
0
0
phpstudy cannot start mysql?
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template