表值函数我的查询计划去了哪里? [英] Table Valued Function where did my query plan go?

查看:17
本文介绍了表值函数我的查询计划去了哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在 SQLServer 2000 上的表值函数中包装了一个复杂的 SQL 语句.在查看 SELECT * FROM dbo.NewFunc 的查询计划时,它只为我提供了我创建的表的表扫描.

I've just wrapped a complex SQL Statement in a Table-valued function on SQLServer 2000. When looking at the Query Plan for a SELECT * FROM dbo.NewFunc it just gives me a Table Scan of the table I have created.

我猜这是因为表是在 tempdb 中创建的,而我只是从中进行选择.

I'm guessing that this is because table is created in tempdb and I am just selecting from it.

所以查询很简单:

SELECT * FROM table in tempdb

我的问题是:

UDF 是否使用与复杂 SQL 语句相同的计划?

Is the UDF using the same plan as the complex SQL statement?

如何调整此 UDF 的索引?

How can I tune indexes for this UDF?

我能看到真正的计划吗?

Can I see the true plan?

推荐答案

多语句表值函数 (TVF) 是外部查询优化器的黑匣子.您只能从分析器中看到 IO、CPU 等.

Multi-statement table valued functions (TVF) are black boxes to the optimiser for the outer query. You can only see IO, CPU etc from profiler.

TVF 必须运行完成并在任何处理发生之前返回所有行.例如,这意味着不会优化 where 子句.

The TVF must run to completion and return all rows before any processing happens. That means a where clause will not be optimised for example.

所以如果这个 TVF 返回一百万行,它已经被先排序了.

So if this TVF returns a million rows, it has be sorted first.

SELECT TOP 1 x FROM db.MyTVF ORDER BY x DESC

单个语句/内联 TVF 不会受到影响,因为它们像宏一样被扩展和评估.上面的例子将评估索引等.

Single statement/inline TVFs do not suffer because they are expanded like macros and evaluated. The example above would evaluate indexes etc.

也在这里:查询计划优化器是否适用于连接/过滤的表值函数?Microsoft SQL Server 2008 中 JOIN 与 APPLY 的相对效率

准确回答:不,不,不

我的多语句 TVF 很少:在我做的地方,我有很多参数要在 UDF 中过滤.

I have very few multi statement TVFs: where I do, I have lots of parameters to filter inside the UDF.

这篇关于表值函数我的查询计划去了哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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