当前位置:Gxlcms > 数据库问题 > MySql in子句 效率低下优化

MySql in子句 效率低下优化

时间:2021-07-01 10:21:17 帮助过:2人阅读

,效率极其低下,耗时高达几分钟。

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 后,极大优化效率。

 

MySql in子句 效率低下优化

标签:

人气教程排行