最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

MySql性能调优利器之Explain

来源:动视网 责编:小采 时间:2020-11-09 07:38:01
文档

MySql性能调优利器之Explain

MySql性能调优利器之Explain:Mysql Explain 详解 一.语法 explain table_name 例如: explain select * from t3 where id=3952602; 二.explain输出解释 +—-+————-+——-+——-+——————-+———+———+——-+——+——-+ | id | select_type |
推荐度:
导读MySql性能调优利器之Explain:Mysql Explain 详解 一.语法 explain table_name 例如: explain select * from t3 where id=3952602; 二.explain输出解释 +—-+————-+——-+——-+——————-+———+———+——-+——+——-+ | id | select_type |


Mysql Explain 详解 一.语法 explain table_name 例如: explain select * from t3 where id=3952602; 二.explain输出解释 +—-+————-+——-+——-+——————-+———+———+——-+——+——-+ | id | select_type | table | type | possible_keys |

Mysql Explain 详解

一.语法

explain < table_name >

例如: explain select * from t3 where id=3952602;

二.explain输出解释

+—-+————-+——-+——-+——————-+———+———+——-+——+——-+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+—-+————-+——-+——-+——————-+———+———+——-+——+——-+

1.id
我的理解是SQL执行的顺利的标识,SQL从大到小的执行.

例如:
mysql> explain select * from (select * from ( select * from t3 where id=3952602) a) b;
+—-+————-+————+——–+——————-+———+———+——+——+——-+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+—-+————-+————+——–+——————-+———+———+——+——+——-+
| 1 | PRIMARY | | system | NULL | NULL | NULL | NULL | 1 | |
| 2 | DERIVED | | system | NULL | NULL | NULL | NULL | 1 | |
| 3 | DERIVED | t3 | const | PRIMARY,idx_t3_id | PRIMARY | 4 | | 1 | |
+—-+————-+————+——–+——————-+———+———+——+——+——-+

很显然这条SQL是从里向外的执行,就是从id=3 向上执行.

  1. select_type

就是select类型,可以有以下几种

(1) SIMPLE
简单SELECT(不使用UNION或子查询等) 例如:
mysql> explain select * from t3 where id=3952602;
+—-+————-+——-+——-+——————-+———+———+——-+——+——-+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+—-+————-+——-+——-+——————-+———+———+——-+——+——-+
| 1 | SIMPLE | t3 | const | PRIMARY,idx_t3_id | PRIMARY | 4 | const | 1 | |
+—-+————-+——-+——-+——————-+———+———+——-+——+——-+

(2). PRIMARY

我的理解是最外层的select.例如:

mysql> explain select * from (select * from t3 where id=3952602) a ;
+—-+————-+————+——–+——————-+———+———+——+——+——-+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+—-+————-+————+——–+——————-+———+———+——+——+——-+
| 1 | PRIMARY | | system | NULL | NULL | NULL | NULL | 1 | |
| 2 | DERIVED | t3 | const | PRIMARY,idx_t3_id | PRIMARY | 4 | | 1 | |
+—-+————-+————+——–+——————-+———+———+——+——+——-+

(3).UNION

UNION中的第二个或后面的SELECT语句.例如
mysql> explain select * from t3 where id=3952602 union all select * from t3 ;
+—-+————–+————+——-+——————-+———+———+——-+——+——-+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+—-+————–+————+——-+——————-+———+———+——-+——+——-+
| 1 | PRIMARY | t3 | const | PRIMARY,idx_t3_id | PRIMARY | 4 | const | 1 | |
| 2 | UNION | t3 | ALL | NULL | NULL | NULL | NULL | 1000 | |
|NULL | UNION RESULT |

文档

MySql性能调优利器之Explain

MySql性能调优利器之Explain:Mysql Explain 详解 一.语法 explain table_name 例如: explain select * from t3 where id=3952602; 二.explain输出解释 +—-+————-+——-+——-+——————-+———+———+——-+——+——-+ | id | select_type |
推荐度:
标签: mysql 性能 优化
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top