簡體   English   中英

如何處理SQL存儲過程中的更新查詢的性能問題?

[英]How to handle performance issue of update query inside of the SQL stored procedure?

我創建了一個用於更新表的sql查詢,但是它存在性能問題。 當我從存儲過程中調用以下更新時,從我的asp.net平台將sql數據庫超時。 您能幫我更快地解決數據庫超時問題嗎?

    UPDATE e SET e.X=tablo.X,E.Y=ISNULL(tablo.Y,0),e.V=tablo.V,e.ADRES=tablo.ADRES,e.A=tablo.A
FROM tbltabloor e 
JOIN tablo_NOT tablo ON e.Z=tablo.Z AND E.T=convert(datetime,CONVERT(varchar(8),tablo.T,112)) AND E.U=tablo.U
WHERE NOT  exists (select * from tablo_NOT t where t.Z =e.Z AND E.T=convert(datetime,CONVERT(varchar(8),t.T,112)) AND  E.U=t.U 
AND E.X=t.X AND ISNULL(t.Y,0)=ISNULL(E.Y,0) AND E.V=t.V AND E.ADRES=t.ADRES
)
Did you create indexes on all join fields between tables? 
To accelerate processing without changing the structure of your current query, you must create these indexes.
Note that for fields calculated as _convert (datetime, CONVERT (varchar (8), tablo.T, 112))_, you must create function based index and here is a useful link that can help you: 
[http://stackoverflow.com/questions/22168213/function-based-indexes-in-sql-server][1].
Normally with this, executing your query will not result in a timeout.

hope this can help.

使用以下命令查找任何缺少的適用索引:

SELECT 
statement AS [database.scheme.table],
column_id , column_name, column_usage, 
migs.user_seeks, migs.user_scans, 
migs.last_user_seek, migs.avg_total_user_cost,
migs.avg_user_impact
FROM sys.dm_db_missing_index_details AS mid
CROSS APPLY sys.dm_db_missing_index_columns (mid.index_handle)
INNER JOIN sys.dm_db_missing_index_groups AS mig 
ON mig.index_handle = mid.index_handle
INNER JOIN sys.dm_db_missing_index_group_stats  AS migs 
ON mig.index_group_handle=migs.group_handle
ORDER BY mig.index_group_handle, mig.index_handle, column_id

在此處閱讀有關此內容的更多信息缺少索引幫助

另外,請盡可能從where子句中刪除轉換日期的內容,因為這肯定會降低查詢速度。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM