1.ref理解
- ref:顯示索引的哪一列被使用了蜈膨,有時(shí)候會(huì)是一個(gè)常量:表示哪些列或常量被用于用于查找索引列上的值
2.ref分析
3.key-len案例
mysql> explain select * from t1,t2 where t1.id = t2.id and t1.id='1';
+----+-------------+-------+-------+-----------------------+---------+---------+-------+------+-------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+-------+-----------------------+---------+---------+-------+------+-------+
| 1 | SIMPLE | t1 | const | PRIMARY,index_id_name | PRIMARY | 4 | const | 1 | |
| 1 | SIMPLE | t2 | const | PRIMARY | PRIMARY | 4 | const | 1 | |
+----+-------------+-------+-------+-----------------------+---------+---------+-------+------+-------+
2 rows in set (0.00 sec)
mysql> explain SELECT * from t1,t2 where t1.id = t2.id and t1.`name` = 'downeyjr_1';
+----+-------------+-------+--------+-----------------------+---------+---------+--------------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+--------+-----------------------+---------+---------+--------------+------+-------------+
| 1 | SIMPLE | t2 | ALL | PRIMARY | NULL | NULL | NULL | 1 | |
| 1 | SIMPLE | t1 | eq_ref | PRIMARY,index_id_name | PRIMARY | 4 | mysql1.t2.id | 1 | Using where |
+----+-------------+-------+--------+-----------------------+---------+---------+--------------+------+-------------+
2 rows in set (0.00 sec)
mysql> explain SELECT * from t1,t3 where t1.id = t3.id and t3.age='10';
+----+-------------+-------+-------+-----------------------+---------------+---------+------+------+--------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+-------+-----------------------+---------------+---------+------+------+--------------------------------+
| 1 | SIMPLE | t1 | index | PRIMARY,index_id_name | index_id_name | 37 | NULL | 3 | Using index |
| 1 | SIMPLE | t3 | ALL | PRIMARY | NULL | NULL | NULL | 3 | Using where; Using join buffer |
+----+-------------+-------+-------+-----------------------+---------------+---------+------+------+--------------------------------+
2 rows in set (0.00 sec)
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者