批量UPDATE的操作

2021-06-17 20:22:19 字數 718 閱讀 9198

有乙個簡單的業務需求,要根據另外乙個表的id去更新這張表的sys為scott;要更新211w記錄。

sql> create index t_idx1 on t_merge1(object_id);

index created.

sql> create index idx_t on t_merge2(object_id);

index created.

update t_merge1 set owner='scott' where object_id in(select object_id from t_merge2 where t_merge2.object_id=t_merge2.object_id);

21047392 rows updated.

elapsed: 00:32:16.39

耗時: 32分鐘

merge into t_merge1 a

using (select object_id from t_merge2) b

on(a.object_id=b.object_id)

when matched then

update set a.owner='scott';

21047392 rows merged.

elapsed: 00:13:22.77

耗時:13分鐘

merge的操作大大提高了更新速度。

批量插入,update

setting 1 create table t as select from all objects where 1 2 模擬逐行提交的情況,注意觀察執行時間 declare begin for cur in select from t ref loop insert into t values ...

mysql批量更新update操作,導致鎖表

sql如下 update pay trans set return state 1 where order id and user id 批量執行此條sql時,導致資料表被鎖,所有交易異常。經排查where條件order id and user id 沒有加索引,導致整個表被鎖。mysql的行鎖是通...

Oracle批量Update記錄

工作中經常用到oracle批量更新記錄,做為老手也怕出錯,總之要小心再小心,確保資料批量更新正確。下面舉乙個例子 1 建立兩張結構類似的表,建表語句如下 create table jayt1 id int,code varchar2 8 create table jayt2 id int,code ...