Oracle通過主鍵id刪除記錄很慢

來源:互聯網
上載者:User

標籤:http   io   ar   os   sp   for   檔案   on   2014   

問題描述:

Oracle通過主鍵id刪除2000條記錄很慢,需要花費十二分鐘。

解決過程:

1.首先查看SQL的執行計畫,執行計畫正常,cost只有4,用到了主鍵索引。

2.查看等待事件,

select * from v$session_wait where sid = 507

顯示的event是db file sequential read,也沒有異常。

3.查看統計資訊是否正常

select * from user_tables where table_name = ‘‘;

經檢測,統計資訊也是正常的。

4.查看系統IO,也是正常的。

5.找不到原因,開啟SQL跟蹤

alter session set events=‘10046 trace name context forever,level 12‘;

delete from t_table1 where id >= xxx

alter session set events=‘10046 trace name context off‘;

SQL跟蹤得到一個trace檔案

tkprof orcl_ora_3708.trc myoutput.txt

cat myoutput.txt,這次發現異常,檔案裡面除了有delete語句,還有兩個select語句:

select /*+ all_rows */ count(1)  from  "xxx"."T_TABLE2" where "FRESHMANID" = :1   call    count      cpu    elapsed      disk      query    current        rows  ------- ------  -------- ---------- ---------- ---------- ----------  ----------  Parse        1      0.00      0.00          0          0          0          0  Execute  2000      0.23      0.22          0          0          0          0  Fetch    2000    720.58    740.36        842  61038000          0        2000  ------- ------  -------- ---------- ---------- ---------- ----------  ----------  total    4001    720.82    740.59        842  61038000          0        2000

 

select /*+ all_rows */ count(1)  from  "xxx"."T_TABLE3" where "FRESHMANID" = :1  

call    count      cpu    elapsed      disk      query    current        rows  ------- ------  -------- ---------- ---------- ---------- ----------  ----------  Parse        1      0.00      0.00          0          0          0          0  Execute  2000      0.27      0.27          0          0          0          0  Fetch    2000      1.84      1.93          0    136000          0        2000  ------- ------  -------- ---------- ---------- ---------- ----------  ----------  total    4001      2.11      2.20          0    136000          0        2000

這兩張表各查詢了2000次,可以判斷出來,就是因為這個原因導致delete非常慢,詢問現場相關人員,t_table2、t_table3跟t_table1有什麼關係,現場人員說t_table2和t_table3個有一個外鍵

依賴t_table1的主鍵ID,經過查詢,t_table2和t_table3的外鍵上都沒有建立索引,於是建立索引,再執行delete語句,這次執行速度很快,經過SQL跟蹤,也沒有發現去查詢t_table2和t_table3。

更多Oracle相關資訊見Oracle 專題頁面 http://www.linuxidc.com/topicnews.aspx?tid=12

本文永久更新連結地址:http://www.linuxidc.com/Linux/2014-04/100702.htm

Oracle通過主鍵id刪除記錄很慢

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.