Possible duplicate:
Drawbacks of quoting integers in a Mysql query?
I have a very simple Called Device table in the MYSql database.
+-----------------------------------+--------------+------+-----+----------------+ | Field | Type | Null | Key | Extra | +-----------------------------------+--------------+------+-----+----------------+ | DTYPE | varchar(31) | NO | | | | id | bigint(20) | NO | PRI | auto_increment | | dateCreated | datetime | NO | | | | dateModified | datetime | NO | | | | phoneNumber | varchar(255) | YES | MUL | | | version | bigint(20) | NO | | | | oldPhoneNumber | varchar(255) | YES | | | +-----------------------------------+--------------+------+-----+----------------+
This table contains over 100 thousand records. I execute a very simple request
select * from AttDevice where phoneNumber = 5107357058;
This request takes almost 4-6 seconds, but when I change this request a bit, as shown below.
select * from AttDevice where phoneNumber = '5107357058';
It takes almost no time to complete. Note that the phone number column is varchar. I do not understand why the first case takes more time, and later not. The difference between the two queries is a single quote. Can MYSQL handle these queries differently, if so, why?
EDIT 1
I used EXPLAIN and got the following output, but donโt know how to interpret these two results.
mysql> EXPLAIN select * from AttDevice where phoneNumber = 5107357058; +----+-------------+-----------+------+---------------------------------------+------+---------+------+---------+-------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+-----------+------+---------------------------------------+------+---------+------+---------+-------------+ | 1 | SIMPLE | Device | ALL | phoneNumber,idx_Device_phoneNumber | NULL | NULL | NULL | 6482116 | Using where | +----+-------------+-----------+------+---------------------------------------+------+---------+------+---------+-------------+ 1 row in set (0.00 sec) mysql> EXPLAIN select * from AttDevice where phoneNumber = '5107357058'; +----+-------------+-----------+------+---------------------------------------+-------------+---------+-------+------+-------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+-----------+------+---------------------------------------+-------------+---------+-------+------+-------------+ | 1 | SIMPLE | Device | ref | phoneNumber,idx_Device_phoneNumber | phoneNumber | 258 | const | 2 | Using where | +----+-------------+-----------+------+---------------------------------------+-------------+---------+-------+------+-------------+ 1 row in set (0.00 sec)
Can someone explain to me the key, key_len and the lines present in the output of the EXPLAIN request?
source share