简体   繁体   中英

select speed on indexed column mysql

I have a mysql table on innodb with 4.5ish million rows.

Why is there a HUGE time difference between these (seemingly to me) almost identical select statement?

url is varchar(200)

select * from table where url = 12345;  take 2.715 seconds

select * from table where url = "12345"; takes 0.000 seconds

Thanks in advance

I think you'll find the following information enlightening.

https://bugs.mysql.com/bug.php?id=32308

http://dev.mysql.com/doc/refman/5.0/en/type-conversion.html

Notably, the documentation clearly states (emphasis mine):

For comparisons of a string column with a number, MySQL cannot use an index on the column to look up the value quickly . If str_col is an indexed string column, the index cannot be used when performing the lookup in the following statement:

 SELECT * FROM tbl_name WHERE str_col=1; 

The reason for this is that there are many different strings that may convert to the value 1 , such as '1' , ' 1' , or '1a' .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM