Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear cache of 1 stored procedure in sql server

Tags:

sql-server

I am using SQL Server 2008 R2.

I know that DBCC FREEPROCCACHE will clear cache of all stored procedures in SQL Server.

But what I need is to clear cache of only 1 stored procedure. How can I do that?

The Stored Procedure name is Rpt_RegionReport. I don't want to execute the stored procedure with WITH RECOMPILE option.

like image 291
srh Avatar asked Jun 02 '15 13:06

srh


People also ask

How do you clear the execution plan cache in SQL Server for a stored procedure?

We can use the DBCC FREEPROCCACHE command to clear the procedural cache in SQL Server. We might drop a single execution plan or all plans from the buffer cache. SQL Server needs to create new execution plans once the user reruns the query.

How do I flush a SQL query plan?

Purge the query plan cache from each Compute node and from the Control node. Starting with SQL Server 2016 (13. x), the ALTER DATABASE SCOPED CONFIGURATION CLEAR PROCEDURE_CACHE to clear the procedure (plan) cache for the database in scope.

What is DBCC Freeproccache?

Syntax. DBCC FREEPROCCACHE [ ( { plan_handle | sql_handle | pool_name } ) ] [ WITH NO_INFOMSGS ] plan handle uniquely identifies a query plan for a batch that has executed and whose plan resides in the plan cache. sql_handle is the SQL handle of the batch to be cleared.

How do you clear the buffer pool in SQL Server?

By cleaning the buffer pool before each test run SQL Server will have to re-read the data it needs from disk. To clean the buffer pool you execute the command: DBCC DROPCLEANBUFFERS. Next you should remove your execution plans from the procedure cache.


1 Answers

DBCC FreeProcCache has a single optional argument - the ID of the execution plan you want to delete.

You can find the plan you want to delete using sys.dm_exec_cached_plans, and then you can just use it as

DBCC FREEPROCCACHE (0x0123456....);
like image 169
Luaan Avatar answered Sep 18 '22 07:09

Luaan