码迷,mamicode.com
首页 > 数据库 > 详细

MySql in子句 效率低下优化(亲测有效,从200秒变1秒)

时间:2019-01-08 00:19:13      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:条件   sele   attention   logs   let   www.   .com   resid   update   

MySql in子句 效率低下优化

背景:

 更新一张表中的某些记录值,更新条件来自另一张含有200多万记录的表,效率极其低下,耗时高达几分钟。

update clear_res set candelete=0 where resid in
(
 select distinct resourceid from att_attentionresult where important=0
);

耗时 365s

 

优化后

 update clear_res set candelete=0 where resid in
(
  select resourceid from (
    select distinct resourceid from att_attentionresult where important=0
  ) as tmp
);

耗时 1.41s

 

总结:对于where xxx in 子句效率极其低下问题,经过in的子句外包装一层select xxx from( ... )as tmp 后,极大优化效率。

 

https://www.cnblogs.com/hdwang/p/4749152.html

MySql in子句 效率低下优化(亲测有效,从200秒变1秒)

标签:条件   sele   attention   logs   let   www.   .com   resid   update   

原文地址:https://www.cnblogs.com/findumars/p/10236488.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!