Asha
Asha

Reputation: 4311

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

Upvotes: 0

Views: 480

Answers (1)

anon
anon

Reputation:

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.

Upvotes: 1

Related Questions