如何提高SQL Server 2008中表值函数的性能? [英] How can I Increase performance of Table Valued Function in SQL Server 2008 ?

查看:91
本文介绍了如何提高SQL Server 2008中表值函数的性能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友,



我有疑问





Hi Friends,

I have a query


SELECT   S.STNNumber,T.* FROM STN S
INNER JOIN TypeDetail TD ON TD.TypeDetailID=S.StatusTypeDetailID
CROSS APPLY dbo.GetSTNInfo(S.STNID,TD.Code,S.ReasonTypeDetailID)T





表值函数GetSTNInfo需要很长时间,

当我看到执行计划时没有必要的TVF信息显示。



请建议我提高这个查询的性能。



(我已经删除了一些25个差不多表格的联接,但是时间只有TVF而已。





先谢谢,



shreeniwas kushwah



Table valued Function GetSTNInfo takes much time ,
when i see Execution Plan no required info shows for TVF.

Pls suggest me to increase performance of this query.

(I have remove some Joins which are 25 almost tables but time comsuming is TVF only)


Thanks in Advance,

shreeniwas kushwah

推荐答案

嗨您在查询中直接使用表值函数

所以首先创建临时表并将表值存储表存储到该临时表中,然后使用该临时表而不是表值函数



Hi You are using table valued function directly in the query
so first create temp table and store table valued output into that temp table and then use that temp table instead of table valued function

Declare @ptemp table(STNID int,Code varchar(45),ReasonTypeDetailID int)

insert into @Ptemp 
select * from dbo.GetSTNInfo(S.STNID,TD.Code,S.ReasonTypeDetailID)


SELECT   S.STNNumber,T.* FROM STN S
INNER JOIN TypeDetail TD ON TD.TypeDetailID=S.StatusTypeDetailID
cross apply @Ptemp





你应该再次创建索引,在查询中使用哪些列,这样可以加快你的执行速度。



请在这里分享您的表值功能代码,这样我可以为您提供更多帮助。





谢谢,



And again you should create indexes as which columns you are using in query so it may fast your execution.

And please share your table valued function code here so i can help you more.


THanks,


这篇关于如何提高SQL Server 2008中表值函数的性能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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