MSSQLTips.com - your daily source for SQL Server tips

Google
 
Web mssqltips.com

ESSENTIALS: Home | Tips | Search | Categories | Top 10 | Products | Authors | Blogs | Forums | Webcasts | Advertise | About
Determining which procedures execute the most often - MSSQLTips

MSSQLTips

MSSQLTips.com - your daily source for SQL Server tips
Welcome to MSSQLTips Sign in | Join | Help
in Search

Determining which procedures execute the most often

Last post 11-04-2008 2:48 PM by bkshilo. 6 replies.
Page 1 of 1 (7 items)
Sort Posts: Previous Next
  • 11-03-2008 9:51 AM

    Determining which procedures execute the most often

    I'm planning on doing some stored procedure performance tuning.  It makes sense to concentrate first on the SP's that get executed the most often, as saving a couple of seconds could quickly add up.

     

    What is the best/easiest way to determine which SP's are getting executed the most frequently?

  • 11-03-2008 6:00 PM In reply to

    • aprato
    • Top 10 Contributor
    • Joined on 12-01-2007
    • Greater Boston
    • Posts 296

    Re: Determining which procedures execute the most often

     Which version of SQL Server?

  • 11-04-2008 7:13 AM In reply to

    Re: Determining which procedures execute the most often

    2005 SP2

  • 11-04-2008 7:40 AM In reply to

    • aprato
    • Top 10 Contributor
    • Joined on 12-01-2007
    • Greater Boston
    • Posts 296

    Re: Determining which procedures execute the most often

     The DMVs hold a wealth of information

    This query shows the queries in the procedure cache with the greatest usecounts


    select qs.refcounts, qs.usecounts, cacheobjtype, objtype, qt.text
    from sys.dm_exec_cached_plans qs
    cross apply sys.dm_exec_sql_text(qs.plan_handle) as qt
    order by qs.usecounts desc
    go

     

  • 11-04-2008 10:39 AM In reply to

    Re: Determining which procedures execute the most often

    I love it when smart people point me towards an answer.

     

    What would I then join to in order to get the DB_id and the object_id of the stored procs?

  • 11-04-2008 12:39 PM In reply to

    • aprato
    • Top 10 Contributor
    • Joined on 12-01-2007
    • Greater Boston
    • Posts 296

    Re: Determining which procedures execute the most often

     Hi

     The id's can be found within sys.dm_exec_sql_text and converted.  For ad-hoc or prepared queries, they'll be NULL

    select db_name(qt.dbid), object_name(qt.objectid), qs.refcounts, qs.usecounts, cacheobjtype, objtype, qt.text
    from sys.dm_exec_cached_plans qs
    cross apply sys.dm_exec_sql_text(qs.plan_handle) as qt
    order by qs.usecounts desc
    go

     

  • 11-04-2008 2:48 PM In reply to

    Re: Determining which procedures execute the most often

    Thank you, O Wise One

Page 1 of 1 (7 items)