• 三十七、【进阶】SQL的explain


    1、explain

    2、基础使用

    在使用explain关键字时,只需要在所执行语句前加上explain即可

    1. mysql> explain select * from stu where id=3;
    2. +----+-------------+-------+------------+-------+---------------+---------+---------+-------+------+----------+-------+
    3. | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
    4. +----+-------------+-------+------------+-------+---------------+---------+---------+-------+------+----------+-------+
    5. | 1 | SIMPLE | stu | NULL | const | PRIMARY | PRIMARY | 4 | const | 1 | 100.00 | NULL |
    6. +----+-------------+-------+------------+-------+---------------+---------+---------+-------+------+----------+-------+
    7. 1 row in set, 1 warning (0.00 sec)

    3、id

    4、select_type

    5、type

     (1)当根据主键or唯一索引进行访问时,type参数会显示为const:

    1. mysql> explain select * from stu where id=3;
    2. +----+-------------+-------+------------+-------+---------------+---------+---------+-------+------+----------+-------+
    3. | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
    4. +----+-------------+-------+------------+-------+---------------+---------+---------+-------+------+----------+-------+
    5. | 1 | SIMPLE | stu | NULL | const | PRIMARY | PRIMARY | 4 | const | 1 | 100.00 | NULL |
    6. +----+-------------+-------+------------+-------+---------------+---------+---------+-------+------+----------+-------+
    7. 1 row in set, 1 warning (0.00 sec)

    (2)当不查询任何表时,type参数显示为NULL:

    1. mysql> explain select 'a';
    2. +----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+----------------+
    3. | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
    4. +----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+----------------+
    5. | 1 | SIMPLE | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | No tables used |
    6. +----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+----------------+
    7. 1 row in set, 1 warning (0.00 sec)

    (3)使用非唯一性索引,type参数通常显示为ref:

    6、possible_key

    显示这张表上可能用到的索引,一个或者多个

    7、Key

    实际使用的索引,如果为NULL,则没有使用索引

    8、Key_len

    表示索引中使用的字节数,该值为索引字段最大可能长度,并非实际使用长度,在不损失精确性的前提下,长度越短越好

    9、rows

    MySQL认为必须要执行查询的行数,在innodb引擎的表中,是一个估计值,可能并不总是准确的。

    10、filtered

    表示返回结果的行数栈读取行数的百分比,filtered的值越大越好

  • 相关阅读:
    小程序和uniapp中scroll-view触底加载
    微服务使用UNI-APP开发手机APP流程及VUE前端注意事项
    使用OpenCV的函数hconcat()、vconcat()实现图像或矩阵的连接
    IAR 下的雅特力AT32F415CBT7工程创建与设置
    《爆肝整理》保姆级系列教程-玩转Charles抓包神器教程(14)-Charles过滤网络请求
    MySQL之事务隔离级别和MVCC
    Chrome浏览器不好用?因为你没安装扩展插件
    Netty—Channel
    基于vite3+tauri模拟QQ登录切换窗体|Tauri自定义拖拽|最小/大/关闭
    Linxu系统(Centos 7)安装 DNS 服务
  • 原文地址:https://blog.csdn.net/2301_79149013/article/details/133970446