SQL Server Plan Cache is a critical memory component that stores query execution plans, facilitating plan reuse to enhance query performance and reduce overhead in generating new plans, ultimately optimizing database performance.

When you execute a query for the first time, it will be compiled and query plan will be generated for each query. It uses memory to store objects like stored procedure, triggers, adhoc and prepared T-SQL statements.

These two behave exactly the same way,

> possibly auto parameterized statements.

> EXECUTE (@string)

> Client side from ODBC & OLEDB

> SQLPrepare, SQLExecute and iCommandPrepare


> Aggregate by query_hash to find similar queries.

> Aggregate by query_hash & query_plan_hash to find similar queries together with their plan.

> Stored procedure, function, triggers ...

> Generally desirable

> Adhoc SQL Statements (including parameterized)

> Prepared statements

> OK when highly reused but often not

> Views, constraints and defaults

> Usually OK

> SQL 2008+ and SQL 2005 SP2

> SQL 2005 RTM and SQL 2005 SP1

> SQL 2000


> When different parameters do not change the optimal plan, then saving and reusing is excellent.

> SQL Server saves time in compilation.

> When different parameters wildly change the size of the result set and the optimal plans vary, then reusing the plan can be horribly bad.

> If statistics are added to base tables, existing plans may not leverage them.


Why?

Do we need to this in every procedure?

Statement-level recompilation

Note: This is a short term fix - You must dig deeper in fixing query bottleneck.