(7). DEPENDENT SUBQUERY
子查询中的第一个select,取决于外面的查询。
mysql> explain select id from t3 where id in (select id from t3 where id=3952602 ) ; +—-+——————–+——-+——-+——————-+———+———+——-+——+————————–+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +—-+——————–+——-+——-+——————-+———+———+——-+——+————————–+ | 1 | PRIMARY | t3 | index | NULL | PRIMARY | 4 | NULL | 1000 | Using where; Using index | | 2 | DEPENDENT SUBQUERY | t3 | const | PRIMARY,idx_t3_id | PRIMARY | 4 | const | 1 | Using index | +—-+——————–+——-+——-+——————-+———+———+——-+——+————————–+ |
派生表的select(FROM子句的子查询)
mysql> explain select * from (select * from t3 where id=3952602) a ; +—-+————-+————+——–+——————-+———+———+——+——+——-+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +—-+————-+————+——–+——————-+———+———+——+——+——-+ | 1 | PRIMARY | | system | NULL | NULL | NULL | NULL | 1 | | | 2 | DERIVED | t3 | const | PRIMARY,idx_t3_id | PRIMARY | 4 | | 1 | | +—-+————-+————+——–+——————-+———+———+——+——+——-+ |
3.table
显示这一行的数据是关于哪张表的.
有时不是真实的表名字,看到的是derivedx(x是个数字,我的理解是第几步执行的结果)
mysql> explain select * from (select * from ( select * from t3 where id=3952602) a) b; +—-+————-+————+——–+——————-+———+———+——+——+——-+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +—-+————-+————+——–+——————-+———+———+——+——+——-+ | 1 | PRIMARY | | system | NULL | NULL | NULL | NULL | 1 | | | 2 | DERIVED | | system | NULL | NULL | NULL | NULL | 1 | | | 3 | DERIVED | t3 | const | PRIMARY,idx_t3_id | PRIMARY | 4 | | 1 | | +—-+————-+————+——–+——————-+———+———+——+——+——-+ |
4.type
这列很重要,显示了连接使用了哪种类别,有无使用索引.
从最好到最差的连接类型为const、eq_reg、ref、range、indexhe和ALL
(1).system
这是const联接类型的一个特例。表仅有一行满足条件.如下(t3表上的id是 primary key)
mysql> explain select * from (select * from t3 where id=3952602) a ; +—-+————-+————+——–+——————-+———+———+——+——+——-+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +—-+————-+————+——–+——————-+———+———+——+——+——-+ | 1 | PRIMARY | | system | NULL | NULL | NULL | NULL | 1 | | | 2 | DERIVED | t3 | const | PRIMARY,idx_t3_id | PRIMARY | 4 | | 1 | | +—-+————-+————+——–+——————-+———+———+——+——+——-+ |
我们一直都在努力坚持原创.......请不要一声不吭,就悄悄拿走。
我原创,你原创,我们的内容世界才会更加精彩!
【所有原创内容版权均属TechTarget,欢迎大家转发分享。但未经授权,严禁任何媒体(平面媒体、网络媒体、自媒体等)以及微信公众号复制、转载、摘编或以其他方式进行使用。】
微信公众号

TechTarget
官方微博

TechTarget中国
作者
相关推荐
-
2017年3月数据库流行度排行榜 Oracle卫冕之路困难重重
时隔一个月,数据库市场经过一轮“洗牌”,旧的市场格局是否会被打破,曾经占巨大市场份额的企业是否可能失去优势?
-
2017年2月数据库流行度排行榜 攻城容易守城难
2016年下半年,数据库排行榜的前二十名似乎都“固守阵地”,在排名上没有太大的变动。随着2017年的悄然而至,数据库的排名情况是否会有新的看点?
-
MySQL管理特性:让企业适合交易平台
当Alexander Culiniac和他的同事在TickTrade系统公司建立一个基于云的交易平台时,面临一些基本的约束。那就是,系统必须在云上工作良好并且经济实用。
-
数据库和数据仓库的区别在哪儿?
目前,大部分数据仓库还是用数据库进行管理。数据库是整个数据仓库环境的核心,是数据存放的地方和提供对数据检索的支持。