简体   繁体   English

SQL Server 2008子查询缓存?

[英]SQL Server 2008 sub-query caching?

If I run the following query multiple times on SQL Server 2008 does it cache the result of the inner query (my complicated select query) after first time? 如果我在SQL Server 2008上多次运行以下查询,是否在第一次之后就缓存内部查询(我的复杂选择查询)的结果?

Or is it running that query every time with a new n and m values? 还是每次使用新的n和m值运行该查询?

SELECT * FROM (
   SELECT *, ROW_NUMBER() OVER (ORDER BY x.id) AS rowID 
   FROM (*My complicated select Query* ORDER BY id) x
 ) y WHERE y.rowID BETWEEN n AND m

This will depend on a variety of factors, including settings for parameterization (simple/forced etc), the "optimize for ad hoc workloads" setting, amount of memory, complexity of query, what's in the cache, how often plans get cycled out, etc. Note that there is a big difference between "caching the result" (which doesn't happen) and "caching and re-using a plan" (which can). 这将取决于多种因素,包括参数化设置(简单/强制等),“针对临时工作负载进行优化”设置,内存量,查询的复杂性,缓存中的内容,计划的循环频率,请注意,“缓存结果”(不会发生)和“缓存并重新使用计划”(可以)之间存在很大差异。 Caching the results doesn't really make sense unless your database (or the filegroup where this table has been created) has been set to read only. 除非将数据库(或创建此表的文件组)设置为只读,否则缓存结果实际上没有任何意义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM