In a case, I need SQL like this, in Mysql, innodb engine:

**select** code, title **from** my_table **where** code **in** ('cx001', 'kd309', 'yb020');

The column code has a unique index. Would the SQL run with the index? Would it scan the whold table? Comparing with doing " where code='cx001' " three times, would my SQL run faster?


with Chinese following: 我有如下的一个sql语句,使用Mysql的innodb引擎: select code, title from my_table where code in ('cx001', 'kd309', 'yb020'); code列上有唯一索引,那么这句SQL是否能使用此索引?会不会造成全表遍历? 与每个id都直接用" code = 'xxxxx' "比起来,哪个会更快一些呢?

link|improve this question
3  
Best way to find out is to use MySQL's EXPLAIN and run benchmarks against your data set. – liquorvicar 53 mins ago
1  
Have a look at the EXPLAIN statement. – Gumbo 53 mins ago
2  
It should, but it does not hurt to check for yourself. I would expect no difference from switching to three =. – dasblinkenlight 52 mins ago
feedback

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
or
required, but never shown

Browse other questions tagged or ask your own question.