SQL Server视图性能调整 [英] SQL Server View Performance Tuning

查看:211
本文介绍了SQL Server视图性能调整的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个SQL Server视图,它从一个巨大的表中检索数据,并通过比较当前行和先前的记录在视图中进行一些计算关键记录。

I am having a SQL Server view which is retrieving data from a huge table and doing some calculation within the view by comparing the current row with the previous records for a key record.

目前,该视图在测试数据较少的情况下表现良好。 

At present, the view is performing well with less number of test data. 

但是当它转移到prod时,它会达到性能,从视图中检索数据需要时间。 

But when it moves to prod, then it will hit the performance and it takes time to retrieve the data from the view. 

对SQL Server视图进行一些性能改进的方法可能是什么。 

What could be the ways to do some performance improvement to the SQL Server view. 

我知道我们将无法在视图中使用临时表或表变量。 

I understand that we won't be able to use the temp tables or table variables within the view. 

因此我正在使用CTE计算部分。 

Hence am using CTE for the calculation part. 

期待一些有价值的建议。 

Expecting some valuable suggestions. 

问候

MUS

推荐答案

你检查过该表是否有锁?

did you check that the table has a lock ?

这通常是一个问题table .. 

this is often a Problem with a Hugh table.. 

你可以用于测试使用标志"with(nolock)"看到性能更好,但你需要知道什么是" with(nolock)"是。 

you can for testing use the flag "with (nolock)" to see is the Performance better, but you Need to know for what the " with (nolock)" is. 

另一种方法是使用函数或存储过程,在其中你可以使用CTE或temp tbl。 

a other way is to use a function or Stored Procedure and inside this you can use a CTE or temp tbl. 

btw。 

btw. 

您可以在视图中使用CTE .. 

you can use CTE inside a view.. 

http://www.sqlusa.com/bestpractices2005/viewwithcte/

如果它解决了您的问题,请将此标记为答案如果它有助于解决您的问题,请投票如有帮助|免责声明:此帖子不提供任何保证,也不授予任何权利。

N 48°8'39.8419" E 11°36'1.3339"

klaus 

klaus 


这篇关于SQL Server视图性能调整的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆