MySQL中,为什么索引失效?
Jun 07, 2016 pm 04:42 PM1、 如果条件中有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:这个值越高,说明查询低效
原文地址:MySQL中,为什么索引失效?, 感谢原作者分享。

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

deepseek why can't you log in deepseek login portal

Why can't the Bybit exchange link be directly downloaded and installed?

Why is Bittensor said to be the 'bitcoin' in the AI track?

gateio exchange app old version gateio exchange app old version download channel

Bitcoin: The 'barometer' of global liquidity?

Cryptocurrency Investment Guide for 2025! Novice can learn it
