是一个

select *  from myView

比查询本身更快地创建视图(为了拥有相同的resultSet):

select * from ([query to create same resultSet as myView])

?

我不完全清楚视图是否使用了某种缓存,使其比简单查询更快。


当前回答

没有实际的区别,如果你读BOL,你会发现你的普通旧SQL SELECT * FROM X确实利用了计划缓存等。

其他回答

我无意中看到了这个帖子,只是想分享Brent Ozar的这篇文章,作为使用可用性组时的考虑。

布伦特·欧扎尔报道

存储执行计划应该会有一些微不足道的好处,但可以忽略不计。

在我的发现中,使用视图比普通查询要快一些。我的存储过程大约花了25分钟(使用不同的更大的记录集和多个连接),在使用视图(非集群)后,性能稍微快了一点,但并不显著。我不得不使用一些其他的查询优化技术/方法来做出巨大的改变。

对于SQL Server来说,视图肯定比嵌套查询要好。在不知道为什么它更好的情况下(直到我读到Mark Brittingham的文章),我已经运行了一些测试,在使用视图和嵌套查询时,我经历了几乎惊人的性能提升。在连续运行查询的每个版本数百次之后,查询的视图版本在一半的时间内完成。我得说这对我来说已经足够了。

In SQL Server at least, Query plans are stored in the plan cache for both views and ordinary SQL queries, based on query/view parameters. For both, they are dropped from the cache when they have been unused for a long enough period and the space is needed for some other newly submitted query. After which, if the same query is issued, it is recompiled and the plan is put back into the cache. So no, there is no difference, given that you are reusing the same SQL query and the same view with the same frequency.

显然,在一般情况下,一个视图,根据它的本质(有人认为它被经常使用,使它成为一个视图)通常比任何任意的SQL语句更有可能被“重用”。