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

相關文章
相關標籤/搜索