为什么mysql在索引列上搜索空字符串时不使用索引?
explain select * from DEFAULT_TABLE where RANDOMID = '';
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
| 1 | SIMPLE | DEFAULT_TABLE | ALL | RANDOMID | NULL | NULL | NULL | 108 | Using where |
explain select * from DEFAULT_TABLE where RANDOMID IS NULL;
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
| 1 | SIMPLE | DEFAULT_TABLE | ref | RANDOMID | RANDOMID | 9 | const | 1 | Using index condition |
最佳答案
有个类似的问题here .
正如@Solarflare 在评论中所写,当索引字段与不同类型参数进行比较时,MySQL 不使用该字段上的索引,因为字符串顺序与数字顺序不同,并且对于许多其他问题和差异相关到字典整理。
整体不同的类型有不同的'规则',使用索引应该不方便。
关于mysql - 使用表上的索引时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47556364/