DEPENDENT SUBQUERY” 和 “SUBQUERY”
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”的更多相关文章
- [慢查优化]慎用MySQL子查询,尤其是看到DEPENDENT SUBQUERY标记时
案例梳理时间:2013-9-25 写在前面的话: 在慢查优化1和2里都反复强调过 explain 的重要性,但有时候肉眼看不出 explain 结果如何指导优化,这时候还需要有一些其他基础知识的佐助, ...
- 看懂mysql执行计划--官方文档
原文地址:https://dev.mysql.com/doc/refman/5.7/en/explain-output.html 9.8.2 EXPLAIN Output Format The EXP ...
- [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优 ...
- Mysql DOC阅读笔记
Mysql DOC阅读笔记 转自我的Github Speed of SELECT Statements 合理利用索引 隔离调试查询中花费高的部分,例如函数调用是在结果集中的行执行还是全表中的行执行 最 ...
- MySQL库表状态查询
一. 查看库的各链接状态 对于一个mysql连接或者一个线程,任何时刻都有一个状态,表示其当前正在做什么.一般使用show full processlist查看. +---------+------- ...
- 【mysql】mysql 调优之 ——执行计划 explain
1.what is explain(explain 是个什么东东) explain(解释),在 Mysql 中 作为一个关键词,用来解释 Mysql 是如何执行语句,可以连接 select .dele ...
- Mysql的性能优化
1.参考书籍:MYSQL 5.5从零开始学 Mysql性能优化就算通过合理安排资源,调整系统参数使MYSQL运行更快,更节省资源.MYSQL性能优化包括查询速度优化,更新速度优化,mysql服务器优化 ...
- 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 ...
- MySQL优化之Explain命令解读,optimizer_trace
简述: explain为mysql提供语句的执行计划信息.可以应用在select.delete.insert.update和place语句上.explain的执行计划,只是作为语句执行过程的一个参考, ...
随机推荐
- Google开源库-Volley
Android平台的网络通信库,使是网通信 更快,更简单,更健壮 适合场景: 数据量不大,通信 频繁. 大数据,流媒体是不适合使用的 * 它主要是帮我们载入和缓存从远程网络加载的图片 * 所有的 ...
- JS中的call、apply、bind方法
JS中的call.apply.bind方法 一.call()和apply()方法 1.方法定义 call方法: 语法:call([thisObj[,arg1[, arg2[, [,.argN]]] ...
- build tree
有二叉树的前序遍历和后序遍历,构造二叉树 /** * Definition for binary tree * public class TreeNode { * int val; * TreeNod ...
- 控制反转(IoC)与依赖注入(DI)
1.控制反转(Inversion of Control)与依赖注入(Dependency Injection) 控制反转即IoC (Inversion of Control),它把传统上由程序代码直接 ...
- jquery插件,美化select标签
最近经常与select打交道,因为ie下的select实在太丑了,css怎么搞都搞不好看,因为程序已经写得差不多了,要再去模拟select改动太大,就想着能否不改动select,同时美化它.借鉴一下这 ...
- UI设计师的 Android 备忘录
Images and themes Nine-patch Colors Holo themes Naming conventions Naming conventions for drawables ...
- Learn Objectvie-C on the Mac 2nd Edition 笔记
Chapter 1Apple’s Cocoa (for OS X) 和 Cocoa Touch (for iOS) toolkits 都是用 Objective-C写的. Chapter 2 (1) ...
- git入门超详细(转载)
转自:http://www.cnblogs.com/tugenhua0707/p/4050072.html Git使用教程 一:Git是什么? Git是目前世界上最先进的分布式版本控制系统. 二:SV ...
- JavaScript高级程序设计6.pdf
ECMAScript通过RegExp类型来支持正则表达式 var expression=/pattern/flags;其中模式(pattern)部分是正则表达式,可以包含字符类.限定符.分组.向前查找 ...
- [转]让程序在崩溃时体面的退出之Dump文件
原文地址:http://blog.csdn.net/starlee/article/details/6630816 在我的那篇<让程序在崩溃时体面的退出之CallStack>中提供了一个在 ...