You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Stored_Procedure/dbo.sp_BenchmarkTSQL.sql
+35-24Lines changed: 35 additions & 24 deletions
Original file line number
Diff line number
Diff line change
@@ -21,40 +21,51 @@ ALTER PROCEDURE dbo.sp_BenchmarkTSQL(
21
21
)
22
22
/*
23
23
.SYNOPSIS
24
-
Run TSQL statement @numberOfExecution times and calculate execution time, save results if needed or print it.
24
+
Run TSQL statement @numberOfExecution times and calculate each execution time, save results if needed or print it.
25
25
26
26
.DESCRIPTION
27
27
Run SQL statement specified times, show results, insert execution details into log table master.dbo.BenchmarkTSQL.
28
28
29
29
.PARAMETER @tsqlStatementBefore
30
-
TSQL statement that executed before tested main TSQL statement - not taken into account when measuring @tsqlStatement. Default is NULL.
30
+
TSQL statement that executed before tested main TSQL statement - not taken into account when measuring @tsqlStatement.
31
+
Default value is NULL.
31
32
32
33
.PARAMETER @tsqlStatement
33
34
TSQL statement for benchmarking. Mandatory parameter.
35
+
No defaults.
34
36
35
37
.PARAMETER @tsqlStatementAfter
36
-
TSQL statement that executed after tested TSQL statement - not taken into account when measuring @tsqlStatement. Default is NULL.
38
+
TSQL statement that executed after tested TSQL statement - not taken into account when measuring @tsqlStatement.
39
+
Default value is NULL.
37
40
38
41
.PARAMETER @numberOfExecution
39
42
Number of execution TSQL statement.
43
+
Default value is 10.
40
44
41
45
.PARAMETER @saveResults
42
-
Save benchmark details to master.dbo.BenchmarkTSQL table if @saveResults = 1. Create table if not exists (see 301 line: CREATE TABLE master.dbo.BenchmarkTSQL …).
46
+
Save benchmark details to master.dbo.BenchmarkTSQL table if @saveResults = 1.
47
+
Create table if not exists (see 301 line: CREATE TABLE master.dbo.BenchmarkTSQL …).
48
+
Default value is 0 - not saved.
43
49
44
50
.PARAMETER @skipTSQLCheck
45
-
Checking for valid TSQL statement. Default value is 1 (true) - skip checking.
51
+
Checking for valid TSQL statement.
52
+
Default value is 1 (true) - skip checking.
46
53
47
54
.PARAMETER @clearCache
48
-
Clear cached plan for TSQL statement. Default value is 0 (false) - not clear.
55
+
Clear cached plan for TSQL statement before each run.
56
+
Default value is 0 (false) - not clear.
49
57
50
58
.PARAMETER @calcMedian
51
-
Calculate pseudo median of execution time. Default value is 0 (false) - not calculated.
59
+
Calculate pseudo median of all execution times.
60
+
Default value is 0 (false) - not calculated.
52
61
53
62
.PARAMETER @printStepInfo
54
-
PRINT detailed step information: step count, start time, end time, duration. Default value is 0.
63
+
PRINT detailed step information: step count, start time, end time, duration.
64
+
Default value is 0 - not printed.
55
65
56
66
.PARAMETER @durationAccuracy
57
-
Duration accuracy calculation, possible values for this stored procedure parameter: ns, mcs, ms, ss, mi, hh, dd, wk. Default value is ss - seconds.
67
+
Duration accuracy calculation, possible values for this stored procedure parameter: ns, mcs, ms, ss, mi, hh, dd, wk.
68
+
Default value is ss - seconds.
58
69
See DATEDIFF https://docs.microsoft.com/en-us/sql/t-sql/functions/datediff-transact-sql
59
70
60
71
.PARAMETER @dateTimeFunction
@@ -127,7 +138,7 @@ ALTER PROCEDURE dbo.sp_BenchmarkTSQL(
127
138
128
139
.EXAMPLE
129
140
WITH CTE AS (
130
-
SELECT TSQLStatementGUID
141
+
SELECTTSQLStatementGUID
131
142
, StartBenchmark
132
143
, EndBenchmark
133
144
, ClearCache
@@ -161,10 +172,10 @@ ALTER PROCEDURE dbo.sp_BenchmarkTSQL(
161
172
, TsqlStatementAfter
162
173
, OriginalLogin
163
174
, AdditionalInfo
164
-
FROMmaster.dbo.BenchmarkTSQL
165
-
WHERE TSQLStatementGUID IN ('D34C4BD6-01B8-4C9C-B627-E3C26F84D9FA', '02DF082C-7D3D-450E-B125-C738F015B35A')
175
+
FROMmaster.dbo.BenchmarkTSQL
176
+
WHERETSQLStatementGUID IN ('D34C4BD6-01B8-4C9C-B627-E3C26F84D9FA', '02DF082C-7D3D-450E-B125-C738F015B35A')
166
177
)
167
-
SELECT TSQLStatementGUID
178
+
SELECTTSQLStatementGUID
168
179
, StartBenchmark
169
180
, EndBenchmark
170
181
, ClearCache
@@ -176,23 +187,23 @@ ALTER PROCEDURE dbo.sp_BenchmarkTSQL(
176
187
, MAX(StepDuration) AS StepDurationMAX
177
188
, AVG(StepDuration) AS StepDurationAVG
178
189
, TsqlStatement
179
-
FROM CTE
180
-
GROUP BY TSQLStatementGUID
181
-
, StartBenchmark
182
-
, EndBenchmark
183
-
, ClearCache
184
-
, PrintStepInfo
185
-
, DurationAccuracy
186
-
, BenchmarkDuration
187
-
, TsqlStatement;
190
+
FROMCTE
191
+
GROUP BY TSQLStatementGUID
192
+
, StartBenchmark
193
+
, EndBenchmark
194
+
, ClearCache
195
+
, PrintStepInfo
196
+
, DurationAccuracy
197
+
, BenchmarkDuration
198
+
, TsqlStatement;
188
199
189
200
.LICENSE MIT
190
201
Permission is here by granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights touse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, andto permit persons to whom the Software is furnished to do so, subjectto the following conditions:
191
202
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
192
203
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. INNOEVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF ORIN CONNECTION WITH THE SOFTWARE OR THE USEOR OTHER DEALINGS IN THE SOFTWARE.
193
204
194
205
.NOTE
195
-
Version: 5.5
206
+
Version: 5.7
196
207
Created: 2017-12-14by Konstantin Taranov
197
208
Modified: 2019-04-18by Konstantin Taranov
198
209
Main contributors: Konstantin Taranov, Aleksei Nagorskii
@@ -632,7 +643,7 @@ BEGIN CATCH
632
643
'. Try to use @durationAccuracy with a less precise datepart - seconds (ss) or minutes (mm) or days (dd).'+ @crlf +
633
644
'But in log table master.dbo.BenchmarkTSQL (if you run stored procedure with @saveResult = 1) all times saving with datetime2(7) precise!'+ @crlf +
634
645
'You can manualy calculate difference after decreasing precise datepart.'+ @crlf +
635
-
'For analyze log table see latest examples in document section.') + @crlf ++ @crlf;
646
+
'For analyze log table see latest example in document section.') + @crlf ++ @crlf;
0 commit comments