Quickest way to identify most used Stored Procedure variation in SQL Server 2005

后端 未结 4 2114
醉话见心
醉话见心 2021-02-14 23:28

I am trying to figure out if there\'s a way to identify a \"version\" of a SP that gets called the most. I have an SP that gets called with a bunch of different parameters. I kn

4条回答
  •  北海茫月
    2021-02-15 00:03

    It sounds like you only need to be able to capture this information for a short period of time. The sproc may be called a large number of times during that period, but it's a finite period.

    If that is the case, perhaps you could log the sproc calls somewhere? If you have control over the sproc code, you could perform the logging there. One approach would be to create a special table for this purpose, add an INSERT to that table at the beginning or end of the existing sproc, and wait for some records to accumulate in the table.

    Depending on the specifics, you could create a column in the custom logging table for each sproc parameter.

    Then you'd have ample information about the usage of the sproc, for the period of time you perform the logging.

    Given the data accumulated in the table, you could query to find the most frequent parameter values, which users or applications or web pages, etc. are entailed, the datetimes for the beginning and ending of the sproc call, and whatever else you log.

    This would not involve any changes to the application code, and it could be completely eliminated after you have completed your troubleshooting. So, aside from the inevitable performance hit of all that logging, the price of this approach is not high.

    Edit: This approach would be an alternative for users who lack the special permissions required to run DMV queries on tables such as sys.dm_exec_query_stats. In many shops, getting such permissions -- particularly on production databases -- is not feasible for developers.

提交回复
热议问题