Inside Microsoft® SQL Server™ 2005: Query Tuning and Optimization
by Kalen Delaney, Sunil Agarwal, Craig Freedman, Ron Talmage, Adam Machanic
Caching Mechanisms
SQL Server can avoid compilations of previously executed queries by using four mechanisms to make plan caching accessible in a wide set of situations.
Adhoc query caching
Autoparameterization
Prepared queries, using either sp_executesql or the prepare and execute method invoked through your API
Stored procedures or other compiled objects (triggers, TVFs, etc.)
To determine which mechanism is being used for each plan in cache, we need to look at the values in the cacheobjtype and objtype columns in the sys.dm_exec_cached_plans view. The cacheobjtype column can have one of five possible values:
Compiled Plan
Parse Tree
Extended Proc
CLR Compiled Func
CLR Compiled Proc
In this section, the only value we’ll be looking at is Compiled ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access