Conclusion:
When MySQL is in an int type, the search condition where num= ' 111 ' and where num=111 can use the index of the field.
When MySQL field is a varchar type, the search condition where num= ' 111 ' can use the index, where num=111 can not use the index
Verification process:
To build a table statement:
CREATE TABLE ' Gyl ' ( ' id ' int (one) not null auto_increment, ' str ' varchar (255) is not NULL, ' num ' int (one) ' NOT NULL Default ' 0 ', ' obj ' varchar (255) Default NULL, PRIMARY key (' id '), key ' str_x ' (' str '), key ' num_x ' (' num ' ') Engine=innodb DEFAULT Charset=utf8;
Inserting data into a table using a self-replicating statement
Insert INTO Gyl (' str ', ' num ') VALUES (123123, ' 12313 ');
Insert INTO Gyl (' str ', ' num ') select ' str ', ' num ' from Gyl;
Change data Update Gyl set Num=id,str=id
Results:
Mysql> Explain select * from Gyl where str=123123 limit 1;+----+-------------+-------+------+---------------+------+ ---------+------+--------+-------------+| ID | Select_type | Table | Type | Possible_keys | Key | Key_len | Ref | Rows | Extra |+----+-------------+-------+------+---------------+------+---------+------+--------+-------------+| 1 | Simple | Gyl | All | str_x | NULL | NULL | NULL | 262756 | Using where |+----+-------------+-------+------+---------------+------+---------+------+--------+-------------+1 Row in setmysql> explain select * from Gyl where str= ' 123123 ' limit 1;+----+-------------+-------+------+------------- --+-------+---------+-------+--------+-------------+| ID | Select_type | Table | Type | Possible_keys | Key | Key_len | Ref | Rows | Extra |+----+-------------+-------+------+---------------+-------+---------+-------+--------+-------------+| 1 | Simple | Gyl | Ref | str_x | str_x | 257 | ConsT | 131378 | Using where |+----+-------------+-------+------+---------------+-------+---------+-------+--------+------------- +1 row in setmysql> explain select * from Gyl where num= ' 12313 ' limit 1; +----+-------------+-------+------+---------------+-------+---------+-------+--------+-------+| ID | Select_type | Table | Type | Possible_keys | Key | Key_len | Ref | Rows | Extra |+----+-------------+-------+------+---------------+-------+---------+-------+--------+-------+| 1 | Simple | Gyl | Ref | num_x | num_x | 4 | Const | 131378 | |+----+-------------+-------+------+---------------+-------+---------+-------+--------+-------+1 row in set1065- Query was emptymysql> explain select * from Gyl where num=12313 limit 1;+----+-------------+-------+------+----------- ----+-------+---------+-------+--------+-------+| ID | Select_type | Table | Type | Possible_keys | Key | Key_len | Ref | Rows | Extra |+----+-------------+-------+------+---------------+-------+---------+-------+--------+-------+| 1 | Simple | Gyl | Ref | num_x | num_x | 4 | Const | 131378 | |+----+-------------+-------+------+---------------+-------+---------+-------+--------+-------+1 row in Set
MySQL index used: When the field is varchar type, the condition is to be wrapped up with ' '