You have a small workaround here...
select * from stdCustomers where custpincode ='363 423'SCRIPT :2
SELECT Q.plan_handle 'Plan Handle',
Do the following steps:
convert(varchar,Q.creation_time,120) 'Plan Created at' ,
convert(varchar,Q.last_execution_time,120) 'Plan Reused at',
Q.execution_count 'Plan Reused Count'
FROM sys.dm_exec_query_stats Q CROSS APPLY sys.dm_exec_sql_text(Q.PLAN_HANDLE) e
WHERE e.[text] LIKE 'select * from stdCustomers where custpincode =%'
Run the SCRIPT :2, If it returns any row then you have to Remove the Row(PLAN) from the Plan Cache.
Just copy the "Plan Handle" data from the step 1 (ie. 0x06000800244.........)
Run the script given below to remove the existing Plan from the Plan Cache
DBCC FREEPROCCACHE(Plan Handle)
ie: DBCC FREEPROCCACHE(0x06000800244.........)
The result will be "DBCC execution completed. If DBCC printed error messages, contact your system administrator."
Run the SCRIPT :2, it should not return any row. If returns, do the steps 2,3,4
Run the SCRIPT :1
Run the SCRIPT :2, If it returns any row then, do the following analysis.
If "Plan Created at" and "Plan Reused at" columns are SAME date and "Plan Reused Count" is 1 then "THE IS NEWLY CREATED PLAN".
If "Plan Created at" and "Plan Reused at" columns are NOT SAME date and "Plan Reused Count" is >1 then "THE PLAN REUSED N-1 TIMES" (here N is nothing but, "Plan Reused Count" value)
Whenever you run the SCRIPT :2, It will return "Plan Created at" and "Plan Reused at" and "Plan Reused Count" is >1.
If you want to generate a New Plan then, You have to remove the existing Plan from the Plan Cache.
Follow the steps 1,2,3
If the "Plan Reused Count" is >1 then The "PLAN IS REUSED". The "Plan Reused at" column tells when was the Plan Re-used for this query.
I think this is clear about Generating / Re-Using the Plan.
If you need any clarifications, Pls get back....
This script applicable only in SQL Server 2005/2008/2008 R2.
CheersDevanand, if this helps please login to Mark As Answer. | Alert Moderator