使用explain查询select查询语句执行计划
2016-12-14 09:35
639 查看
1.使用explain查询select查询语句执行计划
mysql> select * from baba where name ='fjdsjf';
+------+--------+
| id | name |
+------+--------+
| 1 | fjdsjf |
+------+--------+
查询该sql语句的执行计划
mysql> explain select * from baba where name ='fjdsjf' \G;
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: baba
type: ALL
possible_keys: NULL
key: NULL
key_len: NULL
ref: NULL
rows: 2
Extra: Using where
1 row in set (0.00 sec) //该条sql语句没有走索引
增加索引:
mysql> create index index_baba on baba(name);
Query OK, 2 rows affected (0.09 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> desc baba;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| name | varchar(30) | YES | MUL | NULL | |
+-------+-------------+------+-----+---------+-------+
mysql> explain select * from baba where name ='fjdsjf' \G;
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: baba
type: ref
possible_keys: index_baba
key: index_baba
key_len: 33
ref: const
rows: 1 //搜索到一行,就找到所
Extra: Using where
2. 学会使用执行计划帮助
mysql> help explain
Name: 'EXPLAIN'
Description:
Syntax:
EXPLAIN [explain_type] SELECT select_options
explain_type:
EXTENDED
| PARTITIONS
Or:
EXPLAIN tbl_name
The EXPLAIN statement can be used either as a way to obtain information
about how MySQL executes a statement, or as a synonym for DESCRIBE:
o When you precede a SELECT statement with the keyword EXPLAIN, MySQL
displays information from the optimizer about the query execution
plan. That is, MySQL explains how it would process the statement,
including information about how tables are joined and in which order.
EXPLAIN EXTENDED can be used to obtain additional information.
For information about using EXPLAIN and EXPLAIN EXTENDED to obtain
query execution plan information, see http://dev.mysql.com/doc/refman/5.1/en/using-explain.html.
mysql> select * from baba where name ='fjdsjf';
+------+--------+
| id | name |
+------+--------+
| 1 | fjdsjf |
+------+--------+
查询该sql语句的执行计划
mysql> explain select * from baba where name ='fjdsjf' \G;
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: baba
type: ALL
possible_keys: NULL
key: NULL
key_len: NULL
ref: NULL
rows: 2
Extra: Using where
1 row in set (0.00 sec) //该条sql语句没有走索引
增加索引:
mysql> create index index_baba on baba(name);
Query OK, 2 rows affected (0.09 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> desc baba;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| name | varchar(30) | YES | MUL | NULL | |
+-------+-------------+------+-----+---------+-------+
mysql> explain select * from baba where name ='fjdsjf' \G;
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: baba
type: ref
possible_keys: index_baba
key: index_baba
key_len: 33
ref: const
rows: 1 //搜索到一行,就找到所
Extra: Using where
2. 学会使用执行计划帮助
mysql> help explain
Name: 'EXPLAIN'
Description:
Syntax:
EXPLAIN [explain_type] SELECT select_options
explain_type:
EXTENDED
| PARTITIONS
Or:
EXPLAIN tbl_name
The EXPLAIN statement can be used either as a way to obtain information
about how MySQL executes a statement, or as a synonym for DESCRIBE:
o When you precede a SELECT statement with the keyword EXPLAIN, MySQL
displays information from the optimizer about the query execution
plan. That is, MySQL explains how it would process the statement,
including information about how tables are joined and in which order.
EXPLAIN EXTENDED can be used to obtain additional information.
For information about using EXPLAIN and EXPLAIN EXTENDED to obtain
query execution plan information, see http://dev.mysql.com/doc/refman/5.1/en/using-explain.html.
相关文章推荐
- 如何使用SQLPLUS分析SQL语句(查询执行计划跟踪)
- 强制SQL Server执行计划使用并行提升在复杂查询语句下的性能
- 在MySQL中使用explain查询SQL的执行计划
- MySQL通过Explain查看select语句的执行计划结果触发写操作
- 如何使用SQLPLUS分析SQL语句(查询执行计划跟踪)
- 如何使用SQLPLUS分析SQL语句(查询执行计划跟踪)
- MySql中如何使用 explain 查询 SQL 的执行计划
- 强制SQL Server执行计划使用并行提升在复杂查询语句下的性能
- 如何使用SQLPLUS分析SQL语句(查询执行计划跟踪)
- 强制SQL Server执行计划使用并行提升在复杂查询语句下的性能
- MYSQL 用 explain 语句判断select查询是否使用了索引
- explain、db2exfmt 命令的使用:文本输出执行计划
- 使用SAPCommand查询SAP表的SELECT语句
- ORCLE-Select 语句执行顺序以及如何提高Oracle 基本查询效率
- 使用in关键字来限制SQL语句中的select查询结果
- 怎样看oracle查询语句执行计划
- ORACLE-Select语句执行顺序及如何提高Oracle 基本查询效率
- ORCLE-Select 语句执行顺序以及如何提高Oracle 基本查询效率
- php中使用mysql_stmt(预处理语句)来处理select查询结果
- 应用程序对Sqlserver进行SQL查询使用与不使用参数对执行计划的影响