2016-11-14 45 views
-1

我創建了一個sql查詢來更新表,但它有一個性能問題。從我的asp.net平臺將從SQL數據庫超時,當我從存儲過程更新下面。你能幫我讓它更快,並幫助數據庫超時問題?如何處理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 
) 
+0

第一步是在SSMS中運行它,按CTRL-L和觀察查詢計劃。它會建議可能有幫助的索引。 –

+0

問題可能真的在任何地方 - 這取決於表的大小,索引等 - 顯示您的查詢計劃! – Charleh

+1

在'ON'和'WHERE'子句中使用'CONVERT'會限制優化器使用索引的能力。從'DATETIME'提取日期的索引計算列可能會有所幫助。 – HABO

回答

1

看看這裏任何缺少適用的索引使用此:

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 

瞭解更多關於此這裏Missing Index Help

此外,儘量去除轉換日期的東西,如果在所有可能從你的where子句中,因爲這肯定會減慢你的查詢速度。在優化

1
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.