Is there a measure of time frame as to which the execution plan of inline queries will cached?
+4
A:
There is an algorithm (will find it), but practically it will stay there:
- while being used (Edit: See AdaTheDev's answer)
- until statistics update (also implied by index rebuild)
- until definition changes (including whitespace and case)
- SQL instance restart
- until severe memory pressure
gbn
2010-02-04 12:14:23
The stats update will invalidate the plan, but doesn't immediately remove it bizarrely.
Andrew
2010-02-04 12:19:08
yes, seen that. also ALTER PROC (get "definition has been changed or similar' error).
gbn
2010-02-04 12:25:45
+1 for main points + article
AdaTheDev
2010-02-04 12:33:25
+3
A:
As gbn said, there is an algorithm. Just to add that the length of time a plan will be cached for also relates to how valuable a plan is deemed to be and how often it is used (if it's a higher value plan, and it keeps getting used then it's value is very high so will be more likely to be held for longer than other plans)
AdaTheDev
2010-02-04 12:19:56