標籤: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死結的解決過程