mysql执行计划分析

本实验employees数据库从https://launchpad.net/test-db/下载

1.id列

若一个select语句中要连接多个数据表,执行计划会根据连接的表数进行显示,并赋予相同的id。下面示例只有一个select语句,但连接多个表,此时id值不会增加,拥有相同id:

root@localhost:mysql3316.sock  11:58:51 [employees]>explain extended select e.emp_no,e.first_name,s.from_date,s.salary from employees e,salaries s where e.emp_no=s.emp_no limit 10;
+----+-------------+-------+------+----------------+---------+---------+--------------------+--------+----------+-------+
| id | select_type | table | type | possible_keys  | key     | key_len | ref                | rows   | filtered | Extra |
+----+-------------+-------+------+----------------+---------+---------+--------------------+--------+----------+-------+
|  1 | SIMPLE      | e     | ALL  | PRIMARY        | NULL    | NULL    | NULL               | 299290 |   100.00 | NULL  |
|  1 | SIMPLE      | s     | ref  | PRIMARY,emp_no | PRIMARY | 4       | employees.e.emp_no |      4 |   100.00 | NULL  |
+----+-------------+-------+------+----------------+---------+---------+--------------------+--------+----------+-------+
2 rows in set, 1 warning (0.00 sec)

相反,下列查询执行计划中,整个查询语句由3个select语句组成,所以执行计划的各记录拥有不同id值:

root@localhost:mysql3316.sock  12:12:35 [employees]>explain select( (select count(*) from employees) + (select count(*) from departments) ) as total_count;
+----+-------------+-------------+-------+---------------+-----------+---------+------+--------+----------------+
| id | select_type | table       | type  | possible_keys | key       | key_len | ref  | rows   | Extra          |
+----+-------------+-------------+-------+---------------+-----------+---------+------+--------+----------------+
|  1 | PRIMARY     | NULL        | NULL  | NULL          | NULL      | NULL    | NULL |   NULL | No tables used |
|  3 | SUBQUERY    | departments | index | NULL          | dept_name | 122     | NULL |      9 | Using index    |
|  2 | SUBQUERY    | employees   | index | NULL          | PRIMARY   | 4       | NULL | 299290 | Using index    |
+----+-------------+-------------+-------+---------------+-----------+---------+------+--------+----------------+
3 rows in set (0.00 sec)
时间: 2024-11-05 18:31:11

mysql执行计划分析的相关文章

mysql 执行计划分析三看, explain,profiling,optimizer_trace

http://blog.csdn.net/xj626852095/article/details/52767963 step 1 使用explain 查看执行计划, 5.6后可以加参数 explain format=json xxx 输出json格式的信息 step 2  使用profiling详细的列出在每一个步骤消耗的时间,前提是先执行一遍语句. #打开profiling 的设置 SET profiling = 1; SHOW VARIABLES LIKE '%profiling%'; #查

【转】MySQL执行计划分析

原文:http://www.cnblogs.com/wangyanhong/archive/2013/09/18/3327919.html 一.语法explain <sql语句>例如: explain select * from t3 where id=3952602; 二.explain输出解释 +----+-------------+-------+-------+-------------------+---------+---------+-------+------+-------+

MySQL执行计划复习

MySQL执行计划分析 Ⅰ.认识执行计划的每个字段 ([email protected]) [(none)]> desc select 1; +----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+----------------+ | id | select_type | table | partitions | type | possib

MySQL学习系列2--MySQL执行计划分析EXPLAIN

1.Explain语法 EXPLAIN SELECT -- 变体:   EXPLAIN EXTENDED SELECT -- 将执行计划"反编译"成SELECT语句,运行SHOW WARNINGS 可得到被MySQL优化器优化后的查询语句 2.执行计划分析和实例 创建员工表Employee create table Employee ( ID int auto_increment, Ename varchar(32), Age int, Salary float, MID int, P

MySQL执行计划 EXPLAIN参数

MySQL执行计划参数详解 转http://www.jianshu.com/p/7134286b3a09 MySQL数据库中,在SELECT查询语句前边加上“EXPLAIN”或者“DESC”关键字,即可查看该查询语句的执行计划,分析执行计划是优化慢查询的重要手段.如: EXPLAIN SELECT * FROM school; DESC SELECT * FROM school; 执行结果: 执行计划参数.png 接下来对这10个参数进行简单解释: 1.id:在整个查询中SELECT的位置: 2

MySQL执行计划显示与执行过程不符合一例

一 建表和现象的过程如下 CREATE TABLE t1 (id1 INT, a1 INT, b1 INT, PRIMARY KEY(id1));CREATE TABLE t3 (id3 INT UNIQUE, a3 INT, b3 INT); INSERT INTO t1 VALUES (1, 1, NULL);INSERT INTO t3 VALUES (1, 1, NULL); mysql> select * from (select * from t1 where id1 =(selec

MongoDB执行计划分析详解(1)

正文 queryPlanner queryPlanner是现版本explain的默认模式,queryPlanner模式下并不会去真正进行query语句查询,而是针对query语句进行执行计划分析并选出winning plan. { "queryPlanner" : { "plannerVersion" : 1, "namespace" : "game_db.game_user", "indexFilterSet&qu

MySQL执行计划解读

MySQL执行计划解读 http://www.cnblogs.com/ggjucheng/archive/2012/11/11/2765237.html MySQL执行计划解读 Explain语法 EXPLAIN SELECT -- 变体: 1. EXPLAIN EXTENDED SELECT -- 将执行计划"反编译"成SELECT语句,运行SHOW WARNINGS 可得到被MySQL优化器优化后的查询语句 2. EXPLAIN PARTITIONS SELECT -- 用于分区表

MySQL执行计划解读 转他人文章

Explain语法 EXPLAIN SELECT …… 变体: 1. EXPLAIN EXTENDED SELECT …… 将执行计划“反编译”成SELECT语句,运行SHOW WARNINGS 可得到被MySQL优化器优化后的查询语句 2. EXPLAIN PARTITIONS SELECT …… 用于分区表的EXPLAIN 执行计划包含的信息 id 包含一组数字,表示查询中执行select子句或操作表的顺序 id相同,执行顺序由上至下 如果是子查询,id的序号会递增,id值越大优先级越高,越