2016-11-14 39 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.