• 企业400电话
  • 微网小程序
  • AI电话机器人
  • 电商代运营
  • 全 部 栏 目

    企业400电话 网络优化推广 AI电话机器人 呼叫中心 网站建设 商标✡知产 微网小程序 电商运营 彩铃•短信 增值拓展业务
    mysql的in会不会让索引失效?

    mysql的in会让索引失效吗?不会! 看结果:

    mysql> desc select * from tb_province where name in ('lily3', 'lily2', 'lily1');
    +----+-------------+-------------+------------+------+---------------+------+---------+------+--------+----------+-------------+
    | id | select_type | table    | partitions | type | possible_keys | key | key_len | ref | rows  | filtered | Extra    |
    +----+-------------+-------------+------------+------+---------------+------+---------+------+--------+----------+-------------+
    | 1 | SIMPLE   | tb_province | NULL    | ALL | NULL     | NULL | NULL  | NULL | 108780 |  30.00 | Using where |
    +----+-------------+-------------+------------+------+---------------+------+---------+------+--------+----------+-------------+
    1 row in set, 1 warning (0.00 sec)
    
    mysql> alter table tb_province add index g(name);
    Query OK, 0 rows affected (0.29 sec)
    Records: 0 Duplicates: 0 Warnings: 0
    
    mysql> desc select * from tb_province where name in ('lily3', 'lily2', 'lily1');
    +----+-------------+-------------+------------+-------+---------------+------+---------+------+------+----------+-----------------------+
    | id | select_type | table    | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra         |
    +----+-------------+-------------+------------+-------+---------------+------+---------+------+------+----------+-----------------------+
    | 1 | SIMPLE   | tb_province | NULL    | range | g       | g  | 34   | NULL |  3 |  100.00 | Using index condition |
    +----+-------------+-------------+------------+-------+---------------+------+---------+------+------+----------+-----------------------+
    1 row in set, 1 warning (0.00 sec)
    mysql> 

    顺便说下,in查出的结果,不一定按in排序, 如下:

    mysql> select * from tb_province where name in ('lily3', 'lily2', 'lily1');
    +----+-------+-------+------+------+------+------+------+------+------+------+------+------+------+
    | id | name | score | x  | x1  | x2  | x3  | x4  | x5  | x6  | x7  | x8  | x9  | x10 |
    +----+-------+-------+------+------+------+------+------+------+------+------+------+------+------+
    | 1 | lily1 |   1 |  0 |  0 |  0 |  0 |  0 |  0 |  0 |  0 |  0 |  0 |  0 |
    | 2 | lily2 |   2 |  0 |  0 |  0 |  0 |  0 |  0 |  0 |  0 |  0 |  0 |  0 |
    | 3 | lily3 |   3 |  0 |  0 |  0 |  0 |  0 |  0 |  0 |  0 |  0 |  0 |  0 |
    +----+-------+-------+------+------+------+------+------+------+------+------+------+------+------+
    3 rows in set (0.00 sec)
    mysql> 

    总结

    以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对脚本之家的支持。如果你想了解更多相关内容请查看下面相关链接

    您可能感兴趣的文章:
    • MySQL索引失效的典型案例
    • mysql索引失效的几种情况分析
    • MySQL索引失效的几种情况详析
    • MySQL索引失效的几种情况汇总
    • mysql索引失效的五种情况分析
    • Mysql索引会失效的几种情况分析
    • 解决mysql模糊查询索引失效问题的几种方法
    上一篇:Mysql的数据库迁移到另一个机器上的方法详解
    下一篇:MySQL批量插入和唯一索引问题的解决方法
  • 相关文章
  • 

    © 2016-2020 巨人网络通讯 版权所有

    《增值电信业务经营许可证》 苏ICP备15040257号-8

    mysql的in会不会让索引失效? mysql,的,会不会,让,索引,