查询视图比直接执行SQL要慢吗?

前端之家收集整理的这篇文章主要介绍了查询视图比直接执行SQL要慢吗?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
场景:

我有3个表需要连接在一起,一个where子句来限制结果集,并且每个表中只有几列被选中.简单.但是,执行此操作的查询并不是很漂亮,并且在数据库和应用程序之间使用ORM时,它就像尝试将方形挂钩放入圆孔中一样.

解决这个问题的方法是创建一个包含查询的视图,现在我的应用程序模型直接映射到数据库中的视图;没有更多的疯狂映射ORM层.

题:
假设没有其他因素在这里发挥作用,对视图的查询是否会产生任何额外的性能损失,如果我直接执行sql语句,我将不会遇到这些惩罚? – 这不是索引视图,假设相同的where子句,保持这个简单.

我被引导相信一个观点遭受“正在建立”的额外开销.我的理解是,在其他所有情况相同的情况下,两者应具有相同的性能.

请澄清.谢谢!

解决方法

来自MSDN:
View resolution

When an sql statement references a nonindexed view,the parser and query optimizer analyze the source of both the sql statement and the view and then resolve them into a single execution plan. There is not one plan for the sql statement and a separate plan for the view.

不应该有任何不同的表现.视图可以帮助您组织,而不是任何性能增强.除非您使用索引视图.

Only the definition of a nonindexed view is stored,not the rows of the view. The query optimizer incorporates the logic from the view definition into the execution plan it builds for the sql statement that references the nonindexed view.

原文链接:https://www.f2er.com/mssql/78687.html

猜你在找的MsSQL相关文章