SQL 优化经验记录

1. IN  查询效率低下,可以使用联表查询来优化效率,如下SQL 优化,将性能提升了10倍。

1.优化前:

update tag set washTimes=washTimes+1  where tag.TagNo in (select mx.tagno from BusinessEventMX mx where mx.eventID=1)

and tag.ID in (select TAGID from asset where asset.ORGID = 2);

2.优化后的SQL
 update tag, asset,`businesseventmx` mx  set  tag.`WashTimes` =`tag` .`WashTimes` +1
where   `asset`.`ORGID` =2  and  tag.`TagNo` =mx.`TagNo` and tag.`ID` =`asset`.`TagID`  ;

猜你喜欢

转载自blog.csdn.net/angellyouran/article/details/80162423
今日推荐