mysql update语句 in执行效率优化

1、常用的mysql执行更新操作语句如下:

UPDATE table1 set num = num + 1 where id in (SELECT id FROM table2 WHERE date>'2017-05-09)

in条件的更新效率可优化使用join语法;
2、join预发更新操作

UPDATE table1 t1 INNER JOIN table2 t2 on t1.id = t2.id set t1.num = t1.num + 1 where t2.date>'2017-05-09'

 

 

1、要更新的数据大概 有10W多条  然后 我执行了下 结果 2个小时了 还是没 执行成功

pdate  table1 t  set t.column1 =0 where t.id in (select id from table2)  

 2、 sql 改成

update table1 t ,table2 b set t.column1=0 where t.id=b.id  

   几秒钟就执行成功  !!!

posted @ 2020-06-13 14:35  一个人的孤独自白  阅读(8619)  评论(0编辑  收藏  举报