优化前
SELECT* FROM erp_helei mg WHERE mg.num = 602 AND mg.pid IN (10002559,10002561,10002562,10002563,10002564,10002598,10002599,10002600,10002601,10002602,10002603,10002604,10002648,10002649,10002667,10002668,10002676,10002558)
优化后
SELECT* FROM erp_helei mg WHERE mg.num = 602 AND mg.pid IN (‘10002559‘,‘10002561‘,‘10002562‘,‘10002563‘,‘10002564‘,‘10002598‘,‘10002599‘,‘10002600‘,‘10002601‘,‘10002602‘,‘10002603‘,‘10002604‘,‘10002648‘,‘10002649‘,‘10002667‘,‘10002668‘,‘10002676‘,‘10002558‘)
原因
pid列是char类型,必须加‘‘号才可走索引,否则导致全表扫描,会随着表的增大而变得更慢
时间: 2024-09-12 12:54:36