是一个
select * from myView
比查询本身更快地创建视图(为了拥有相同的resultSet):
select * from ([query to create same resultSet as myView])
?
我不完全清楚视图是否使用了某种缓存,使其比简单查询更快。
是一个
select * from myView
比查询本身更快地创建视图(为了拥有相同的resultSet):
select * from ([query to create same resultSet as myView])
?
我不完全清楚视图是否使用了某种缓存,使其比简单查询更快。
当前回答
没有实际的区别,如果你读BOL,你会发现你的普通旧SQL SELECT * FROM X确实利用了计划缓存等。
其他回答
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语句更有可能被“重用”。
如果创建物化视图(带有模式绑定),可能会更快。非物化视图的执行就像常规查询一样。
没有实际的区别,如果你读BOL,你会发现你的普通旧SQL SELECT * FROM X确实利用了计划缓存等。
在我的发现中,使用视图比普通查询要快一些。我的存储过程大约花了25分钟(使用不同的更大的记录集和多个连接),在使用视图(非集群)后,性能稍微快了一点,但并不显著。我不得不使用一些其他的查询优化技术/方法来做出巨大的改变。
从视图或表中选择没有太大意义。
当然,如果视图没有不必要的连接、字段等。您可以检查用于提高View性能的查询、连接和索引的执行计划。
您甚至可以为更快的搜索需求在视图上创建索引。http://technet.microsoft.com/en-us/library/cc917715.aspx
但是如果你搜索'%…SQL引擎将不能从文本列上的索引中获益。如果你能强迫你的用户进行类似“……比那快多了
参考asp论坛上的回答: https://forums.asp.net/t/1697933.aspx?Which+is+faster+when+using+SELECT+query+VIEW+or+Table+