国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數(shù)據(jù)庫 > Oracle > 正文

實(shí)例講解臨時(shí)處理去重 80w 數(shù)據(jù)時(shí)夯死現(xiàn)象

2024-08-29 13:58:26
字體:
供稿:網(wǎng)友

這篇文章主要介紹了臨時(shí)處理去重 80w 數(shù)據(jù)時(shí)夯死現(xiàn)象,需要的朋友可以參考下

近日,在對一張百萬數(shù)據(jù)的業(yè)務(wù)表進(jìn)行去重時(shí),去重操作竟然夯住了。下面就來簡單回憶一下。

1、查詢業(yè)務(wù)表數(shù)據(jù)量,查看到總共有200多w條

 

 
  1. SQL> select count(*) from tb_bj_banker_etl; 
  2.  
  3. 2552381 

2、查詢表內(nèi)應(yīng)該去掉的重復(fù)數(shù)據(jù)量,共80多w條

 

 
  1. SQL> select count(*) from tb_bj_banker_etl where (id) in (select id from tb_bj_banker_etl group by id having count(*)>1) and rowid not in(select max(rowid) from tb_bj_banker_etl group by id having count(*)>1); 
  2.  
  3. 830099 

3、于是,在晚上下班前,執(zhí)行了下面的語句腳本,為了去重

 

  1. SQL> delete from tb_bj_banker_etl where(id) in (select id from tb_bj_banker_etl group by id having count(*)>1) and rowid not in(select max(rowid) from tb_bj_banker_etl group by id having count(*)>1); 
  2.  
  3. SQL> commit; 

4、第二天,到達(dá)現(xiàn)場時(shí),發(fā)現(xiàn)PL/SQL Developer工具中昨天晚上執(zhí)行的語句仍在執(zhí)行中

首先察覺,80多w的去重?cái)?shù)據(jù)跑了一個(gè)晚上也沒跑完?這肯定是哪里出了問題?

懷疑有鎖表。

于是查詢是否有鎖表的用戶。

 

 
  1. SELECT 
  2. A.OWNER, --OBJECT所屬用戶  
  3. A.OBJECT_NAME, --OBJECT名稱  
  4. B.XIDUSN,  
  5. B.XIDSLOT,  
  6. B.XIDSQN,  
  7. B.SESSION_ID, --鎖表用戶的session  
  8. B.ORACLE_USERNAME, --鎖表用戶的Oracle用戶名  
  9. B.OS_USER_NAME, --鎖表用戶的操作系統(tǒng)登陸用戶名  
  10. B.PROCESS,  
  11. B.LOCKED_MODE,  
  12. C.MACHINE, --鎖表用戶的計(jì)算機(jī)名稱  
  13. C.STATUS, --鎖表狀態(tài)  
  14. C.SERVER,  
  15. C.SID,  
  16. C.SERIAL#,  
  17. C.PROGRAM --鎖表用戶所用的數(shù)據(jù)庫管理工具  
  18. FROM 
  19. ALL_OBJECTS A,  
  20. V$LOCKED_OBJECT B,  
  21. SYS.GV_$SESSION C  
  22. WHERE 
  23. A.OBJECT_ID = B.OBJECT_ID  
  24. AND B.PROCESS = C.PROCESS  
  25. ORDER BY 1,2 

在下面結(jié)果中可以看到,鎖表的只是去重語句的發(fā)起會(huì)話,并沒有其它用戶造成鎖表,這說明語句仍然在執(zhí)行嘛?帶著疑問,開始嘗試解決。

1 BJHYL tb_bj_banker_ETL 15 18 9000 913 BJHYL Administrator 4036:972 3 WORKGROUP/BACKDB ACTIVE DEDICATED 913 3381 plsqldev.exe

2 BJHYL tb_bj_banker_ETL 15 18 9000 913 BJHYL Administrator 4036:972 3 WORKGROUP/BACKDB INACTIVE DEDICATED 649 41791 plsqldev.exe

3 BJHYL tb_bj_banker_ETL 15 18 9000 913 BJHYL Administrator 4036:972 3 WORKGROUP/BACKDB INACTIVE DEDICATED 817 27777 plsqldev.exe

4 BJHYL tb_bj_banker_ETL 15 18 9000 913 BJHYL Administrator 4036:972 3 WORKGROUP/BACKDB INACTIVE DEDICATED 841 1981 plsqldev.exe

5、采用分批次,解決去重夯住問題

由于直接去重?zé)o法順利進(jìn)行,于是想到了分批次去重的方法,試一下。

 

 
  1. 第一次:  
  2. delete from tb_bj_banker_etl where(id) in (select id from tb_bj_banker_etl group by id having count(*)>1) and rowid not in(select max(rowid) from tb_bj_banker_etl group by id having count(*)>1) and rownum<=100000;  
  3. commit;  
  4.  
  5. 第二次:  
  6. delete from tb_bj_banker_etl where(id) in (select id from tb_bj_banker_etl group by id having count(*)>1) and rowid not in(select max(rowid) from tb_bj_banker_etl group by id having count(*)>1) and rownum<=100000;  
  7. commit;  
  8.  
  9. 。。。。。。。  
  10. 。。。。。。。  
  11. 。。。。。。。  
  12.  
  13. 第八次:  
  14. delete from tb_bj_banker_etl where(id) in (select id from tb_bj_banker_etl group by id having count(*)>1) and rowid not in(select max(rowid) from tb_bj_banker_etl group by id having count(*)>1);  
  15. commit; 

結(jié)果:通過將80多萬數(shù)據(jù)劃分成以10w數(shù)據(jù)為單次進(jìn)行去重操作,總共用時(shí)140多秒,完成了去重80萬數(shù)據(jù)的目的。但為何直接處理出現(xiàn)夯死情況,有待后續(xù)跟蹤分析。

以上就是臨時(shí)處理去重80w數(shù)據(jù)時(shí)夯死現(xiàn)象的全部過程,希望可以幫到大家。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 合肥市| 桑植县| 永德县| 沙河市| 都兰县| 五原县| 沾化县| 怀宁县| 和林格尔县| 荆门市| 突泉县| 定边县| 永胜县| 青海省| 芜湖县| 盐亭县| 托克托县| 醴陵市| 广汉市| 科技| 厦门市| 攀枝花市| 西乌珠穆沁旗| 沅陵县| 罗源县| 岑巩县| 淅川县| 潞城市| 乐业县| 安岳县| 城步| 江津市| 丘北县| 工布江达县| 莫力| 会东县| 祁门县| 宣威市| 来安县| 咸丰县| 汾阳市|