mysql 获取真是执行计划_mysql 获取执行计划的方法

explain进行查看sql的执行计划相对简单,其实通线程正在执行的sql查看执行计划也很简单,那么为什么还需要第二种方式呢?

因为日常工作会发现很多sql一直在执行,执行发生异常,如果把该sql拿出来执行又很快,于是我们想获取该sql执行异常时候的执行计划,同时因为数据在时刻的变化,统计信息也有可能变化,有可能导致执行计划发生改变,好在mysql5.7开始已经可以通过正在执行的线程查看该sql的执行计划,不需要把sql拿出来执行获取执行计划,这样就可以很好的还原真相:

show processlist;或者select * from information_schema.PROCESSLIST where info is not null order by time desc ;查看。

mysql> select from information_schema.PROCESSLIST where info is not null;

+-----+------+-----------------+------+---------+------+--------------+-----------------------------------------------------------------------+

| ID | USER | HOST | DB | COMMAND | TIME | STATE | INFO |

+-----+------+-----------------+------+---------+------+--------------+-----------------------------------------------------------------------+

| 17 | root | localhost | NULL | Query | 0 | executing | select from information_schema.PROCESSLIST where info is not null |

| 178 | root | localhost:60124 | app1 | Query | 560 | Sending data | select count(*) from t ,t_adress where t.adress = t_adress.adress |

+-----+------+-----------------+------+---------+------+--------------+-----------------------------------------------------------------------+

2 rows in set (0.00 sec)

mysql> EXPLAIN FOR CONNECTION 178;

+----+-------------+----------+------------+------+---------------+------+---------+------+--------+----------+----------------------------------------------------+

| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |

+----+-------------+----------+------------+------+---------------+------+---------+------+--------+----------+----------------------------------------------------+

| 1 | SIMPLE | t_adress | NULL | ALL | NULL | NULL | NULL | NULL | 200096 | 100.00 | NULL |

| 1 | SIMPLE | t | NULL | ALL | NULL | NULL | NULL | NULL | 309664 | 100.00 | Using where; Using join buffer (Block Nested Loop) |

+----+-------------+----------+------------+------+---------------+------+---------+------+--------+----------+----------------------------------------------------+

2 rows in set (0.01 sec)

使用起来是不是很方便?

最后说一句:

今天心里很憋屈,睡觉了。。。。。。。。

原文:http://blog.51cto.com/1937519/2321552

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值