zoukankan      html  css  js  c++  java
  • mysql --sql执行语句的详情

    使用 EXPLAIN 函数可以清楚的查看语句的执行情况


    EXPLAIN select id from b_nc_card where id
    != 10000;

    一共查询了:530912 行 

    优化后

    EXPLAIN
    (select id from b_nc_card where id > 10000)
     union all
    (select id from b_nc_card where id < 10000 and id > 0)
    1    SIMPLE    b_nc_card        range    PRIMARY    PRIMARY    4        530912    100.00    Using where; Using index

     一共查询了:511856  +  19032  = 530888  行 

    概要描述:
    id:选择标识符
    select_type:表示查询的类型。
    table:输出结果集的表
    partitions:匹配的分区
    type:表示表的连接类型
    possible_keys:表示查询时,可能使用的索引
    key:表示实际使用的索引
    key_len:索引字段的长度
    ref:列与索引的比较
    rows:扫描出的行数(估算的行数)
    filtered:按表条件过滤的行百分比
    Extra:执行情况的描述和说明 Using where; Using index(出现这个说明是最优解)

    注: 主要关注的是,type 和 key

    type = ALL :表示全表扫描

    type = const :表示通过索引一次就找到了

    type = ref:对于每个来自于前面的表的行组合,所有有匹配索引值的行将从这张表中读取。

    type = index:该联接类型与ALL相同,除了只有索引树被扫描。这通常比ALL快,因为索引文件通常比数据文件小。

    type = range:只检索给定范围的行,使用一个索引来选择行。

    key = NULL:表示没有使用索引

    key = primary :表示使用了主键

  • 相关阅读:
    牛客网 二叉树的镜像 JAVA
    牛客网 反转链表 JAVA
    牛客网 调整数组顺序使奇数位于偶数前面 JAVA
    Integer to Roman LeetCode Java
    Valid Number leetcode java
    Longest Common Prefix
    Wildcard Matching leetcode java
    Regular Expression Matching
    Longest Palindromic Substring
    Add Binary LeetCode Java
  • 原文地址:https://www.cnblogs.com/alomsc/p/13164629.html
Copyright © 2011-2022 走看看