暂无图片
explain中的几个疑问?
我来答
分享
暂无图片 匿名用户
explain中的几个疑问?

mysql> ANALYZE TABLE t1;
+---------+---------+----------+----------+
| Table | Op | Msg_type | Msg_text |
+---------+---------+----------+----------+
| test.t1 | analyze | status | OK |
+---------+---------+----------+----------+
1 row in set (0.08 sec)

mysql> select count(*) from t1 where f2>40;
+----------+
| count(*) |
+----------+
| 80 |
+----------+
1 row in set (0.00 sec)

mysql> EXPLAIN SELECT f1, f2 FROM t1 WHERE f2 > 40;
+----+-------------+-------+------------+-------+---------------+---------+---------+------+------+----------+----------------------------------------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+----+-------------+-------+------------+-------+---------------+---------+---------+------+------+----------+----------------------------------------+
| 1 | SIMPLE | t1 | NULL | range | PRIMARY | PRIMARY | 8 | NULL | 53 | 100.00 | Using where; Using index for skip scan 


统计信息已经是最新的了,明明是80,explain中的rows =53,怎么理解?

2:filtered =100,怎么理解?

3:mysql中的explain应该是假跑的,怎么获取真实的跑sql的执行计划呢??

我来答
添加附件
收藏
分享
问题补充
2条回答
默认
最新
大大刺猬
  1. analyze收集的统计信息, 只是个估计值, 不是真实值. 收集统计信息一般是采样, 采样越多越准确, 但是越慢(oracle里面为estimate_percent), mysql里面为innodb_stats_persistent_sample_pages(默认20,单位PAGE)
  2. 对于explain中各字段是啥意思, 建议看官网https://dev.mysql.com/doc/refman/5.7/en/explain-output.html
  3. 觉得explain不准的话, 可以使用PROFILE. 还是看官网. 注意profile是看实际执行的结果, 如果要看delete/update的话, 建议开启事务. 不然数据就真滴变了: https://dev.mysql.com/doc/refman/5.7/en/show-profile.html
  4. 没事多看看官网…
暂无图片 评论
暂无图片 有用 0
chengang

我补充两点
1、关于filtered的理解可以看这一篇大佬写的文章
https://www.jianshu.com/p/e70de1f7cdcf
2、explain for CONNECTION 可以看正在执行的执行计划

暂无图片 评论
暂无图片 有用 0
回答交流
提交
问题信息
请登录之后查看
邀请回答
暂无人订阅该标签,敬请期待~~
暂无图片墨值悬赏