查询与查看 [英] Query vs. View

查看:9
本文介绍了查询与查看的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道查询和视图在性能方面的区别是什么.如果视图成本很高,除了查询之外,我还能做什么来提高性能?

I want to know what is the difference between a query and a view in terms of performance. And if a view is costly, what else besides a query could I do to improve performance?

推荐答案

在简单的情况下,视图和即席查询在性能方面几乎相同.如此之多以至于当您使用视图编程时,您应该将其视为视图定义的文本被剪切并粘贴到您的父查询中.

Views and ad-hoc queries, in the simple case, are nearly identical in terms of performance. So much so that when you program with a view, you should think of it as though the text of the view definition were being cut and pasted into your parent query.

HLGEM 在他的回答中指出,某些版本的 SQL Server 允许您索引"视图——在这种情况下,SQL Server 在幕后维护作为表基础的相同结构,使得索引视图和表非常性能方面相似.

HLGEM points out in his answer that certain editions of SQL Server allows you to "index" views -- in this case, behind the scenes SQL Server maintains the same structures that underlie a table, making an indexed view and a table very similar in terms of performance.

在 SQL Server 中,虽然您通常可以相当自由地嵌套视图而不会遇到性能问题,但它会使事情更难以理解和调试.

In SQL Server, though you can generally nest views fairly liberally without running into performance problems, it can make things more difficult to understand and debug.

这篇关于查询与查看的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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