-------------+
1 row in set (0.00 sec)
MySQL [test]> select * from emp where ename=23456; ## 当varchar类型不对时,仍然是可以查出结果
+-------+-------+-----------+------+---------------------+------+------+--------+
| EMPNO | ENAME | JOB | MGR | HIREDATE | SAL | COMM | DEPTNO |
+-------+-------+-----------+------+---------------------+------+------+--------+
| 7936 | 23456 | BOSCO-DBA | 7788 | 2014-09-13 16:13:56 | 2450 | 800 | 10 |
+-------+-------+-----------+------+---------------------+------+------+--------+
1 row in set, 14 warnings (0.00 sec)
MySQL [test]> explain select * from emp where ename=23456; ## 当varchar类型不匹配时,索引无效了,选择了全表扫描
+----+-------------+-------+------+---------------+------+---------+------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------+---------------+------+---------+------+------+-------------+
| 1 | SIMPLE | emp | ALL | idx_ename | NULL | NULL | NULL | 15 | Using where |
+----+-------------+-------+------+---------------+------+---------+------+------+-------------+
1 row in set (0.00 sec)
可见,如果是字符类型,当出现类型不一致时,是会影响索引的使用的,会产生隐式转换的。
blog地址:http://blog.csdn.net/hw_libo/article/details/39252427
-- Bosco QQ:375612082
---- END ----
-------------------------------------------------------------------------------------------------------
版权所有,文章允许转载,但必须以链接方式注明源地址,否则追究法律责任!