为什么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 |
这里有一个类似的问题。
作为@solarflare作为注释,当将索引字段与其他类型的参数进行比较时,MySQL不使用该字段上的索引,因为字符串顺序与数字顺序不同,对于许多其他问题和差异,到字典的整理。
总体不同的类型具有不同的"规则",不应方便地使用索引。