简体   繁体   中英

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?

Or is it running that query every time with a new n and m values?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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