MySQL EXPLAIN:Impossible WHERE noticed after re...

mysql 的 explain命令用于查看执行效果,很久没有来分析sql了(ps:有段时间没写SQL了)无解……还好,有google。 mysql


mysql> create table t_william(id int primary key,name char(2))engine=innodb;
Query OK, 0 rows affected (0.13 sec)
/*上两条数据*/

insert into t_william value(1,'ad');
insert into t_william value(2,'a2');
mysql> explain select *from t_willam where id=1;
+----+-------------+----------+-------+---------------+---------+---------+-------+------+-------+
| id | select_type | table    | type  | possible_keys | key     | key_len | ref   | rows | Extra |
+----+-------------+----------+-------+---------------+---------+---------+-------+------+-------+
|  1 | SIMPLE      | t_willam | const | PRIMARY       | PRIMARY | 4       | const |    1 |       |
+----+-------------+----------+-------+---------------+---------+---------+-------+------+-------+
1 row in set (0.00 sec)
对于已存在的记录还正常。换一个不存在的主键id,则奇葩出现了,出现了,



mysql> explain select *from t_willam where id=3; 
+----+-------------+-------+------+---------------+------+---------+------+------+-----------------------------------------------------+
| id | select_type | table | type | possible_keys | key  | key_len | ref  | rows | Extra                                               |
+----+-------------+-------+------+---------------+------+---------+------+------+-----------------------------------------------------+
|  1 | SIMPLE      | NULL  | NULL | NULL          | NULL | NULL    | NULL | NULL | Impossible WHERE noticed after reading const tables |
+----+-------------+-------+------+---------------+------+---------+------+------+-----------------------------------------------------+


Impossible WHERE noticed after reading const tables。(听说,这是由于mysql是首先对索引记录进行查询,而后在分析效果。) sql


附录: google

知识回顾: spa

Explain的type显示的是访问类型,是较为重要的一个指标,结果值从好到坏依次是:

system > const > eq_ref > ref > fulltext > ref_or_null > index_merge > unique_subquery > index_subquery > range > index > ALL

code

参考: blog

http://wangyuanzju.blog.163.com/blog/static/13029200691114035831/ 索引

http://hi.baidu.com/thinkinginlamp/item/88fd66da58ff0ae4795daad3 it

相关文章
相关标签/搜索