Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

when store procedure recompiled last time Expand / Collapse
Author
Message
Posted Wednesday, July 18, 2012 6:24 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Monday, September 8, 2014 3:14 AM
Points: 43, Visits: 233
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
Post #1331413
Posted Wednesday, July 18, 2012 6:48 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 9:47 AM
Points: 13,872, Visits: 28,270
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
The Scary DBA
Author of: SQL Server Query Performance Tuning
SQL Server 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans

Product Evangelist for Red Gate Software
Post #1331428
Posted Wednesday, July 18, 2012 9:29 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Monday, September 8, 2014 3:14 AM
Points: 43, Visits: 233
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.
Post #1331560
Posted Wednesday, July 18, 2012 10:18 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 4:08 PM
Points: 40,177, Visits: 36,580
Cross apply to sys,dm_exec_sql_text


Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #1331611
Posted Thursday, September 27, 2012 8:37 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Wednesday, October 8, 2014 12:34 PM
Points: 1,865, Visits: 3,615
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%'



__________________________________________________________________________________

Turbocharge Your Database Maintenance With Service Broker: Part 2
Turbocharge Your Database Maintenance With Service Broker: Part 1
Real-Time Tracking of Tempdb Utilization Through Reporting Services
Monitoring Database Blocking Through SCOM 2007 Custom Rules and Alerts
Preparing for the Unthinkable - a Disaster/Recovery Implementation
Post #1365309
Posted Thursday, September 27, 2012 8:52 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 4:08 PM
Points: 40,177, Visits: 36,580
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 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #1365324
Posted Thursday, September 27, 2012 1:50 PM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Wednesday, October 8, 2014 12:34 PM
Points: 1,865, Visits: 3,615
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).


__________________________________________________________________________________

Turbocharge Your Database Maintenance With Service Broker: Part 2
Turbocharge Your Database Maintenance With Service Broker: Part 1
Real-Time Tracking of Tempdb Utilization Through Reporting Services
Monitoring Database Blocking Through SCOM 2007 Custom Rules and Alerts
Preparing for the Unthinkable - a Disaster/Recovery Implementation
Post #1365485
Posted Thursday, September 27, 2012 1:57 PM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 4:08 PM
Points: 40,177, Visits: 36,580
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 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #1365490
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse