加入收藏 | 设为首页 | 会员中心 | 我要投稿 核心网 (https://www.hxwgxz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程 > 正文

MySQL EXPLAIN结果集分析 - 附带大量案例

发布时间:2019-09-18 00:07:43 所属栏目:编程 来源:佚名
导读:EXPLAIN:查看SQL语句的执行计划 EXPLAIN命令可以帮助我们深入了解MySQL基于开销的优化器,还可以获得很多可能被优化器考虑到的访问策略的细节,以及当运行SQL语句时哪种策略预计会被优化器采用,在优化慢查询时非常有用。 执行explain之后结果集包含如下

dependent union: union中的第二个或随后的select查询,依赖于外部查询的结果集

  1. mysql> explain select * from test where id in (select id  from test where id = 1000 union all select id from test2) ; 
  2. +----+--------------------+------------+--------+---------------+---------+---------+-------+-------+-----------------+ 
  3. | id | select_type        | table      | type   | possible_keys | key     | key_len | ref   | rows  | Extra           | 
  4. +----+--------------------+------------+--------+---------------+---------+---------+-------+-------+-----------------+ 
  5. |  1 | PRIMARY            | test       | ALL    | NULL          | NULL    | NULL    | NULL  | 68505 | Using where     | 
  6. |  2 | DEPENDENT SUBQUERY | test       | const  | PRIMARY       | PRIMARY | 8       | const |     1 | Using index     | 
  7. |  3 | DEPENDENT UNION    | test2      | eq_ref | PRIMARY       | PRIMARY | 8       | func  |     1 | Using index     | 
  8. | NULL | UNION RESULT       | <union2,3> | ALL    | NULL          | NULL    | NULL    | NULL  |  NULL | Using temporary | 
  9. +----+--------------------+------------+--------+---------------+---------+---------+-------+-------+-----------------+ 

subquery: 子查询中的第一个select查询,不依赖与外部查询的结果集

  1. mysql> explain select * from test where id = (select id from test where id = 1000); 
  2. +----+-------------+-------+-------+---------------+---------+---------+-------+------+-------------+ 
  3. | id | select_type | table | type  | possible_keys | key     | key_len | ref   | rows | Extra       | 
  4. +----+-------------+-------+-------+---------------+---------+---------+-------+------+-------------+ 
  5. |  1 | PRIMARY     | test  | const | PRIMARY       | PRIMARY | 8       | const |    1 | NULL        | 
  6. |  2 | SUBQUERY    | test  | const | PRIMARY       | PRIMARY | 8       | const |    1 | Using index | 
  7. +----+-------------+-------+-------+---------------+---------+---------+-------+------+-------------+ 

(编辑:核心网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

热点阅读