mysql的从另外一张表update多个字段语句如何优化
我的需示很简单,就是到另外一张表将二个字段更新过来,如下
Update Client a
INNER JOIN DoNotCallList b on (a.tmpphone=b.PhoneNo)
set a.donotcall=b.status,a.DateOfLastDNCLScrub=b.DateCreated
where a.tmpphone in (select c.phoneNO FROM DoNotCallList c);
结果,发现如果 client中的tmpphone 都不在DoNotCallList表中时,速度却很慢,,若有数据倒是会快点。是不是我的sql有的问题?
表结构如个
Client(clientid,HomePhone,Cellphone,TmpPhone)
DoNotCallList(PhoneNo,status,DateCreated)
------解决方案--------------------
where a.tmpphone in (select c.phoneNO FROM DoNotCallList c);可以不需要吧?
建立索引没有 tmpphone 、PhoneNo
------解决方案--------------------Update Client a
INNER JOIN DoNotCallList b on (a.tmpphone=b.PhoneNo)
set a.donotcall=b.status,a.DateOfLastDNCLScrub=b.DateCreated
------解决方案--------------------where a.tmpphone in (select c.phoneNO FROM DoNotCallList c);
这种in语句在mysql中效率非常低