HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

Best way(s) to time ad hoc queries and stored procedures

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
storedproceduresbestwaytimeandquerieshoc

Problem

What are the most accepted ways to time your queries, whether they are ad hoc or stored procedures?

Is it more accurate to use SQL Profiler than SET STATISTICS TIME ON?

Solution

Profiler is easier to understand (all in one line) and will capture hidden IO, CPU etc in UDFs (scalar and multi-statement TVFs)

SET STATISTICS TIME ON and SET STATISTICS IO ON will not show you IO and CPU from scalar UDFs and multi-statement TVFs: only the "outer" query statistics

From SO:

  • SQL Server Profiler discrepancy



  • Table Valued Function where did my query plan go?



  • Does query plan optimizer works well with joined/filtered table-valued functions?



And no doubt some folk will disagree with me, so here is Adam Machanic on the subject too

  • Scalar functions, inlining, and performance

Context

StackExchange Database Administrators Q#5325, answer score: 4

Revisions (0)

No revisions yet.