Mysql 执行计划分析
zjdev 正常访问; mysql> explain SELECT temp.* ,
-> (SELECT COUNT(sn) FROM AssignClientManager WHERE FIND_IN_SET(clientManagerSn,temp.managerSnlist)>0) clientAccount,
-> (SELECT
-> IFNULL(SUM(capitalBalance), 0) + IFNULL(SUM(yieldBalance), 0)
-> FROM
-> ProductRepayment pr ,ProductRepay p
-> WHERE
-> pr.productSn = p.productSn AND
-> pr.clientSn IN (SELECT clientSn FROM AssignClientManager WHERE FIND_IN_SET(clientManagerSn,temp.managerSnlist)>0 )
-> AND pr.status = 1 AND DATEDIFF(p.realValueEndDate,CURDATE()) <=7 AND DATEDIFF(p.realValueEndDate,CURDATE())>=0
-> ) investBalance,
-> (SELECT
-> IFNULL(SUM(capitalBalance), 0) + IFNULL(SUM(yieldBalance), 0) + temp.availableBalance + temp.frozenWithDraw + temp.frozenPay
-> FROM
-> ProductRepayment
-> WHERE
-> clientSn = temp.sn IN (SELECT clientSn FROM AssignClientManager WHERE FIND_IN_SET(clientManagerSn,temp.managerSnlist)>0 )
-> AND STATUS = 1) totalBalance,
-> (SELECT
-> IFNULL(SUM(capitalBalance), 0) + IFNULL(SUM(yieldBalance), 0)
-> FROM
-> ProductRepayment pr
-> WHERE
-> pr.clientSn IN (SELECT clientSn FROM AssignClientManager WHERE FIND_IN_SET(clientManagerSn,temp.managerSnlist)>0 ) AND pr.status =1
-> ) unclearedBalance
-> FROM(
-> SELECT c.sn,cm.`parent`,c.`mobilePhone`,c.`userNick`,cp.`personName`,loadTreeByParent(cm.sn) AS managerSnlist,
-> cai.`availableBalance`,cai.`frozenWithDraw`,cai.`frozenPay`
-> FROM `Client` c
-> LEFT JOIN ClientManager cm ON c.`sn` = cm.`sn`
-> LEFT JOIN ClientPersonalInfo cp ON cp.`clientSn` = c.`sn`
-> LEFT JOIN ClientAssetInfo cai ON cai.`clientSn` = c.`sn`
-> WHERE cm.parent = 1496 ) temp
-> ;
+----+--------------------+---------------------+--------+---------------+---------+---------+-------------------+------+-------------------------------------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+--------------------+---------------------+--------+---------------+---------+---------+-------------------+------+-------------------------------------------------------------------+
| 1 | PRIMARY | <derived9> | ALL | NULL | NULL | NULL | NULL | 56 | NULL |
| 9 | DERIVED | cm | ALL | PRIMARY | NULL | NULL | NULL | 56 | Using where |
| 9 | DERIVED | c | eq_ref | PRIMARY | PRIMARY | 4 | zjzc.cm.sn | 1 | NULL |
| 9 | DERIVED | cp | eq_ref | PRIMARY | PRIMARY | 4 | zjzc.cm.sn | 1 | NULL |
| 9 | DERIVED | cai | eq_ref | PRIMARY | PRIMARY | 4 | zjzc.cm.sn | 1 | NULL |
| 7 | DEPENDENT SUBQUERY | AssignClientManager | ALL | NULL | NULL | NULL | NULL | 2126 | Using where; Start temporary |
| 7 | DEPENDENT SUBQUERY | pr | ALL | NULL | NULL | NULL | NULL | 5699 | Using where; End temporary; Using join buffer (Block Nested Loop) |
| 5 | DEPENDENT SUBQUERY | ProductRepayment | ALL | NULL | NULL | NULL | NULL | 5699 | Using where |
| 6 | DEPENDENT SUBQUERY | AssignClientManager | ALL | NULL | NULL | NULL | NULL | 2126 | Using where |
| 3 | DEPENDENT SUBQUERY | pr | ALL | NULL | NULL | NULL | NULL | 5699 | Using where |
| 3 | DEPENDENT SUBQUERY | p | eq_ref | PRIMARY | PRIMARY | 4 | zjzc.pr.productSn | 1 | Using where |
| 3 | DEPENDENT SUBQUERY | AssignClientManager | ALL | NULL | NULL | NULL | NULL | 2126 | Using where; FirstMatch(p); Using join buffer (Block Nested Loop) |
| 2 | DEPENDENT SUBQUERY | AssignClientManager | ALL | NULL | NULL | NULL | NULL | 2126 | Using where |
+----+--------------------+---------------------+--------+---------------+---------+---------+-------------------+------+-------------------------------------------------------------------+
13 rows in set (0.00 sec) mysql select_type : <derived9> 派生表 DERIVED:被驱动的SELECT子查询(子查询位于FROM子句) DEPENDENT SUBQUERY:子查询中首个SELECT,但依赖于外层的表(如果有多个子查询存在) +----+--------------------+---------------------+------------+--------+---------------+---------+---------+-------------------+------+----------+--------------------------------------------------------------------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+----+--------------------+---------------------+------------+--------+---------------+---------+---------+-------------------+------+----------+--------------------------------------------------------------------+
| 1 | PRIMARY | cm | NULL | ALL | PRIMARY | NULL | NULL | NULL | 92 | 10.00 | Using where |
| 1 | PRIMARY | c | NULL | eq_ref | PRIMARY | PRIMARY | 4 | zjzc.cm.sn | 1 | 100.00 | NULL |
| 1 | PRIMARY | cp | NULL | eq_ref | PRIMARY | PRIMARY | 4 | zjzc.cm.sn | 1 | 100.00 | NULL |
| 1 | PRIMARY | cai | NULL | eq_ref | PRIMARY | PRIMARY | 4 | zjzc.cm.sn | 1 | 100.00 | NULL |
| 7 | DEPENDENT SUBQUERY | pr | NULL | ALL | NULL | NULL | NULL | NULL | 7559 | 10.00 | Using where |
| 7 | DEPENDENT SUBQUERY | AssignClientManager | NULL | ALL | NULL | NULL | NULL | NULL | 2817 | 10.00 | Using where; FirstMatch(pr); Using join buffer (Block Nested Loop) |
| 5 | DEPENDENT SUBQUERY | ProductRepayment | NULL | ALL | NULL | NULL | NULL | NULL | 7559 | 1.00 | Using where |
| 6 | DEPENDENT SUBQUERY | AssignClientManager | NULL | ALL | NULL | NULL | NULL | NULL | 2817 | 10.00 | Using where |
| 3 | DEPENDENT SUBQUERY | pr | NULL | ALL | NULL | NULL | NULL | NULL | 7559 | 10.00 | Using where |
| 3 | DEPENDENT SUBQUERY | p | NULL | eq_ref | PRIMARY | PRIMARY | 4 | zjzc.pr.productSn | 1 | 100.00 | Using where |
| 3 | DEPENDENT SUBQUERY | AssignClientManager | NULL | ALL | NULL | NULL | NULL | NULL | 2817 | 10.00 | Using where; FirstMatch(p); Using join buffer (Block Nested Loop) |
| 2 | DEPENDENT SUBQUERY | AssignClientManager | NULL | ALL | NULL | NULL | NULL | NULL | 2817 | 100.00 | Using where |
+----+--------------------+---------------------+------------+--------+---------------+---------+---------+-------------------+------+----------+--------------------------------------------------------------------+ mysql> explain SELECT temp.* ,
-> (SELECT COUNT(sn) FROM AssignClientManager WHERE FIND_IN_SET(clientManagerSn,temp.managerSnlist)>0) clientAccount
->
->
-> FROM (
-> SELECT c.sn,cm.`parent`,c.`mobilePhone`,c.`userNick`,cp.`personName`,loadTreeByParent(cm.sn) AS managerSnlist,
-> cai.`availableBalance`,cai.`frozenWithDraw`,cai.`frozenPay`
-> FROM `Client` c
-> LEFT JOIN ClientManager cm ON c.`sn` = cm.`sn`
-> LEFT JOIN ClientPersonalInfo cp ON cp.`clientSn` = c.`sn`
-> LEFT JOIN ClientAssetInfo cai ON cai.`clientSn` = c.`sn`
-> WHERE cm.parent = 1496 ) temp
-> ;
+----+--------------------+---------------------+------------+--------+---------------+---------+---------+------------+------+----------+-------------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+----+--------------------+---------------------+------------+--------+---------------+---------+---------+------------+------+----------+-------------+
| 1 | PRIMARY | cm | NULL | ALL | PRIMARY | NULL | NULL | NULL | 92 | 10.00 | Using where |
| 1 | PRIMARY | c | NULL | eq_ref | PRIMARY | PRIMARY | 4 | zjzc.cm.sn | 1 | 100.00 | NULL |
| 1 | PRIMARY | cp | NULL | eq_ref | PRIMARY | PRIMARY | 4 | zjzc.cm.sn | 1 | 100.00 | NULL |
| 1 | PRIMARY | cai | NULL | eq_ref | PRIMARY | PRIMARY | 4 | zjzc.cm.sn | 1 | 100.00 | NULL |
| 2 | DEPENDENT SUBQUERY | AssignClientManager | NULL | ALL | NULL | NULL | NULL | NULL | 2817 | 100.00 | Using where |
+----+--------------------+---------------------+------------+--------+---------------+---------+---------+------------+------+----------+-------------+
5 rows in set, 2 warnings (0.02 sec) DEPENDENT SUBQUERY | AssignClientManager 表示依赖子查询 所以这里是1驱动2 type ALL
全表扫描,MySQL 从头到尾扫描整张表查找行。 mysql> explain SELECT temp.* ,
-> (SELECT COUNT(sn) FROM AssignClientManager WHERE FIND_IN_SET(clientManagerSn,temp.managerSnlist)>0) clientAccount
->
->
-> FROM (
-> SELECT c.sn,cm.`parent`,c.`mobilePhone`,c.`userNick`,cp.`personName`,loadTreeByParent(cm.sn) AS managerSnlist,
-> cai.`availableBalance`,cai.`frozenWithDraw`,cai.`frozenPay`
-> FROM `Client` c
-> LEFT JOIN ClientManager cm ON c.`sn` = cm.`sn`
-> LEFT JOIN ClientPersonalInfo cp ON cp.`clientSn` = c.`sn`
-> LEFT JOIN ClientAssetInfo cai ON cai.`clientSn` = c.`sn`
-> WHERE cm.parent = 1496 ) temp
-> ;
+----+--------------------+---------------------+--------+---------------+---------+---------+------------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+--------------------+---------------------+--------+---------------+---------+---------+------------+------+-------------+
| 1 | PRIMARY | <derived3> | ALL | NULL | NULL | NULL | NULL | 56 | NULL |
| 3 | DERIVED | cm | ALL | PRIMARY | NULL | NULL | NULL | 56 | Using where |
| 3 | DERIVED | c | eq_ref | PRIMARY | PRIMARY | 4 | zjzc.cm.sn | 1 | NULL |
| 3 | DERIVED | cp | eq_ref | PRIMARY | PRIMARY | 4 | zjzc.cm.sn | 1 | NULL |
| 3 | DERIVED | cai | eq_ref | PRIMARY | PRIMARY | 4 | zjzc.cm.sn | 1 | NULL |
| 2 | DEPENDENT SUBQUERY | AssignClientManager | ALL | NULL | NULL | NULL | NULL | 2126 | Using where |
+----+--------------------+---------------------+--------+---------------+---------+---------+------------+------+-------------+
6 rows in set (0.00 sec) 这里 DEPENDENT SUBQUERY | AssignClientManager 驱动表是3 id是一组数字,表示查询中执行select子句或操作表的顺序。 如果id相同,则执行顺序从上至下。 如果是子查询,id的序号会递增,id越大则优先级越高,越先会被执行。 id如果相同,则可以认为是一组,从上往下顺序执行,所有组中,id越高,优先级越高,越容易执行。 驱动表为ID=3 cm: cm,c,cp cai执行出来的结果 再去驱动2 id为3 出来的结果
就是1 <derived3> 指向3 表示 是3产生的派生表 mysql> explain SELECT COUNT(sn) FROM AssignClientManager where clientSn>5;
+----+-------------+---------------------+------------+------+---------------+------+---------+------+------+----------+-------------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+----+-------------+---------------------+------------+------+---------------+------+---------+------+------+----------+-------------+
| 1 | SIMPLE | AssignClientManager | NULL | ALL | NULL | NULL | NULL | NULL | 2817 | 33.33 | Using where |
+----+-------------+---------------------+------------+------+---------------+------+---------+------+------+----------+-------------+ type ALL
全表扫描,MySQL 从头到尾扫描整张表查找行。
Mysql 执行计划分析的更多相关文章
- MySQL执行计划分析
原文:MySQL执行计划分析 一. 执行计划能告诉我们什么? SQL如何使用索引 联接查询的执行顺序 查询扫描的数据函数 二. 执行计划中的内容 SQL执行计划的输出可能为多行,每一行代表对一个数据库 ...
- (转)mysql执行计划分析
转自:https://www.cnblogs.com/liu-ke/p/4432774.html MySQL执行计划解读 Explain语法 EXPLAIN SELECT …… 变体: 1. EX ...
- mysql 执行计划分析三看, explain,profiling,optimizer_trace
http://blog.csdn.net/xj626852095/article/details/52767963 step 1 使用explain 查看执行计划, 5.6后可以加参数 explain ...
- 【转】MySQL执行计划分析
原文:http://www.cnblogs.com/wangyanhong/archive/2013/09/18/3327919.html 一.语法explain <sql语句>例如: e ...
- MySQL执行计划复习
MySQL执行计划分析 Ⅰ.认识执行计划的每个字段 (root@localhost) [(none)]> desc select 1; +----+-------------+-------+- ...
- MySQL学习系列2--MySQL执行计划分析EXPLAIN
原文:MySQL学习系列2--MySQL执行计划分析EXPLAIN 1.Explain语法 EXPLAIN SELECT …… 变体: EXPLAIN EXTENDED SELECT …… 将执行 ...
- MySQL学习系列2--MySQL执行计划分析EXPLAIN [原创]
1.Explain语法 EXPLAIN SELECT …… 变体: EXPLAIN EXTENDED SELECT …… 将执行计划“反编译”成SELECT语句,运行SHOW WARNINGS 可 ...
- MySQL执行计划 EXPLAIN参数
MySQL执行计划参数详解 转http://www.jianshu.com/p/7134286b3a09 MySQL数据库中,在SELECT查询语句前边加上“EXPLAIN”或者“DESC”关键字,即 ...
- 查看Mysql执行计划
使用navicat查看mysql执行计划: 打开profile分析工具: 查看是否生效:show variable like ‘%profil%’; 查看进程:show processlist; 选择 ...
随机推荐
- java--String方法
String : 字符串类型 一.构造函数 String(byte[ ] bytes):通过byte数组构造字符串对象. String(char[ ] value):通过char数组构造字符串对象. ...
- Clojure学习02:语法
相比我们传统的 c ,java ,python ,javascript等,Clojure的语法比较特别,初一看,还可能会有些不适应. 本文来介绍下Clojure的语法特点. 一.表达式 所有的Cloj ...
- uva - Broken Keyboard (a.k.a. Beiju Text)(链表)
11988 - Broken Keyboard (a.k.a. Beiju Text) You’re typing a long text with a broken keyboard. Well i ...
- WPF-22:WPF绘制五角星改进版(增加半个五角星的绘制)-修改bug
之前用坐标画多边形的方法,绘制五角星.今天调试时发现当时写的时候有bug,修改一下. 原文: http://blog.csdn.net/yysyangyangyangshan/article/deta ...
- PLSQL Developer过期要注冊表
打开执行输入 regedit 打表注冊表 删除 HKEY_CURRENT_USER\Software\Allround Automations HKEY_CURRENT_USER\Software\M ...
- Fragment使用
当我们需要动态的多界面切换的时候,就需要将UI元素和Activity融合成一个模块.在2.3中我们一般通过各种Activity中进行跳转来实现多界面的跳转和单个界面动态改变.在4.0或以上系统中就可以 ...
- RadioButton控件
前台代码: <div> <asp:RadioButton ID="RadioButton1" runat="server" GroupName ...
- 七、Nginx学习笔记七Nginx的Web缓存服务
user www; worker_processes 1; error_log /usr/local/nginx/logs/error.log crit; pid /usr/local/nginx/l ...
- Homebrew 1.0.0 发布,MacOS 上的包管理器
神器,没有它不知道怎么用macos https://www.oschina.net/news/77367/homebrew-1-0-0
- mysql各版本区别
MySQL 的官网下载地址:http://www.mysql.com/downloads/ 在这个下载界面会有几个版本的选择. 1. MySQL Community Server 社区版本,开源免费, ...