问题:mysql语句中使用like后面的%(百分号) 是不是越多运行效率越慢!
总用时:0.0489秒 0.0691 0.0485 0.0467
SELECT &#96;goods_name&#96;, &#96;goods_img&#96;, &#96;sku_id&#96;, &#96;import&#96; FROM &#96;goods&#96; WHERE &#96;goods_name&#96; LIKE &#39;%iPhone%iPod%&#39; AND &#96;stime&#96; <1413877244 AND &#96;etime&#96; > 1413877244 ORDER BY &#96;flag&#96; DESC
总用时&#xff1a;0.0460秒 0.0430 0.0493 0.0783 0.0496
SELECT &#96;goods_name&#96;, &#96;goods_img&#96;, &#96;sku_id&#96;, &#96;import&#96; FROM &#96;goods&#96; WHERE &#96;goods_name&#96; LIKE &#39;%iPhone%&#39; AND &#96;goods_name&#96; LIKE &#39;%iPod%&#39; AND &#96;stime&#96; <1413877367 AND &#96;etime&#96; > 1413877367 ORDER BY &#96;flag&#96; DESC
总用时&#xff1a;0.0458秒 0.0441秒0.0449秒
SELECT &#96;goods_name&#96;, &#96;goods_img&#96;, &#96;sku_id&#96;, &#96;import&#96; FROM &#96;goods&#96; WHERE &#96;goods_name&#96; LIKE &#39;%%%%%%%%%%%%%%%%%%%%%%%iPhone%iPod%%%%%%%%%%%%%%%%%%%%%%%&#39; AND &#96;stime&#96; <1413877997 AND &#96;etime&#96; > 1413877997 ORDER BY &#96;flag&#96; DESC
实践证明&#xff0c;百分号的数量不影响sql运行的速度。这几种方法的效率都是差点儿相同的。
以上是我測试的结果。个人可依据自己的实际需求去选择写法&#xff01;建议是最好选择另外一种&#xff01;