内联函数和视图之间的区别 [英] Difference between a inline function and a view

查看:26
本文介绍了内联函数和视图之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是使用函数的新手,在我看来,内联函数与视图非常相似.我说的对吗?

I am a newbie in using functions and it appears to me that an inline function is very similar to a view. Am I correct?

另外,我可以在函数中使用 UPDATE 语句吗?

Also, can I have UPDATE statements within a function?

推荐答案

在阅读了这里的许多答案后,我想指出内联表值函数与任何其他类型的函数之间存在很大差异(标量或多行 TVF).

After reading many of the answers here, I'd like to note that there is a big difference between an inline table-valued function and any other kind of function (scalar or multi-line TVF).

内联 TVF 只是一个参数化视图.它可以像视图一样扩展和优化.在返回结果"或类似的东西之前不需要具体化任何东西(尽管不幸的是,语法有一个 RETURN.

An inline TVF is simply a parameterized view. It can be expanded and optimized away just like a view. It is not required to materialize anything before "returning results" or anything like that (although, unfortunately, the syntax has a RETURN.

我发现内联 TVF 相对于视图的一大好处是它确实强制要求参数化,而对于视图,您必须假设调用者将适当地加入或限制视图的使用.

A big benefit I've found of an inline TVF over a view is that it does force required parameterization whereas with a view, you have to assume that the caller will appropriately join or restrict the usage of the view.

例如,我们在 DW 中有许多具有典型 Kimball 星型模型的大型事实表.我对以事实表为中心的模型有一个看法,该模型不受任何限制地调用,将返回数亿行.通过使用具有适当参数化的内联 TVF,用户不会意外地请求所有行.两者的性能在很大程度上没有区别.

For example, we have many large fact tables in DW with a typical Kimball star model. I have a view on a fact table-centered model, which called without any restriction, will return hundreds of millions of rows. By using an inline TVF with appropriate parameterization, users are unable to accidentally ask for all the rows. Performance is largely indistinguishable between the two.

这篇关于内联函数和视图之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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