MySQL - 不使用索引

Pet*_*gad 4 mysql sql performance

我想弄明白我可能做错了什么.此查询似乎没有使用索引,因为它取代了long.

执行时:

Explain SELECT a, b, c, d  FROM `table` WHERE d = 4013456

id       select_type     table       type    possible_keys       key     key_len     ref     rows    Extra`
1      SIMPLE          table       ALL     d                   NULL    NULL     NULL    79787   Using where`
index:
d    INDEX       79787
Run Code Online (Sandbox Code Playgroud)

有什么我做错了吗?解释里面的查询花了10秒钟......好像应该花不到一秒钟.

谢谢!

Asa*_*aph 7

你的索引没有被使用的原因是因为dvarchar(你在评论中提到过这个)并且你的where子句中有一个整数.如果您将查询更改为:

SELECT a, b, c, d  FROM `table` WHERE d = '4013456';
Run Code Online (Sandbox Code Playgroud)

它更有可能使用索引.但是更好的解决方案可能是将列更改为整数并保留查询(如果在其他情况下可能的话).