设为首页 加入收藏

TOP

mysql explain type(二)
2015-11-21 02:08:25 来源: 作者: 【 】 浏览:2
Tags:mysql explain type
ble: a
? ? ? ? ?type: eq_ref
possible_keys: PRIMARY
? ? ? ? ? key: PRIMARY
? ? ? key_len: 2
? ? ? ? ? ref: sakila.b.film_id
? ? ? ? ?rows: 1
? ? ? ? Extra: Using where
2 rows in set (0.00 sec)
?
type = const/system,单表中最多只有一条匹配行,查询起来非常迅速,所以这个匹配行中的其他列中的值可以被优化器在当前查询中当做常量来处理。例如根据主键或者唯一索引进行的查询。
mysql> explain select * from film ?where film_id = 1\G
*************************** 1. row ***************************
? ? ? ? ? ?id: 1
? select_type: SIMPLE
? ? ? ? table: film
? ? ? ? ?type: const
possible_keys: PRIMARY
? ? ? ? ? key: PRIMARY
? ? ? key_len: 2
? ? ? ? ? ref: const
? ? ? ? ?rows: 1
? ? ? ? Extra:
1 row in set (0.02 sec)
?
注释:如果上表中film表中只有一行数据,那么type就是system。
?
?
type = NULL,MYSQL不用访问表或者索引就直接能到结果。
mysql> explain select 1 from dual ?where 1\G (dual是一个虚拟的表,可以直接忽略)
*************************** 1. row ***************************
? ? ? ? ? ?id: 1
? select_type: SIMPLE
? ? ? ? table: NULL
? ? ? ? ?type: NULL
possible_keys: NULL
? ? ? ? ? key: NULL
? ? ? key_len: NULL
? ? ? ? ? ref: NULL
? ? ? ? ?rows: NULL
? ? ? ? Extra: No tables used
1 row in set (0.00 sec)
?
mysql> select 1+1 from dual;
+-----+
| 1+1 |
+-----+
| ? 2 |
+-----+
1 row in set (0.05 sec)
?
explain extended
mysql> explain extended select sum(amount) from customer a ,payment b where 1 = 1 and a.customer_id = b.customer_id and email = 'JANE.BENNETT@sakilacustomer.org'\G
*************************** 1. row ***************************
? ? ? ? ? ?id: 1
? select_type: SIMPLE
? ? ? ? table: a
? ? ? ? ?type: ALL
possible_keys: PRIMARY
? ? ? ? ? key: NULL
? ? ? key_len: NULL
? ? ? ? ? ref: NULL
? ? ? ? ?rows: 541
? ? ?filtered: 100.00
? ? ? ? Extra: Using where
*************************** 2. row ***************************
? ? ? ? ? ?id: 1
? select_type: SIMPLE
? ? ? ? table: b
? ? ? ? ?type: ref
possible_keys: idx_fk_customer_id
? ? ? ? ? key: idx_fk_customer_id
? ? ? key_len: 2
? ? ? ? ? ref: sakila.a.customer_id
? ? ? ? ?rows: 14
? ? ?filtered: 100.00
? ? ? ? Extra:?
2 rows in set, 1 warning (0.00 sec)
?
mysql> show warnings\G
*************************** 1. row ***************************
? Level: Note
? ?Code: 1003
Message: select sum(`sakila`.`b`.`amount`) AS `sum(amount)` from `sakila`.`customer` `a` join `sakila`.`payment` `b` where ((`sakila`.`b`.`customer_id` = `sakila`.`a`.`customer_id`) and (`sakila`.`a`.`email` = 'JANE.BENNETT@sakilacustomer.org'))
1 row in set (0.00 sec)
?
首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇MySql性能调优(五)采用合适的锁.. 下一篇再议Seconds_Behind_Master

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: