简体   繁体   English

在索引列mysql上选择速度

[英]select speed on indexed column mysql

I have a mysql table on innodb with 4.5ish million rows. 我在具有4.5ish百万行的innodb上有一个mysql表。

Why is there a HUGE time difference between these (seemingly to me) almost identical select statement? 为什么这些(几乎对我来说)几乎相同的选择语句之间存在巨大的时差?

url is varchar(200) urlvarchar(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 https://bugs.mysql.com/bug.php?id=32308

http://dev.mysql.com/doc/refman/5.0/en/type-conversion.html 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 . 为了将字符串列与数字进行比较, MySQL无法使用该列上的索引来快速查找值 If str_col is an indexed string column, the index cannot be used when performing the lookup in the following statement: 如果str_col是索引字符串列,则在以下语句中执行查找时不能使用索引:

 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' . 这样做的原因是有许多不同的字符串可以转换为值1 ,例如'1'' 1''1a'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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