0
点赞
收藏
分享

微信扫一扫

mysql select/update where id in(上万个元素)的优化方案:

花海书香 2022-10-22 阅读 155

select/update where id in(上万个元素)的优化方案:
优化前: select
select docId from tab1 where word in (select word from tab1 where docId=123) group by docId limit 1000;
优化后:
select docId from (select word from tab1 where docId=123) as t2 join tab1 t on t.word=t2.word where t2.word is not null GROUP BY docId limit 1000
优化前: update
update table1 t set t.column1=0 WHERE t.id in (SELECT tid FROM table2 b)
优化后:
update table1 t ,table2 b set t.column1=0 where t.id=b.id;

举报

相关推荐

0 条评论