July 18, 2012 at 6:24 am
Hi There,
I am looking to find when is a specific store procedure recomplied last time. Reason to find this is because database statistics updated everynight for the database but during the day this specific store procedure gives bad performance. If we recompile it works fine for the rest of the day. So something somewhere along the lines going wrong but I am not able to establish.
Thanks for your help in advance.
Imran
July 18, 2012 at 6:48 am
You can get that right out of the Dynamic Management Objects (DMO). This will get that piece of data:
SELECT deqs.creation_time FROM sys.dm_exec_query_stats AS deqs;
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
July 18, 2012 at 9:29 am
Thanks for your reply. I would be greatful if you can get me something where it give me the name of store procedure as well. When I am running this one it does not tell me the spr's.
sorry if I am asking wrong thing.
July 18, 2012 at 10:18 am
Cross apply to sys,dm_exec_sql_text
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
September 27, 2012 at 8:37 am
GilaMonster (7/18/2012)
Cross apply to sys,dm_exec_sql_text
This won't work if the sproc has the "WITH RECOMPILE" option in its definition.
Running the following on such a proc gives me nothing:
SELECT deqs.creation_time, dest.text
FROM sys.dm_exec_query_stats AS deqs
cross apply sys.dm_exec_sql_text(deqs.sql_handle) dest
where dest.text like '%PROCNAME%'
__________________________________________________________________________________
SQL Server 2016 Columnstore Index Enhancements - System Views for Disk-Based Tables[/url]
Persisting SQL Server Index-Usage Statistics with MERGE[/url]
Turbocharge Your Database Maintenance With Service Broker: Part 2[/url]
September 27, 2012 at 8:52 am
No it won't, because procs marked with recompile are never cached and hence never appear in the sys.dm_exec_query_stats DMV.
p.s. You don't need a LIKE match for the procedure name. Use OBJECT_NAME(object_id, database_id) = 'Proc Name'
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
September 27, 2012 at 1:50 pm
GilaMonster (9/27/2012)
No it won't, because procs marked with recompile are never cached and hence never appear in the sys.dm_exec_query_stats DMV.p.s. You don't need a LIKE match for the procedure name. Use OBJECT_NAME(object_id, database_id) = 'Proc Name'
Thanks, good point.
So is there a way to get the answer in that case? ie. when proc last recompiled (which would be same as last time it ran).
__________________________________________________________________________________
SQL Server 2016 Columnstore Index Enhancements - System Views for Disk-Based Tables[/url]
Persisting SQL Server Index-Usage Statistics with MERGE[/url]
Turbocharge Your Database Maintenance With Service Broker: Part 2[/url]
September 27, 2012 at 1:57 pm
SQL Trace or extended events (depending on version)
btw, That's not actually a recompile. It's considered to be a compile because there's no matching plan in cache. Recompiles are only when a cached plan is found to be invalid for whatever reason.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply