Bug #11346 | slow query due to datatype cast? | ||
---|---|---|---|
Submitted: | 15 Jun 2005 9:48 | Modified: | 16 Jul 2005 20:31 |
Reporter: | Pascal Sonon | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | MySQL Server: Optimizer | Severity: | S3 (Non-critical) |
Version: | 4.1.12 | OS: | Linux (Linux Fedora Core 2) |
Assigned to: | CPU Architecture: | Any |
[15 Jun 2005 9:48]
Pascal Sonon
[25 Jun 2005 16:36]
Jorge del Conde
I was unable to reproduce this bug in 5.0.9bk: mysql> explain select * from mytable where id_table like '1'; +----+-------------+---------+--------+---------------+------+---------+------+------+-------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+---------+--------+---------------+------+---------+------+------+-------+ | 1 | SIMPLE | mytable | system | PRIMARY | NULL | NULL | NULL | 1 | | +----+-------------+---------+--------+---------------+------+---------+------+------+-------+ 1 row in set (0.00 sec) mysql> explain select * from mytable where id_table = '1'; +----+-------------+---------+--------+---------------+------+---------+------+------+-------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+---------+--------+---------------+------+---------+------+------+-------+ | 1 | SIMPLE | mytable | system | PRIMARY | NULL | NULL | NULL | 1 | | +----+-------------+---------+--------+---------------+------+---------+------+------+-------+ 1 row in set (0.00 sec) mysql> explain select * from mytable where id_table = 1; +----+-------------+---------+--------+---------------+------+---------+------+------+-------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+---------+--------+---------------+------+---------+------+------+-------+ | 1 | SIMPLE | mytable | system | PRIMARY | NULL | NULL | NULL | 1 | | +----+-------------+---------+--------+---------------+------+---------+------+------+-------+ 1 row in set (0.00 sec)
[25 Jun 2005 16:38]
Jorge del Conde
I was also unable to reproduce it in 4.1.13
[16 Jul 2005 20:31]
Sergei Golubchik
Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.mysql.com/documentation/ and the instructions on how to report a bug at http://bugs.mysql.com/how-to-report.php Additional info: Yes, there is a reason why integer values are not casted to string values before query execution and index selection. Because according to implicit casting that MySQL performs for comparison, when you compare a string with a number, they are compared as numbers. E.g. when all the following will evaluate to TRUE: 1 = "1" 1 = " 1" 1 = " +1" 1 = "000000001" etc. You see, if you cast an integer (1 in my examples) to a string, and perform a string comparison, you won't be able to keep all the above TRUE anymore.