更新一张表中的某些记录值,更新条件来自另一张表(数据量大),效率极其低下。
update A set A.a = 0 where A.b in
(
select distinct B.b from B where B.c = 0
);
优化后
update A set A.a = 0 where A.b in (
select b from (select distinct B.b from B where B.c = 0) as co
);
总结:对于where xxx in 子句效率极其低下问题,经过in的子句外包装一层select xxx from ( ... ) as co 后,极大优化效率。