問題:mysql語句中使用like后面的%(百分號(hào)) 是不是越多執(zhí)行效率越慢!
總用時(shí):0.0489秒 0.0691 0.0485 0.0467
select `goods_name`, `goods_img`, `sku_id`, `import` from `goods` where `goods_name` like '%iphone%ipod%' and `stime` < 1413877244 and `etime` > 1413877244 order by `flag` desc
總用時(shí):0.0460秒 0.0430 0.0493 0.0783 0.0496
select `goods_name`, `goods_img`, `sku_id`, `import` from `goods` where `goods_name` like '%iphone%' and `goods_name` like '%ipod%' and `stime` < 1413877367 and `etime` > 1413877367 order by `flag` desc
總用時(shí):0.0458秒 0.0441秒 0.0449秒
select `goods_name`, `goods_img`, `sku_id`, `import` from `goods` where `goods_name` like '%%%%%%%%%%%%%%%%%%%%%%%iphone%ipod%%%%%%%%%%%%%%%%%%%%%%%' and `stime` < 1413877997 and `etime` > 1413877997 order by `flag` desc
實(shí)踐證明,百分號(hào)的數(shù)量不影響sql執(zhí)行的速度。這幾種方法的效率都是差不多的。
以上是我測(cè)試的結(jié)果。個(gè)人可根據(jù)自己的實(shí)際需求去選擇寫法!建議是最好選擇第二種!
更多信息請(qǐng)查看IT技術(shù)專欄