今天在做SQL语句优化的时候,在explain的时候,有这样一个提示:

mysql> explain SELECT max( up_start ) AS up_start FROM test WHERE up_start > '2008-01-19 00:00:00' and up_start < '2008-01-19 23:59:59';
+----+-------------+-------+------+---------------+------+---------+------+------+------------------------------+
| id | select_type | table | type | possible_keys | key  | key_len | ref  | rows | Extra                        |
+----+-------------+-------+------+---------------+------+---------+------+------+------------------------------+
|  1 | SIMPLE      | NULL  | NULL | NULL          | NULL | NULL    | NULL | NULL | Select tables optimized away |
+----+-------------+-------+------+---------------+------+---------+------+------+------------------------------+
1 row in set (0.00 sec)

我们还可以做这样一个测试:
用一个innodb表和一个myisam表进行select count(*)测试:

myisam表测试
mysql> explain select count(*) from myisam;
+----+-------------+-------+------+---------------+------+---------+------+------+------------------------------+
| id | select_type | table | type | possible_keys | key  | key_len | ref  | rows | Extra                        |
+----+-------------+-------+------+---------------+------+---------+------+------+------------------------------+
|  1 | SIMPLE      | NULL  | NULL | NULL          | NULL | NULL    | NULL | NULL | Select tables optimized away |
+----+-------------+-------+------+---------------+------+---------+------+------+------------------------------+
1 row in set (0.00 sec)

innodb表测试
mysql> explain select count(*) from innodb;
+----+-------------+-----------+-------+---------------+---------+---------+------+------+-------------+
| id | select_type | table     | type  | possible_keys | key     | key_len | ref  | rows | Extra       |
+----+-------------+-----------+-------+---------------+---------+---------+------+------+-------------+
|  1 | SIMPLE      | innodb    | index | NULL          | PRIMARY | 4       | NULL |    4 | Using index |
+----+-------------+-----------+-------+---------------+---------+---------+------+------+-------------+
1 row in set (0.00 sec)

这2个输出的结果里,Extra列输出了"Select tables optimized away"语句。
第2个很明显,myisam已经保存了记录的总数,直接返回结果,,而innodb还需要全表扫描。

这个在MySQL的手册里面没有任何提及,不过看其他各列的数据大概能猜到意思:SELECT操作已经优化到不能再优化了(MySQL根本没有遍历表或索引就返回数据了)。

在MySQL官方站点翻到两段相关的描述,印证了上述观点,原文如下:
For explains on simple count queries (i.e. explain select count(*) from people) the extra section will read "Select tables optimized away." This is due to the fact that MySQL can read the result directly from the table internals and therefore does not need to perform the select.

mysql explain中的 “Select tables optimized away”相关推荐

  1. optimized mysql_mysql中的Select tables optimized away

    mysql中的Select tables optimized away mysql> explain select * from bet_match_result where lottery_n ...

  2. optimized mysql_MySQL解释计划中“Select tables optimized away”的含义

    MySQL解释计划中"Select tables optimized away"的含义 在MySQL解释计划中Select tables optimized away的含义是什么? ...

  3. mysql key_len_浅谈mysql explain中key_len的计算方法

    mysql的explain命令可以分析sql的性能,其中有一项是key_len(索引的长度)的统计.本文将分析mysql explain中key_len的计算方法. 1.创建测试表及数据 CREATE ...

  4. mysql explain中key_len值的说明

    在mysql 的explain的输出中,有个key_len的列,其数据是如何计算的呢? 在看到了淘宝的dba以前发布的博客后,我在mysql 5.6上操作一番,了解了一点. 环境准备 – 创建表. u ...

  5. lock mysql unlock_MySQL中的lock tables和unlock tables

    MySQL允许客户端会话显式地获取表锁,以便与其他会话协作访问表,或者防止其他会话在其需要独占表时使用表.这个能力就是通过LOCK TABLES和UNLOCK TABLES实现的. LOCK TABL ...

  6. Mysql explain 中的extra字段 解读

    extra 是 explain 中比较重要的一个属性指标之一,标识着SQL语句的索引使用情况. 接下来 讲讲常用见的几种状态. Using filesort 这种情况是在使用 order by 关键字 ...

  7. mysql explain中的type列含义和extra列的含义

    很多朋友在用mysql进行调优的时候都肯定会用到explain来看select语句的执行情况,这里简单介绍结果中两个列的含义. 1 type列 官方的说法,说这列表示的是"访问类型" ...

  8. mysql explain using_[MySQL] explain中的using where和using index

    1. 查看表中的所有索引 show index from modify_passwd_log;  有两个 一个是id的主键索引,一个是email_id的普通索引 2. using index表示 使用 ...

  9. mysql存储过程中使用select count(*) into 变量名 from +表+ where条件的用法

    select count(*) into v_count from dual where userid=2; 此语句的意思就是根据where条件查询dual表,得到的行数存入变量v_count中(给变 ...

最新文章

  1. 1.7 单层卷积网络-深度学习第四课《卷积神经网络》-Stanford吴恩达教授
  2. 开机后能解锁吗_黔隆科技刷机教程360奇酷Q5PLUS(1509A00)忘记密码刷机解锁降级救砖解屏幕锁账户锁教程...
  3. 两数之和C++代码实现超详细讲解
  4. C语言学习记录_2019.02.02
  5. 会签 数据库表设计_关于数据库表设计和实体类设计的思考
  6. HW--漂亮度2(测试通过)
  7. C# 获取枚举的描述属性
  8. UDP --02--UDP广播数据
  9. url,href,src区别
  10. 函数参数约定、传递顺序、传递方式
  11. 无法访问工作组计算机修复工具,局域网共享一键修复工具
  12. Nginx 集群搭建
  13. matlab气体流速,气体流速的测定方法.pdf
  14. 计算机网络电子邮件的基本格式,怎样的格式才是正确的电子邮件格式?
  15. echarts折线颜色渐变
  16. android手机 清除DNS缓存命令
  17. 删除 文件夹出现0x80070091错误提示目录不是空的.txt
  18. 17.2: Apps that require users to share personal information, such as email address and date of birth
  19. uniapp 读取手机 通讯录 分组
  20. html+css制作盾牌飞入效果

热门文章

  1. WebRTC源码下载
  2. [SolidWorks二次开发]草图绘制——总论
  3. SVN 不能打开文件 系统找不到指定文件
  4. android局域网直播,安卓共享局域网硬盘实现云播放的方法
  5. 一个c语言程序的开发环境,C语言入门(2)——安装VS2013开发环境并编写第一个C语言程序...
  6. 游戏感:虚拟感觉的游戏设计师指南——译序和引言
  7. fast-request-2.1.3 免费版
  8. 三氯生对人绒毛膜滋养层细胞HTR8-SVneo功能影响的研究
  9. 你会喜欢,最哲理感人的10段话:就算生活给你的是垃圾...
  10. 通过手机GPRS收发Gmail邮件