Before optimization
Select* from Erp_helei mg WHERE mg.num = 602 and mg.pid in (10002559,10002561,10002562,10002563,10002564,10002598,10002 599,10002600,10002601,10002602,10002603,10002604,10002648,10002649,10002667,10002668,10002676,10002558)
After optimization
Select* from Erp_helei mg WHERE mg.num = 602 and Mg.pid in (' 10002559 ', ' 10002561 ', ' 10002562 ', ' 10002563 ', ' 10002564 ', ' 100 02598 ', ' 10002599 ', ' 10002600 ', ' 10002601 ', ' 10002602 ', ' 10002603 ', ' 10002604 ', ' 10002648 ', ' 10002649 ', ' 10002667 ', ' 10002668 ', ' 10002676 ', ' 10002558 ')
Reason
The PID column is a char type and must be added ' to go through the index, otherwise a full table scan will become slower as the table grows
This article is from the "Age volt" blog, please make sure to keep this source http://suifu.blog.51cto.com/9167728/1783375
MySQL in does not walk index