SQL Server死結的解決過程

來源:互聯網
上載者:User

標籤:disco   開啟   work   select   res   iter   led   exist   ued   

某現場報一個SQL死結,於是開啟了1222跟蹤:

dbcc traceon(1222,-1)

一段時間之後拷貝ERROR檔案尋找相關資訊,比較有用的摘錄出來如下:

語句一:

select study_iuid,station_aet,modality,accession_no,patient_fk,item_attrs,start_datetime  from worklist w WITH(readpast), mwl_item m  where w.TAG_STUDY_INSTANCE_UID=m.study_iuid  and isread=‘1‘ and (TAG_SPS_STATUS is null or TAG_SPS_STATUS=‘SCHEDULED‘ or TAG_SPS_STATUS=‘Discontinued‘)  and TAG_SPS_START_DATE between @P0 and @P1   and  not exists (select 1 from mpps b where b.study_iuid=m.study_iuid)    

語句二:

INSERT INTO mwl_item (created_time, updated_time, sps_id, start_datetime, station_aet, station_name, modality, perf_physician, perf_phys_fn_sx, perf_phys_gn_sx, perf_phys_i_name, perf_phys_p_name, req_proc_id, accession_no, study_iuid, item_attrs, sps_status, patient_fk) VALUES (@P0, @P1, @P2, @P3, @P4, @P5, @P6, @P7, @P8, @P9, @P10, @P11, @P12, @P13, @P14, @P15, @P16, @P17);  

相關的死結資源如下:

resource-list pagelock fileid=1 pageid=6996 dbid=8 objectname=Worklist.dbo.mwl_item id=lock19825c100 mode=IX associatedObjectId=72057594039697408  owner-list   owner id=process984d048 mode=IX  waiter-list   waiter id=process60e9708 mode=S requestType=wait pagelock fileid=1 pageid=11086 dbid=8 objectname=Worklist.dbo.mwl_item id=lock1b087b100 mode=S associatedObjectId=72057594039697408  owner-list   owner id=process60e9708 mode=S  waiter-list   waiter id=process984d048 mode=IX requestType=wait

可以明顯的看到是select語句與insert語句產生了死結,爭用的資源分別6996和11086這兩個page。

因此根據死結的產生原理決定進行以下最佳化:

1.最佳化select語句使其儘快完成以減少死結頻率。

2.對select語句使用nolock選項以避免死結問題。

3.通知開發最佳化相關代碼的執行順序來避免死結問題。

最終最佳化了select語句,其他兩條交給開發做修改。

 

SQL Server死結的解決過程

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.