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. mysql进阶1

    在我们用php处理数据的时候总会遇到些比较麻烦的事情,比如:两个二维数组,一个装的是文章分类表内容,一个装的是文章列表,有关联字段,完全等值,要求在列表文章的时候同时能在标题的前面显示栏目名称,此时循 ...

  2. 用vscode写博客和发布

    最近想开始写点博客什么的,然后看到在博客园注册了一个账号这么久,也没有写过文章,就想在博客园写点什么来刷个存在感,而且觉得用Markdown编辑器来写文章挺不错,但是博客园自带的Markdown编辑器 ...

  3. ruby 中文支持设置

    学习Ruby的过程中,对于于涉及中文的的代码的时候,需要添加如下代码在首行 # encoding: utf-8 或者EMAC写法 # -*- coding : utf-8 -*- 因为Ruby编译器会 ...

  4. 关于C# json转object时报错:XXXXXXXXXX需要标记“"”,但找到“XX”。

    使用的类:System.Runtime.Serialization.Json.DataContractJsonSerializer //MessagePackage 为要转成的类DataContrac ...

  5. Python处理XML

    在Python(以及其他编程语言)内有两种常见的方法处理XML:SAX(Simple API for XML)和DOM(Document Object Model,文档对象模型).SAX语法分析器读取 ...

  6. GBin1插件推荐之马可波罗(Marco Polo),jQuery的自动补齐插件 - Autocomplete Plugin

    让我们Google一下"jQuery autocomplete plugin"(jquery自动补齐插件).在过去的4年中,我已经Google了很多次这个组合了.然而结果并没有变化 ...

  7. jquery平滑滚动到锚点 一行代码

    $("html,body").animate({scrollTop: $("#box").offset().top}, 1000); $("#box& ...

  8. 转-Python optionParser模块的使用方法

    Python  有两个内建的模块用于处理命令行参数: 一个是  getopt,<Deep in python>一书中也有提到,只能简单处理 命令行参数: 另一个是  optparse,它功 ...

  9. 大整数相乘的C实现

    //之前有个测试这个题没做完,现在把它做完,通过这个程序可以对乘法了解更深刻.分析:运用整数乘法,当然进制越高越好,考虑到乘法不要越界,故考虑进制底数N应该满 //足,N^2<2^32次方.所以 ...

  10. lingo运筹学上机实验指导

    <运筹学上机实验指导>分为两个部分,第一部分12学时,是与运筹学理论课上机同步配套的4个实验(线性规划.灵敏度分析.运输问题与指派问题.最短路问题和背包问题)的Excel.LONGO和LI ...