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
+51-22Lines changed: 51 additions & 22 deletions
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,4 @@
1
-
IFOBJECT_ID('dbo.sp_BenchmarkTSQL', 'P') ISNULL
2
-
EXECUTE ('CREATE PROCEDURE dbo.sp_BenchmarkTSQL AS SELECT 1;');
1
+
IFOBJECT_ID('dbo.sp_BenchmarkTSQL', 'P') ISNULLEXEC('CREATE PROCEDURE dbo.sp_BenchmarkTSQL AS SELECT 1;');
3
2
GO
4
3
5
4
@@ -12,7 +11,7 @@ ALTER PROCEDURE dbo.sp_BenchmarkTSQL(
12
11
, @skipTSQLCheck BIT=1
13
12
, @clearCache BIT=0
14
13
, @calcMedian BIT=0
15
-
, @printStepInfo BIT=1
14
+
, @printStepInfo BIT=0
16
15
, @durationAccuracy VARCHAR(5) ='ss'
17
16
, @dateTimeFunction VARCHAR(16) ='SYSDATETIME'
18
17
, @additionalInfo BIT=0
@@ -37,7 +36,7 @@ ALTER PROCEDURE dbo.sp_BenchmarkTSQL(
37
36
Number of execution TSQL statement.
38
37
39
38
.PARAMETER @saveResults
40
-
Save benchmark details to master.dbo.BenchmarkTSQL table if @saveResults = 1. Create table if not exists (see 243 line: CREATE TABLE master.dbo.BenchmarkTSQL …).
39
+
Save benchmark details to master.dbo.BenchmarkTSQL table if @saveResults = 1. Create table if not exists (see 246 line: CREATE TABLE master.dbo.BenchmarkTSQL …).
41
40
42
41
.PARAMETER @skipTSQLCheck
43
42
Checking for valid TSQL statement. Default value is 1 (true) - skip checking.
@@ -49,16 +48,19 @@ ALTER PROCEDURE dbo.sp_BenchmarkTSQL(
49
48
Calculate pseudo median of execution time. Default value is 0 (false) - not calculated.
50
49
51
50
.PARAMETER @printStepInfo
52
-
PRINT detailed step information: step count, start time, end time, duration.
51
+
PRINT detailed step information: step count, start time, end time, duration. Default value is 0.
53
52
54
53
.PARAMETER @durationAccuracy
55
54
Duration accuracy calculation, possible values for this stored procedure: ns, mcs, ms, ss, mi, hh, dd, wk. Default value is ss - seconds.
56
55
See DATEDIFF https://docs.microsoft.com/en-us/sql/t-sql/functions/datediff-transact-sql
57
56
58
57
.PARAMETER @dateTimeFunction
59
-
Define using datetime function, possible values of functions: SYSDATETIME, SYSUTCDATETIME.
58
+
Define using datetime function, possible values of functions: SYSDATETIME, SYSUTCDATETIME. Default value is SYSDATETIME.
60
59
See https://docs.microsoft.com/en-us/sql/t-sql/functions/date-and-time-data-types-and-functions-transact-sql
61
60
61
+
.PARAMETER @additionalInfo
62
+
Save additional session parameteres (ANSI_WARNINGS, XACT_ABORT and etc) to XML column AdditionalInfo in log table master.dbo.BenchmarkTSQL. Default value is 0.
63
+
62
64
.EXAMPLE
63
65
EXEC sp_BenchmarkTSQL
64
66
@tsqlStatement = 'SELECT * FROM , sys.databases;'
@@ -126,9 +128,9 @@ The above copyright notice and this permission notice shall be included in all c
126
128
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.
127
129
128
130
.NOTE
129
-
Version: 5.1
131
+
Version: 5.2
130
132
Created: 2017-12-14by Konstantin Taranov
131
-
Modified: 2019-03-28by Konstantin Taranov
133
+
Modified: 2019-04-18by Konstantin Taranov
132
134
Main contributors: Konstantin Taranov, Aleksei Nagorskii
133
135
Source: https://rebrand.ly/sp_BenchmarkTSQL
134
136
*/
@@ -173,10 +175,10 @@ BEGIN TRY
173
175
, 'dd'/* day */
174
176
, 'wk'/* week */
175
177
)
176
-
THROW55004, '@durationAccuracy accept only this values: ns, mcs, ms, ss, mi, hh, wk, dd. See DATEDIFF https://docs.microsoft.com/en-us/sql/t-sql/functions/datediff-transact-sql' , 1;
178
+
THROW55004, '@durationAccuracy accept only this values: ns, mcs, ms, ss, mi, hh, wk, dd. Default value is ss. See DATEDIFF https://docs.microsoft.com/en-us/sql/t-sql/functions/datediff-transact-sql' , 1;
177
179
178
180
IF @dateTimeFunction NOTIN ('SYSDATETIME', 'SYSUTCDATETIME')
179
-
THROW55005, '@dateTimeFunction accept only SYSUTCDATETIME and SYSDATETIME, default is SYSDATETIME. See https://docs.microsoft.com/en-us/sql/t-sql/functions/date-and-time-data-types-and-functions-transact-sql', 1;
181
+
THROW55005, '@dateTimeFunction accept only SYSDATETIME and SYSUTCDATETIME. Default value is SYSDATETIME. See https://docs.microsoft.com/en-us/sql/t-sql/functions/date-and-time-data-types-and-functions-transact-sql', 1;
180
182
181
183
IF @numberOfExecution <=0OR @numberOfExecution >=32000
182
184
THROW55006, '@numberOfExecution must be > 0 and < 32000. If you want more execution then comment 180 and 181 lines.', 1;
@@ -336,15 +338,36 @@ BEGIN TRY
336
338
WHEN @dateTimeFunction ='SYSUTCDATETIME'THENSYSUTCDATETIME()
'. Try to use @durationAccuracy with a less precise datepart - seconds (ss) or minutes (mm) or days (dd).'+ @crlf +
550
-
'But in log table master.dbo.BenchmarkTSQL all times saving with DATETIME2(7) precise! You can manualy calculate difference after decreasing precise datepart.'+ @crlf +
551
-
'For analyze log rable see latest example in document section.');
575
+
'But in log table master.dbo.BenchmarkTSQL (if you run stored procedure with @saveResult = 1) all times saving with DATETIME2(7) precise!'+ @crlf +
576
+
'You can manualy calculate difference after decreasing precise datepart.'+ @crlf +
577
+
'For analyze log table see latest examples in document section.');
0 commit comments