mysql查詢類型轉換 在mysql查詢時最好不要發生類型轉換,如把varchar轉換成int
mysql> explain select * from user where name=1\G
//如果你確定name字段是整型就不要把它轉化成字符串,不加單引號
*************************** 1. row *************************** id: 1 select_type: SIMPLE table: user type: ALL possible_keys: index_name_password key: NULL key_len: NULL ref: NULL rows: 99727 Extra: Using where 1 row in set (0.02 sec) mysql> explain select * from user where name='1'\G
//如果你確定name字段是字符串就不要把它轉化成整型,加單引號
*************************** 1. row *************************** id: 1 select_type: SIMPLE table: user type: ref possible_keys: index_name_password key: index_name_password key_len: 111 ref: const rows: 1 Extra: Using where 1 row in set (0.00 sec)