8.8.2 EXPLAIN Output Format 优化输出格式

来源:互联网 发布:javo软件 编辑:程序博客网 时间:2024/04/28 13:39

8.8.2 EXPLAIN Output Format 优化输出格式

EXPLAIN 语句提供信息关于执行计划的信息:

EXPLAIN 返回一条记录的信息关于每个表用于SELECT 语句,

它列出了表的输出顺序 ,MySQL 会读取当处理SQL语句的时候。

MySQL 解决所有的关联使用一个嵌套循环算法,这意味着MySQL 从第一个表读取一条记录,

在第2个,第3个 表里找到匹配的记录。

当所有的表被处理,MySQL 输出选择的列和回溯通过表列表直到一个表被找到有更多的匹配的记录。

下一行从这个表读取,继续处理下一个表。

当使用EXTENDED 关键字, EXPLAIN 产生额外的信息可以通过SHOW WARNINGS 语句跟着EXPLAIN 语句查询

. EXPLAIN EXTENDED 也可以显示过滤的列,See Section 8.8.3, “EXPLAIN EXTENDED Output Format”.

注意:

你不能使用EXTENDED 和PARTITIONS 关键字结婚在同样的EXPLAIN 语句。

EXPLAIN Output Columns EXPLAIN 输出列

EXPLAIN Join Types EXPLAIN 关联类型

EXPLAIN Extra Information EXPLAIN 额外的信息

EXPLAIN Output Interpretation EXPLAIN 解释输出

EXPLAIN Output Columns EXPLAIN 输出列

这个章节描述EXPLAIN 产生的输出列, 稍后部分提供额外的信息关于类型和额外的列

EXPLAIN 的每行输出提供关于一个表的信息, 每行包含值的总结在Table 8.1, “EXPLAIN Output Columns”,

并在表中更详细的描述。列名在表的第一列显示,第2列提供了等效的属性名字。

Table 8.1 EXPLAIN Output Columns

Column JSON Name Meaning
id select_id The SELECT identifier
select_type None The SELECT type
table table_name The table for the output row
partitions partitions The matching partitions
type access_type The join type
possible_keys possible_keys The possible indexes to choose
key key The index actually chosen
key_len key_length The length of the chosen key
ref ref The columns compared to the index
rows rows Estimate of rows to be examined
filtered filtered Percentage of rows filtered by table condition
Extra None Additional information

mysql> explain SELECT cpi.personName, ccd.clientSn, ccd.income, ccd.pay, ccd.accountBalance, ccd.createdTime, ccd.remark from
-> (select * from ClientCashDetail ccd_int where
-> 1 >
-> (SELECT count(clientSn) from ClientCashDetail
-> where clientSn= ccd_int.clientSn and ccd_int.createdTime < createdTime and createdTime < TIMESTAMP(@dated_time) )
-> and ccd_int.createdTime < TIMESTAMP(@dated_time)
-> ) ccd
-> RIGHT JOIN ClientPersonalInfo cpi on cpi.clientSn = ccd.clientSn
-> where ccd.clientSn in (SELECT clientSn from ClientPersonalInfo where personName in (
-> ‘蔡明’,
-> ‘苑秀凤’,

-> ))  -> ORDER BY cpi.personName,  ccd.clientSn,  ccd.createdTime DESC;  

+—-+——————–+——————–+——–+—————+————-+———+——————-+——+———————————+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+—-+——————–+——————–+——–+—————+————-+———+——————-+——+———————————+
| 1 | PRIMARY | cpi | ALL | PRIMARY | NULL | NULL | NULL | 937 | Using temporary; Using filesort |
| 1 | PRIMARY | ClientPersonalInfo | eq_ref | PRIMARY | PRIMARY | 4 | zjzc.cpi.clientSn | 1 | Using where |
| 1 | PRIMARY | | ref | | | 4 | zjzc.cpi.clientSn | 10 | NULL |
| 2 | DERIVED | ccd_int | ALL | NULL | NULL | NULL | NULL | 5999 | Using where |
| 3 | DEPENDENT SUBQUERY | ClientCashDetail | ALL | NULL | NULL | NULL | NULL | 5999 | Using where |
+—-+——————–+——————–+——–+—————+————-+———+——————-+——+———————————+
5 rows in set (0.11 sec)

mysql> explain select userNick from Client where sn<1200;
+—-+————-+——–+——-+—————+———+———+——+——+————-+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+—-+————-+——–+——-+—————+———+———+——+——+————-+
| 1 | SIMPLE | Client | range | PRIMARY | PRIMARY | 4 | NULL | 1 | Using where |
+—-+————-+——–+——-+—————+———+———+——+——+————-+
1 row in set (0.00 sec)

id (JSON name: select_id)

SELECT 标示符, 这是SELECT 查询的顺序号。这个值可以是NULL,如果row只想一个union结果集。

在这种情况下, 表列显示值为

0 0
原创粉丝点击