http://blog.163.com/li_hx/blog/static/183991413201642410122327/

mysql> CREATE TABLE t1 (a INT, b INT);
Query OK, rows affected (0.22 sec) mysql> CREATE TABLE t2 (c INT, d INT);
Query OK, rows affected (0.21 sec) mysql> CREATE TABLE t3 (e INT);
Query OK, rows affected (0.22 sec) mysql> INSERT INTO t1 VALUES (,), (,);
Query OK, rows affected (0.19 sec)
Records: Duplicates: Warnings: mysql> INSERT INTO t2 VALUES (,), (,);
Query OK, rows affected (0.17 sec)
Records: Duplicates: Warnings: mysql> INSERT INTO t3 VALUES (), ();
Query OK, rows affected (0.18 sec)
Records: Duplicates: Warnings:
mysql> select * from t1;
+------+------+
| a | b |
+------+------+
| | |
| | |
+------+------+
rows in set (0.00 sec) mysql> select * from t2;
+------+------+
| c | d |
+------+------+
| | |
| | |
+------+------+
rows in set (0.00 sec) mysql> select * from t3;
+------+
| e |
+------+
| |
| |
+------+
rows in set (0.00 sec)
mysql> EXPLAIN SELECT * FROM t1 WHERE t1.a IN (SELECT c FROM t2 WHERE (SELECT e FROM t3 as t31) < SOME (SELECT e FROM t3 as t32 WHERE t1.b));
+----+--------------------+-------+------+---------------+------+---------+------+------+--------------------------------------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+--------------------+-------+------+---------------+------+---------+------+------+--------------------------------------------------------------------+
| | PRIMARY | t1 | ALL | NULL | NULL | NULL | NULL | | Using where |
| | PRIMARY | t2 | ALL | NULL | NULL | NULL | NULL | | Using where; FirstMatch(t1); Using join buffer (Block Nested Loop) |
| | DEPENDENT SUBQUERY | t32 | ALL | NULL | NULL | NULL | NULL | | Using where |
| | SUBQUERY | t31 | ALL | NULL | NULL | NULL | NULL | | NULL |
+----+--------------------+-------+------+---------------+------+---------+------+------+--------------------------------------------------------------------+
rows in set (0.00 sec)
mysql> EXPLAIN format=json SELECT * FROM t1 WHERE t1.a IN (SELECT c FROM t2 WHERE (SELECT e FROM t3 as t31) < SOME (SELECT e FROM t3 as t32 WHERE t1.b))\G
*************************** . row ***************************
EXPLAIN: {
"query_block": {
"select_id": ,
"nested_loop": [
{
"table": {
"table_name": "t1",
"access_type": "ALL",
"rows": ,
"filtered": ,
"attached_condition": "<nop>(<in_optimizer>((/* select#3 */ select `test`.`t31`.`e` from `test`.`t3` `t31`),<exists>(/* select#4 */ select 1 from `test`.`t3` `t32` where (`test`.`t1`.`b` and <if>(outer_field_is_not_null, ((<cache>((/* select#3 */ select `test`.`t31`.`e` from `test`.`t3` `t31`)) < `test`.`t32`.`e`) or isnull(`test`.`t32`.`e`)), true)) having <if>(outer_field_is_not_null, <is_not_null_test>(`test`.`t32`.`e`), true))))",
"attached_subqueries": [
{
"dependent": true,
"cacheable": false,
"query_block": {
"select_id": ,
"table": {
"table_name": "t32",
"access_type": "ALL",
"rows": ,
"filtered": ,
"attached_condition": "(`test`.`t1`.`b` and <if>(outer_field_is_not_null, ((<cache>((/* select#3 */ select `test`.`t31`.`e` from `test`.`t3` `t31`)) < `test`.`t32`.`e`) or isnull(`test`.`t32`.`e`)), true))"
}
}
},
{
"dependent": false,
"cacheable": true,
"query_block": {
"select_id": ,
"table": {
"table_name": "t31",
"access_type": "ALL",
"rows": ,
"filtered":
}
}
}
]
}
},
{
"table": {
"table_name": "t2",
"access_type": "ALL",
"rows": ,
"filtered": ,
"first_match": "t1",
"using_join_buffer": "Block Nested Loop",
"attached_condition": "(`test`.`t2`.`c` = `test`.`t1`.`a`)"
}
}
]
}
}
row in set, warnings (0.00 sec)
mysql> SHOW WARNINGS\G
*************************** . row ***************************
Level: Note
Code:
Message: Field or reference 'test.t1.b' of SELECT # was resolved in SELECT #
*************************** . row ***************************
Level: Note
Code:
Message: /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` semi join (`test`.`t2`) where ((`test`.`t2`.`c` = `test`.`t1`.`a`) and <nop>(<in_optimizer>((/* select#3 */ select `test`.`t31`.`e` from `test`.`t3` `t31`),<exists>(/* select#4 */ select from `test`.`t3` `t32` where (`test`.`t1`.`b` and <if>(outer_field_is_not_null, ((<cache>((/* select#3 */ select `test`.`t31`.`e` from `test`.`t3` `t31`)) < `test`.`t32`.`e`) or isnull(`test`.`t32`.`e`)), true)) having <if>(outer_field_is_not_null, <is_not_null_test>(`test`.`t32`.`e`), true)))))
rows in set (0.00 sec)

DEPENDENT SUBQUERY” 和 “SUBQUERY”的更多相关文章

  1. [慢查优化]慎用MySQL子查询,尤其是看到DEPENDENT SUBQUERY标记时

    案例梳理时间:2013-9-25 写在前面的话: 在慢查优化1和2里都反复强调过 explain 的重要性,但有时候肉眼看不出 explain 结果如何指导优化,这时候还需要有一些其他基础知识的佐助, ...

  2. 看懂mysql执行计划--官方文档

    原文地址:https://dev.mysql.com/doc/refman/5.7/en/explain-output.html 9.8.2 EXPLAIN Output Format The EXP ...

  3. [MySQL Reference Manual] 8 优化

    8.优化 8.优化 8.1 优化概述 8.2 优化SQL语句 8.2.1 优化SELECT语句 8.2.1.1 SELECT语句的速度 8.2.1.2 WHERE子句优化 8.2.1.3 Range优 ...

  4. Mysql DOC阅读笔记

    Mysql DOC阅读笔记 转自我的Github Speed of SELECT Statements 合理利用索引 隔离调试查询中花费高的部分,例如函数调用是在结果集中的行执行还是全表中的行执行 最 ...

  5. MySQL库表状态查询

    一. 查看库的各链接状态 对于一个mysql连接或者一个线程,任何时刻都有一个状态,表示其当前正在做什么.一般使用show full processlist查看. +---------+------- ...

  6. 【mysql】mysql 调优之 ——执行计划 explain

    1.what is explain(explain 是个什么东东) explain(解释),在 Mysql 中 作为一个关键词,用来解释 Mysql 是如何执行语句,可以连接 select .dele ...

  7. Mysql的性能优化

    1.参考书籍:MYSQL 5.5从零开始学 Mysql性能优化就算通过合理安排资源,调整系统参数使MYSQL运行更快,更节省资源.MYSQL性能优化包括查询速度优化,更新速度优化,mysql服务器优化 ...

  8. oracle已知会导致错误结果的bug列表(Bug Issues Known to cause Wrong Results)

    LAST UPDATE:     1 Dec 15, 2016 APPLIES TO:     1 2 3 4 Oracle Database - Enterprise Edition - Versi ...

  9. MySQL优化之Explain命令解读,optimizer_trace

    简述: explain为mysql提供语句的执行计划信息.可以应用在select.delete.insert.update和place语句上.explain的执行计划,只是作为语句执行过程的一个参考, ...

随机推荐

  1. Android中通过typeface设置字体

    Android系统默认支持三种字体,分别为:“sans”, “serif”, “monospace",除此之外还可以使用其他字体文件(*.ttf)方法一:XML中使用android默认字体 ...

  2. Laravel框架——任务调度(cron)

    准备: 在服务的/var/spool/cron/root文件中添加代码 cd /var/spool/cron/root 添加以下代码 * * * * * phppath 项目路径/artisan sc ...

  3. OpenCV for c++Builder

    整理日: 20154/6 Borland C++BuilderでOpenCVを使う 確認 Turbo C++ 2007/03 1. ダウンロード&インストール http://sourcefor ...

  4. webserver<1>

    1. 实现基础的信号处理 sigaction使用前一定内存清零 2. 实现基础的进程模型 wait 等待子进程结束 #include <stdio.h> #include <unis ...

  5. seajs 和spm的使用简介

    说实话, 前端开发是一个令人头痛的事情. nodejs出现了很久了, 一直不是很习惯用nodejs, 当初刚出来的时候, 就下载了express, 想搭建个网站, 结果不是我的菜, 愣是用的不习惯,也 ...

  6. bzoj 2594: [Wc2006]水管局长数据加强版 动态树

    2594: [Wc2006]水管局长数据加强版 Time Limit: 25 Sec  Memory Limit: 128 MBSubmit: 934  Solved: 291[Submit][Sta ...

  7. bzoj 1406: [AHOI2007]密码箱 二次剩餘

    1406: [AHOI2007]密码箱 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 701  Solved: 396[Submit][Status] D ...

  8. 【技术贴】解决xp下Microsoft.SqlServer.Management.PSProvider.dll

    解决 安装SQLserver2008时有出错信息,提示:Configuration error description: 无法获得 C:\Program Files\Microsoft SQL Ser ...

  9. LA 3882

    动态规划: 白书上的题,看了好久看不懂刘汝佳的解法: 在网上无意中看到了大神的思路,比较好理解,膜拜! 他的思路是这样的: 设d[i]是n个数按顺时针方向分别从0开始编号,第一次删除0,以后每k个数删 ...

  10. win7电脑自动关机怎么设置

    WIN7系统自带了关机工具的,下面是步骤 1.“开始”-右键点击“计算机”选择“管理”,在左侧界面中选择“任务计划程序”. 2.在右侧界面中选择“创建基本任务”(向导式创建任务,推荐新手使用)或者“创 ...