两种更新操作哪个快些?为什么?
方式一:
UPDATE TA
SET quota_usage1 = 0,
quota_usage2 = 0,
quota_usage3 = 0,
quota_usage4 = 0
where id in (select id from TB);
方式二:
UPDATE TA a
SET quota_usage1 = 0,
quota_usage2 = 0,
quota_usage3 = 0,
quota_usage4 = 0
WHERE EXISTS (SELECT id
FROM TB b
WHERE b.id = a.id);
其中TA表会有数十万数据或更多,TB表最多达到万级数据.
------解决方案--------------------应该是第二种快点,最好在a.id,和b.id上加个索引
------解决方案--------------------EXISTS 比in 速度快
------解决方案--------------------in速度慢,好像要全表扫描;
------解决方案--------------------第二种快。