', qsp.query_plan)
- ) AS xml
+ N'' +
+ REPLACE(prefix.param_prefix, N',', N'
') +
+ N'
' AS xml
)
-) AS x
-CROSS APPLY x.parameter_list_xml.nodes(N'declare namespace p="http://schemas.microsoft.com/sqlserver/2004/07/showplan"; //p:ParameterList/p:ColumnReference') AS cr(c)
-WHERE TRY_CAST(qsp.query_plan AS xml) IS NULL
-AND CHARINDEX(N'', qsp.query_plan) > 0
-AND x.parameter_list_xml IS NOT NULL
+) AS px
+CROSS APPLY px.param_xml.nodes(N'/p') AS p(param_text)
+WHERE NOT EXISTS
+(
+ SELECT
+ 1/0
+ FROM #query_parameters AS qp
+ WHERE qp.plan_id = qsp.plan_id
+ AND qp.parameter_name = LTRIM(RTRIM
+ (
+ LEFT
+ (
+ LTRIM(p.param_text.value(N'.', N'nvarchar(max)')),
+ CHARINDEX
+ (
+ N' ',
+ LTRIM(p.param_text.value(N'.', N'nvarchar(max)'))
+ ) - 1
+ )
+ ))
+)
+OPTION(RECOMPILE);
+
+/*
+Warn when parameters were missing from the plan ParameterList
+*/
+INSERT
+ #reproduction_warnings
+WITH
+ (TABLOCK)
+(
+ plan_id,
+ warning_type,
+ warning_message
+)
+SELECT DISTINCT
+ qp.plan_id,
+ warning_type = N'missing parameter values',
+ warning_message =
+ N'Some parameters declared in the query text were not found in the plan ParameterList. ' +
+ N'Their values are set to ? and must be filled in manually before executing.'
+FROM #query_parameters AS qp
+WHERE qp.parameter_compiled_value = N'?'
OPTION(RECOMPILE);
/*
@@ -35141,7 +36145,7 @@ BEGIN CATCH
END;
THROW;
-END CATCH
+END CATCH;
IF @debug = 1
BEGIN
@@ -35392,8 +36396,8 @@ BEGIN TRY
These are for your outputs.
*/
SELECT
- @version = '6.1',
- @version_date = '20260201';
+ @version = '6.3',
+ @version_date = '20260301';
/*
Helpful section! For help.
@@ -35479,7 +36483,7 @@ BEGIN
CASE
ap.name
WHEN N'@database_name' THEN 'a database name with query store enabled'
- WHEN N'@sort_order' THEN 'cpu, logical reads, physical reads, writes, duration, memory, tempdb, executions, recent, plan count by hashes, cpu waits, lock waits, locks waits, latch waits, latches waits, buffer latch waits, buffer latches waits, buffer io waits, log waits, log io waits, network waits, network io waits, parallel waits, parallelism waits, memory waits, total waits, rows'
+ WHEN N'@sort_order' THEN 'cpu, logical reads, physical reads, writes, duration, memory, tempdb, executions, recent, plan count by hashes, cpu waits, lock waits, locks waits, latch waits, latches waits, buffer latch waits, buffer latches waits, buffer io waits, log waits, log io waits, network waits, network io waits, parallel waits, parallelism waits, memory waits, total waits, rows, total cpu, total logical reads, total physical reads, total writes, total duration, total memory, total tempdb, total rows (avg/average prefix also accepted, e.g. avg cpu, average duration)'
WHEN N'@top' THEN 'a positive integer between 1 and 9,223,372,036,854,775,807'
WHEN N'@start_date' THEN 'January 1, 1753, through December 31, 9999'
WHEN N'@end_date' THEN 'January 1, 1753, through December 31, 9999'
@@ -35695,6 +36699,23 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
END; /*End @help section*/
+/*
+Normalize Sort Order.
+Allow avg/average prefix for backwards compatibility,
+e.g. 'avg cpu' or 'average cpu' maps to 'cpu'.
+*/
+IF LOWER(@sort_order) LIKE 'average %'
+BEGIN
+ SELECT
+ @sort_order = LTRIM(SUBSTRING(@sort_order, 9, LEN(@sort_order)));
+END;
+
+IF LOWER(@sort_order) LIKE 'avg %'
+BEGIN
+ SELECT
+ @sort_order = LTRIM(SUBSTRING(@sort_order, 5, LEN(@sort_order)));
+END;
+
/*
Validate Sort Order.
We do this super early on, because we care about it even
@@ -35728,7 +36749,15 @@ IF @sort_order NOT IN
'parallelism waits',
'memory waits',
'total waits',
- 'rows'
+ 'rows',
+ 'total cpu',
+ 'total logical reads',
+ 'total physical reads',
+ 'total writes',
+ 'total duration',
+ 'total memory',
+ 'total tempdb',
+ 'total rows'
)
BEGIN
RAISERROR('The sort order (%s) you chose is so out of this world that I''m using cpu instead', 10, 1, @sort_order) WITH NOWAIT;
@@ -36340,6 +37369,7 @@ CREATE TABLE
is_trivial_plan bit NOT NULL,
is_parallel_plan bit NOT NULL,
is_forced_plan bit NOT NULL,
+ toggle_forcing nvarchar(300) NOT NULL,
is_natively_compiled bit NOT NULL,
force_failure_count bigint NOT NULL,
last_force_failure_reason_desc nvarchar(128) NULL,
@@ -36724,6 +37754,21 @@ CREATE TABLE
replica_group_id bigint NOT NULL
);
+/*
+Tuning In, Tuning Out
+*/
+CREATE TABLE
+ #database_automatic_tuning_configurations
+(
+ database_id integer NOT NULL,
+ [option] nvarchar(120) NULL,
+ option_value nvarchar(120) NULL,
+ [type] nvarchar(120) NULL,
+ type_value nvarchar(120) NULL,
+ details nvarchar(4000) NULL,
+ [state] integer NULL
+);
+
/*
Trouble Loves Me
*/
@@ -36800,11 +37845,13 @@ INSERT INTO
column_id, metric_group, metric_type, column_name, column_source, is_conditional, condition_param, condition_value, expert_only, format_pattern
)
VALUES
+ (10, 'emergency_troubleshooting', 'toggle_forcing', 'toggle_forcing', 'qsp.toggle_forcing', 0, NULL, NULL, 1, NULL),
(20, 'metadata', 'force_count', 'force_failure_count', 'qsp.force_failure_count', 0, NULL, NULL, 0, NULL),
(30, 'metadata', 'force_reason', 'last_force_failure_reason_desc', 'qsp.last_force_failure_reason_desc', 0, NULL, NULL, 0, NULL),
/* SQL 2022 specific columns */
(40, 'sql_2022', 'feedback', 'has_query_feedback', 'CASE WHEN EXISTS (SELECT 1/0 FROM #query_store_plan_feedback AS qspf WHERE qspf.plan_id = qsp.plan_id) THEN ''Yes'' ELSE ''No'' END', 1, 'sql_2022_views', 1, 0, NULL),
(50, 'sql_2022', 'hints', 'has_query_store_hints', 'CASE WHEN EXISTS (SELECT 1/0 FROM #query_store_query_hints AS qsqh WHERE qsqh.query_id = qsp.query_id) THEN ''Yes'' ELSE ''No'' END', 1, 'sql_2022_views', 1, 0, NULL),
+ (55, 'sql_2022', 'hints', 'set_query_store_hints', '''EXECUTE ''+ QUOTENAME(DB_NAME(qsp.database_id)) + ''.sys.sp_query_store_set_hints @query_id = '' + CONVERT(nvarchar(20), qsq.query_id) + '', @query_hints = N''''OPTION(older_hints_go_here, USE HINT(''''''''newer_hints_go_here''''''''))'''';''', 1, 'sql_2022_views', 1, 1, NULL),
(60, 'sql_2022', 'variants', 'has_plan_variants', 'CASE WHEN EXISTS (SELECT 1/0 FROM #query_store_query_variant AS qsqv WHERE qsqv.query_variant_query_id = qsp.query_id) THEN ''Yes'' ELSE ''No'' END', 1, 'sql_2022_views', 1, 0, NULL),
(70, 'sql_2022', 'replay', 'has_compile_replay_script', 'qsp.has_compile_replay_script', 1, 'sql_2022_views', 1, 0, NULL),
(80, 'sql_2022', 'opt_forcing', 'is_optimized_plan_forcing_disabled', 'qsp.is_optimized_plan_forcing_disabled', 1, 'sql_2022_views', 1, 0, NULL),
@@ -36996,6 +38043,14 @@ VALUES
WHEN 'executions' THEN 'qsrs.count_executions'
WHEN 'recent' THEN 'qsrs.last_execution_time'
WHEN 'rows' THEN 'qsrs.avg_rowcount'
+ WHEN 'total cpu' THEN 'qsrs.total_cpu_time_ms'
+ WHEN 'total logical reads' THEN 'qsrs.total_logical_io_reads_mb'
+ WHEN 'total physical reads' THEN 'qsrs.total_physical_io_reads_mb'
+ WHEN 'total writes' THEN 'qsrs.total_logical_io_writes_mb'
+ WHEN 'total duration' THEN 'qsrs.total_duration_ms'
+ WHEN 'total memory' THEN 'qsrs.total_query_max_used_memory_mb'
+ WHEN 'total tempdb' THEN 'qsrs.total_tempdb_space_used_mb' /*This gets validated later*/
+ WHEN 'total rows' THEN 'qsrs.total_rowcount'
WHEN 'plan count by hashes' THEN 'hashes.plan_hash_count_for_query_hash DESC, hashes.query_hash'
ELSE CASE WHEN @sort_order_is_a_wait = 1 THEN 'waits.total_query_wait_time_ms'
ELSE 'qsrs.avg_cpu_time_ms' END
@@ -37715,18 +38770,6 @@ TRUNCATE TABLE
TRUNCATE TABLE
#ignore_sql_handles;
-TRUNCATE TABLE
- #only_queries_with_hints;
-
-TRUNCATE TABLE
- #only_queries_with_feedback;
-
-TRUNCATE TABLE
- #only_queries_with_variants;
-
-TRUNCATE TABLE
- #forced_plans_failures;
-
TRUNCATE TABLE
#query_hash_totals;
@@ -38207,6 +39250,15 @@ BEGIN
RETURN;
END;
END;
+
+ IF @get_all_databases = 1
+ BEGIN
+ FETCH NEXT
+ FROM @database_cursor
+ INTO @database_name;
+
+ CONTINUE;
+ END;
END;
/*
@@ -38317,6 +39369,15 @@ BEGIN
RETURN;
END;
END;
+
+ IF @get_all_databases = 1
+ BEGIN
+ FETCH NEXT
+ FROM @database_cursor
+ INTO @database_name;
+
+ CONTINUE;
+ END;
END;
/*
@@ -39138,12 +40199,15 @@ BEGIN
SELECT
@where_clause += N'AND DATEPART(WEEKDAY, qsrs.last_execution_time) BETWEEN 1 AND 5' + @nc10;
END;/*df 1*/
-
- IF @df = 7
+ ELSE IF @df = 7
BEGIN
SELECT
@where_clause += N'AND DATEPART(WEEKDAY, qsrs.last_execution_time) BETWEEN 2 AND 6' + @nc10;
END;/*df 7*/
+ ELSE
+ BEGIN
+ RAISERROR('Warning: @workdays filter does not support @@DATEFIRST = %i, weekday filter skipped', 10, 1, @df) WITH NOWAIT;
+ END;
IF @work_start_utc IS NOT NULL
AND @work_end_utc IS NOT NULL
@@ -40503,6 +41567,7 @@ WHERE NOT EXISTS
AND qsqt.query_sql_text NOT LIKE N''%SELECT StatMan%''
AND qsqt.query_sql_text NOT LIKE N''DBCC%''
AND qsqt.query_sql_text NOT LIKE N''(@[_]msparam%''
+ AND qsqt.query_sql_text NOT LIKE N''WAITFOR%''
)
OPTION(RECOMPILE);' + @nc10;
@@ -41175,22 +42240,28 @@ BEGIN
CONVERT
(
float,
- AVG
- (' +
+ ' +
CASE @sort_order
- WHEN 'cpu' THEN N'qsrs.avg_cpu_time'
- WHEN 'logical reads' THEN N'qsrs.avg_logical_io_reads'
- WHEN 'physical reads' THEN N'qsrs.avg_physical_io_reads'
- WHEN 'writes' THEN N'qsrs.avg_logical_io_writes'
- WHEN 'duration' THEN N'qsrs.avg_duration'
- WHEN 'memory' THEN N'qsrs.avg_query_max_used_memory'
- WHEN 'tempdb' THEN CASE WHEN @new = 1 THEN N'qsrs.avg_tempdb_space_used' ELSE N'qsrs.avg_cpu_time' END
- WHEN 'executions' THEN N'qsrs.count_executions'
- WHEN 'rows' THEN N'qsrs.avg_rowcount'
- ELSE CASE WHEN @sort_order_is_a_wait = 1 THEN N'waits.total_query_wait_time_ms' ELSE N'qsrs.avg_cpu_time' END
+ WHEN 'cpu' THEN N'AVG(qsrs.avg_cpu_time)'
+ WHEN 'logical reads' THEN N'AVG(qsrs.avg_logical_io_reads)'
+ WHEN 'physical reads' THEN N'AVG(qsrs.avg_physical_io_reads)'
+ WHEN 'writes' THEN N'AVG(qsrs.avg_logical_io_writes)'
+ WHEN 'duration' THEN N'AVG(qsrs.avg_duration)'
+ WHEN 'memory' THEN N'AVG(qsrs.avg_query_max_used_memory)'
+ WHEN 'tempdb' THEN CASE WHEN @new = 1 THEN N'AVG(qsrs.avg_tempdb_space_used)' ELSE N'AVG(qsrs.avg_cpu_time)' END
+ WHEN 'executions' THEN N'AVG(qsrs.count_executions)'
+ WHEN 'rows' THEN N'AVG(qsrs.avg_rowcount)'
+ WHEN 'total cpu' THEN N'SUM(qsrs.avg_cpu_time * qsrs.count_executions)'
+ WHEN 'total logical reads' THEN N'SUM(qsrs.avg_logical_io_reads * qsrs.count_executions)'
+ WHEN 'total physical reads' THEN N'SUM(qsrs.avg_physical_io_reads * qsrs.count_executions)'
+ WHEN 'total writes' THEN N'SUM(qsrs.avg_logical_io_writes * qsrs.count_executions)'
+ WHEN 'total duration' THEN N'SUM(qsrs.avg_duration * qsrs.count_executions)'
+ WHEN 'total memory' THEN N'SUM(qsrs.avg_query_max_used_memory * qsrs.count_executions)'
+ WHEN 'total tempdb' THEN CASE WHEN @new = 1 THEN N'SUM(qsrs.avg_tempdb_space_used * qsrs.count_executions)' ELSE N'SUM(qsrs.avg_cpu_time * qsrs.count_executions)' END
+ WHEN 'total rows' THEN N'SUM(qsrs.avg_rowcount * qsrs.count_executions)'
+ ELSE CASE WHEN @sort_order_is_a_wait = 1 THEN N'AVG(waits.total_query_wait_time_ms)' ELSE N'AVG(qsrs.avg_cpu_time)' END
END
+ N'
- )
)
FROM ' + @database_name_quoted + N'.sys.query_store_query AS qsq
JOIN ' + @database_name_quoted + N'.sys.query_store_plan AS qsp
@@ -41281,22 +42352,28 @@ BEGIN
CONVERT
(
float,
- AVG
- (' +
+ ' +
CASE @sort_order
- WHEN 'cpu' THEN N'qsrs.avg_cpu_time'
- WHEN 'logical reads' THEN N'qsrs.avg_logical_io_reads'
- WHEN 'physical reads' THEN N'qsrs.avg_physical_io_reads'
- WHEN 'writes' THEN N'qsrs.avg_logical_io_writes'
- WHEN 'duration' THEN N'qsrs.avg_duration'
- WHEN 'memory' THEN N'qsrs.avg_query_max_used_memory'
- WHEN 'tempdb' THEN CASE WHEN @new = 1 THEN N'qsrs.avg_tempdb_space_used' ELSE N'qsrs.avg_cpu_time' END
- WHEN 'executions' THEN N'qsrs.count_executions'
- WHEN 'rows' THEN N'qsrs.avg_rowcount'
- ELSE CASE WHEN @sort_order_is_a_wait = 1 THEN N'waits.total_query_wait_time_ms' ELSE N'qsrs.avg_cpu_time' END
+ WHEN 'cpu' THEN N'AVG(qsrs.avg_cpu_time)'
+ WHEN 'logical reads' THEN N'AVG(qsrs.avg_logical_io_reads)'
+ WHEN 'physical reads' THEN N'AVG(qsrs.avg_physical_io_reads)'
+ WHEN 'writes' THEN N'AVG(qsrs.avg_logical_io_writes)'
+ WHEN 'duration' THEN N'AVG(qsrs.avg_duration)'
+ WHEN 'memory' THEN N'AVG(qsrs.avg_query_max_used_memory)'
+ WHEN 'tempdb' THEN CASE WHEN @new = 1 THEN N'AVG(qsrs.avg_tempdb_space_used)' ELSE N'AVG(qsrs.avg_cpu_time)' END
+ WHEN 'executions' THEN N'AVG(qsrs.count_executions)'
+ WHEN 'rows' THEN N'AVG(qsrs.avg_rowcount)'
+ WHEN 'total cpu' THEN N'SUM(qsrs.avg_cpu_time * qsrs.count_executions)'
+ WHEN 'total logical reads' THEN N'SUM(qsrs.avg_logical_io_reads * qsrs.count_executions)'
+ WHEN 'total physical reads' THEN N'SUM(qsrs.avg_physical_io_reads * qsrs.count_executions)'
+ WHEN 'total writes' THEN N'SUM(qsrs.avg_logical_io_writes * qsrs.count_executions)'
+ WHEN 'total duration' THEN N'SUM(qsrs.avg_duration * qsrs.count_executions)'
+ WHEN 'total memory' THEN N'SUM(qsrs.avg_query_max_used_memory * qsrs.count_executions)'
+ WHEN 'total tempdb' THEN CASE WHEN @new = 1 THEN N'SUM(qsrs.avg_tempdb_space_used * qsrs.count_executions)' ELSE N'SUM(qsrs.avg_cpu_time * qsrs.count_executions)' END
+ WHEN 'total rows' THEN N'SUM(qsrs.avg_rowcount * qsrs.count_executions)'
+ ELSE CASE WHEN @sort_order_is_a_wait = 1 THEN N'AVG(waits.total_query_wait_time_ms)' ELSE N'AVG(qsrs.avg_cpu_time)' END
END
+ N'
- )
)
FROM ' + @database_name_quoted + N'.sys.query_store_query AS qsq
JOIN ' + @database_name_quoted + N'.sys.query_store_plan AS qsp
@@ -41424,6 +42501,14 @@ BEGIN
WHEN 'tempdb' THEN CASE WHEN @new = 1 THEN N'(hashes_with_changes.change_since_regression_time_period * 8.) / 1024.' ELSE N'hashes_with_changes.change_since_regression_time_period / 1000.' END
WHEN 'executions' THEN N'hashes_with_changes.change_since_regression_time_period'
WHEN 'rows' THEN N'hashes_with_changes.change_since_regression_time_period'
+ WHEN 'total cpu' THEN N'hashes_with_changes.change_since_regression_time_period / 1000.'
+ WHEN 'total logical reads' THEN N'(hashes_with_changes.change_since_regression_time_period * 8.) / 1024.'
+ WHEN 'total physical reads' THEN N'(hashes_with_changes.change_since_regression_time_period * 8.) / 1024.'
+ WHEN 'total writes' THEN N'(hashes_with_changes.change_since_regression_time_period * 8.) / 1024.'
+ WHEN 'total duration' THEN N'hashes_with_changes.change_since_regression_time_period / 1000.'
+ WHEN 'total memory' THEN N'(hashes_with_changes.change_since_regression_time_period * 8.) / 1024.'
+ WHEN 'total tempdb' THEN CASE WHEN @new = 1 THEN N'(hashes_with_changes.change_since_regression_time_period * 8.) / 1024.' ELSE N'hashes_with_changes.change_since_regression_time_period / 1000.' END
+ WHEN 'total rows' THEN N'hashes_with_changes.change_since_regression_time_period'
ELSE CASE WHEN @sort_order_is_a_wait = 1 THEN N'hashes_with_changes.change_since_regression_time_period / 1000.' ELSE N'hashes_with_changes.change_since_regression_time_period / 1000.' END
END
ELSE N'hashes_with_changes.change_since_regression_time_period' END
@@ -41634,6 +42719,14 @@ BEGIN
WHEN 'executions' THEN N'qsrs.count_executions'
WHEN 'recent' THEN N'qsrs.last_execution_time'
WHEN 'rows' THEN N'qsrs.avg_rowcount'
+ WHEN 'total cpu' THEN N'qsrs.avg_cpu_time * qsrs.count_executions'
+ WHEN 'total logical reads' THEN N'qsrs.avg_logical_io_reads * qsrs.count_executions'
+ WHEN 'total physical reads' THEN N'qsrs.avg_physical_io_reads * qsrs.count_executions'
+ WHEN 'total writes' THEN N'qsrs.avg_logical_io_writes * qsrs.count_executions'
+ WHEN 'total duration' THEN N'qsrs.avg_duration * qsrs.count_executions'
+ WHEN 'total memory' THEN N'qsrs.avg_query_max_used_memory * qsrs.count_executions'
+ WHEN 'total tempdb' THEN CASE WHEN @new = 1 THEN N'qsrs.avg_tempdb_space_used * qsrs.count_executions' ELSE N'qsrs.avg_cpu_time * qsrs.count_executions' END
+ WHEN 'total rows' THEN N'qsrs.avg_rowcount * qsrs.count_executions'
ELSE N'qsrs.avg_cpu_time'
END +
N') DESC
@@ -41759,10 +42852,10 @@ BEGIN
MAX(((qsrs_with_lasts.partitioned_last_num_physical_io_reads * 8.) / 1024.)),
MIN(((qsrs_with_lasts.min_num_physical_io_reads * 8.) / 1024.)),
MAX(((qsrs_with_lasts.max_num_physical_io_reads * 8.) / 1024.)),
- AVG((qsrs_with_lasts.avg_log_bytes_used / 100000000.)),
- MAX((qsrs_with_lasts.partitioned_last_log_bytes_used / 100000000.)),
- MIN((qsrs_with_lasts.min_log_bytes_used / 100000000.)),
- MAX((qsrs_with_lasts.max_log_bytes_used / 100000000.)),
+ AVG((qsrs_with_lasts.avg_log_bytes_used / 1048576.)),
+ MAX((qsrs_with_lasts.partitioned_last_log_bytes_used / 1048576.)),
+ MIN((qsrs_with_lasts.min_log_bytes_used / 1048576.)),
+ MAX((qsrs_with_lasts.max_log_bytes_used / 1048576.)),
AVG(((qsrs_with_lasts.avg_tempdb_space_used * 8) / 1024.)),
MAX(((qsrs_with_lasts.partitioned_last_tempdb_space_used * 8) / 1024.)),
MIN(((qsrs_with_lasts.min_tempdb_space_used * 8) / 1024.)),
@@ -42054,6 +43147,14 @@ SELECT
WHEN 'executions' THEN N'qsrs.count_executions'
WHEN 'recent' THEN N'qsrs.last_execution_time'
WHEN 'rows' THEN N'qsrs.avg_rowcount'
+ WHEN 'total cpu' THEN N'qsrs.avg_cpu_time * qsrs.count_executions'
+ WHEN 'total logical reads' THEN N'qsrs.avg_logical_io_reads * qsrs.count_executions'
+ WHEN 'total physical reads' THEN N'qsrs.avg_physical_io_reads * qsrs.count_executions'
+ WHEN 'total writes' THEN N'qsrs.avg_logical_io_writes * qsrs.count_executions'
+ WHEN 'total duration' THEN N'qsrs.avg_duration * qsrs.count_executions'
+ WHEN 'total memory' THEN N'qsrs.avg_query_max_used_memory * qsrs.count_executions'
+ WHEN 'total tempdb' THEN CASE WHEN @new = 1 THEN N'qsrs.avg_tempdb_space_used * qsrs.count_executions' ELSE N'qsrs.avg_cpu_time * qsrs.count_executions' END
+ WHEN 'total rows' THEN N'qsrs.avg_rowcount * qsrs.count_executions'
WHEN 'plan count by hashes' THEN N'hashes.plan_hash_count_for_query_hash DESC,
hashes.query_hash'
ELSE CASE WHEN @sort_order_is_a_wait = 1 THEN N'waits.total_query_wait_time_ms' ELSE N'qsrs.avg_cpu_time' END
@@ -42211,6 +43312,14 @@ SELECT
qsp.is_trivial_plan,
qsp.is_parallel_plan,
qsp.is_forced_plan,
+ toggle_forcing =
+ CASE
+ qsp.is_forced_plan
+ WHEN 1
+ THEN ''EXECUTE ' + @database_name_quoted + '.sys.sp_query_store_unforce_plan @query_id = '' + CONVERT(nvarchar(20), qsp.query_id) + '', @plan_id = '' + CONVERT(nvarchar(20), qsp.plan_id) + '';''
+ WHEN 0
+ THEN ''EXECUTE ' + @database_name_quoted + '.sys.sp_query_store_force_plan @query_id = '' + CONVERT(nvarchar(20), qsp.query_id) + '', @plan_id = '' + CONVERT(nvarchar(20), qsp.plan_id) + '', @disable_optimized_plan_forcing = ? ;''
+ END,
qsp.is_natively_compiled,
qsp.force_failure_count,
qsp.last_force_failure_reason_desc,
@@ -42303,6 +43412,7 @@ WITH
is_trivial_plan,
is_parallel_plan,
is_forced_plan,
+ toggle_forcing,
is_natively_compiled,
force_failure_count,
last_force_failure_reason_desc,
@@ -42387,9 +43497,9 @@ SELECT
(qsq.last_optimize_duration / 1000.),
(qsq.avg_optimize_cpu_time / 1000.),
(qsq.last_optimize_cpu_time / 1000.),
- ((qsq.avg_compile_memory_kb * 8) / 1024.),
- ((qsq.last_compile_memory_kb * 8) / 1024.),
- ((qsq.max_compile_memory_kb * 8) / 1024.),
+ (qsq.avg_compile_memory_kb / 1024.),
+ (qsq.last_compile_memory_kb / 1024.),
+ (qsq.max_compile_memory_kb / 1024.),
qsq.is_clouddb_internal_query
FROM #query_store_plan AS qsp
CROSS APPLY
@@ -42504,7 +43614,7 @@ BEGIN
WHEN 1
THEN N',
SUM(qsrs.count_executions * (qsrs.avg_num_physical_io_reads * 8)) / 1024.,
- SUM(qsrs.count_executions * qsrs.avg_log_bytes_used) / 100000000.,
+ SUM(qsrs.count_executions * qsrs.avg_log_bytes_used) / 1048576.,
SUM(qsrs.count_executions * (qsrs.avg_tempdb_space_used * 8)) / 1024.'
ELSE N',
NULL,
@@ -43735,6 +44845,87 @@ OPTION(RECOMPILE);' + @nc10;
@current_table;
END;
END; /*End AG queries*/
+
+ /*database_automatic_tuning_configurations*/
+ SELECT
+ @current_table = 'inserting #database_automatic_tuning_configurations',
+ @sql = @isolation_level;
+
+ IF @troubleshoot_performance = 1
+ BEGIN
+ EXECUTE sys.sp_executesql
+ @troubleshoot_insert,
+ N'@current_table nvarchar(100)',
+ @current_table;
+
+ SET STATISTICS XML ON;
+ END;
+
+ SELECT
+ @sql += N'
+SELECT
+ @database_id,
+ datc.[option],
+ datc.option_value,
+ datc.[type],
+ type_value =
+ CONVERT
+ (
+ nvarchar(120),
+ datc.type_value
+ ),
+ datc.details,
+ datc.[state]
+FROM ' + @database_name_quoted + N'.sys.database_automatic_tuning_configurations AS datc
+WHERE EXISTS
+ (
+ SELECT
+ 1/0
+ FROM #query_store_plan AS qsp
+ WHERE TRY_CAST(datc.type_value AS bigint) = qsp.query_id
+ )
+OPTION(RECOMPILE);' + @nc10;
+
+ IF @debug = 1
+ BEGIN
+ PRINT LEN(@sql);
+ PRINT @sql;
+ END;
+
+ INSERT
+ #database_automatic_tuning_configurations
+ WITH
+ (TABLOCK)
+ (
+ database_id,
+ [option],
+ option_value,
+ [type],
+ type_value,
+ details,
+ [state]
+ )
+ EXECUTE sys.sp_executesql
+ @sql,
+ N'@database_id integer',
+ @database_id;
+
+ IF @troubleshoot_performance = 1
+ BEGIN
+ SET STATISTICS XML OFF;
+
+ EXECUTE sys.sp_executesql
+ @troubleshoot_update,
+ N'@current_table nvarchar(100)',
+ @current_table;
+
+ EXECUTE sys.sp_executesql
+ @troubleshoot_info,
+ N'@sql nvarchar(max),
+ @current_table nvarchar(100)',
+ @sql,
+ @current_table;
+ END;
END; /*End SQL 2022 views*/
FETCH NEXT
@@ -43776,6 +44967,7 @@ FROM
WHEN @include_plan_hashes IS NOT NULL
OR @ignore_plan_hashes IS NOT NULL
OR @sort_order = 'plan count by hashes'
+ OR @expert_mode = 1
THEN N'
qsp.query_plan_hash,'
ELSE N''
@@ -44135,6 +45327,14 @@ ORDER BY
WHEN 'executions' THEN N'x.count_executions'
WHEN 'recent' THEN N'x.last_execution_time'
WHEN 'rows' THEN N'x.avg_rowcount'
+ WHEN 'total cpu' THEN N'x.total_cpu_time_ms'
+ WHEN 'total logical reads' THEN N'x.total_logical_io_reads_mb'
+ WHEN 'total physical reads' THEN N'x.total_physical_io_reads_mb'
+ WHEN 'total writes' THEN N'x.total_logical_io_writes_mb'
+ WHEN 'total duration' THEN N'x.total_duration_ms'
+ WHEN 'total memory' THEN N'x.total_query_max_used_memory_mb'
+ WHEN 'total tempdb' THEN CASE WHEN @new = 1 THEN N'x.total_tempdb_space_used_mb' ELSE N'x.total_cpu_time_ms' END
+ WHEN 'total rows' THEN N'x.total_rowcount'
WHEN 'plan count by hashes' THEN N'x.plan_hash_count_for_query_hash DESC,
x.query_hash_from_hash_counting'
ELSE CASE WHEN @sort_order_is_a_wait = 1 THEN N'x.total_wait_time_from_sort_order_ms' ELSE N'x.avg_cpu_time_ms' END
@@ -44172,6 +45372,14 @@ ORDER BY
WHEN 'executions' THEN N'TRY_PARSE(x.count_executions AS decimal(19,2))'
WHEN 'recent' THEN N'x.last_execution_time'
WHEN 'rows' THEN N'TRY_PARSE(x.avg_rowcount AS decimal(19,2))'
+ WHEN 'total cpu' THEN N'TRY_PARSE(x.total_cpu_time_ms AS decimal(19,2))'
+ WHEN 'total logical reads' THEN N'TRY_PARSE(x.total_logical_io_reads_mb AS decimal(19,2))'
+ WHEN 'total physical reads' THEN N'TRY_PARSE(x.total_physical_io_reads_mb AS decimal(19,2))'
+ WHEN 'total writes' THEN N'TRY_PARSE(x.total_logical_io_writes_mb AS decimal(19,2))'
+ WHEN 'total duration' THEN N'TRY_PARSE(x.total_duration_ms AS decimal(19,2))'
+ WHEN 'total memory' THEN N'TRY_PARSE(x.total_query_max_used_memory_mb AS decimal(19,2))'
+ WHEN 'total tempdb' THEN CASE WHEN @new = 1 THEN N'TRY_PARSE(x.total_tempdb_space_used_mb AS decimal(19,2))' ELSE N'TRY_PARSE(x.total_cpu_time_ms AS decimal(19,2))' END
+ WHEN 'total rows' THEN N'TRY_PARSE(x.total_rowcount AS decimal(19,2))'
WHEN 'plan count by hashes' THEN N'TRY_PARSE(x.plan_hash_count_for_query_hash AS decimal(19,2)) DESC,
x.query_hash_from_hash_counting'
ELSE CASE WHEN @sort_order_is_a_wait = 1 THEN N'TRY_PARSE(x.total_wait_time_from_sort_order_ms AS decimal(19,2))' ELSE N'TRY_PARSE(x.avg_cpu_time_ms AS decimal(19,2))' END
@@ -44335,6 +45543,8 @@ BEGIN
qsqh.query_hint_id,
qsqh.query_id,
qsqh.query_hint_text,
+ remove_hint =
+ ''EXECUTE '' + QUOTENAME(DB_NAME(qsqh.database_id)) + ''.sys.sp_query_store_clear_hints @query_id = '' + CONVERT(nvarchar(20), qsqh.query_id) + '';'',
qsqh.last_query_hint_failure_reason_desc,
query_hint_failure_count = ' +
CASE
@@ -44457,6 +45667,34 @@ BEGIN
END;
END;
END; /*@ags_present*/
+
+ IF @expert_mode = 1
+ BEGIN
+ IF EXISTS
+ (
+ SELECT
+ 1/0
+ FROM #database_automatic_tuning_configurations AS datc
+ )
+ BEGIN
+ SELECT
+ @current_table = 'selecting #database_automatic_tuning_configurations';
+
+ SELECT
+ database_name =
+ DB_NAME(datc.database_id),
+ datc.[option],
+ datc.option_value,
+ datc.[type],
+ datc.type_value,
+ datc.details,
+ datc.[state]
+ FROM #database_automatic_tuning_configurations AS datc
+ ORDER BY
+ datc.[option]
+ OPTION(RECOMPILE);
+ END;
+ END;
END; /*End 2022 views*/
IF @expert_mode = 1
@@ -46782,6 +48020,29 @@ BEGIN
END;
END;
+ IF EXISTS
+ (
+ SELECT
+ 1/0
+ FROM #database_automatic_tuning_configurations AS datc
+ )
+ BEGIN
+ SELECT
+ table_name =
+ '#database_automatic_tuning_configurations',
+ datc.*
+ FROM #database_automatic_tuning_configurations AS datc
+ ORDER BY
+ datc.[option]
+ OPTION(RECOMPILE);
+ END;
+ ELSE
+ BEGIN
+ SELECT
+ result =
+ '#database_automatic_tuning_configurations is empty';
+ END;
+
IF EXISTS
(
SELECT
diff --git a/sp_HumanEvents/sp_HumanEvents.sql b/sp_HumanEvents/sp_HumanEvents.sql
index e60d097b..eeb294c2 100644
--- a/sp_HumanEvents/sp_HumanEvents.sql
+++ b/sp_HumanEvents/sp_HumanEvents.sql
@@ -3586,7 +3586,7 @@ BEGIN
RAISERROR(@the_sleeper_must_awaken, 0, 1) WITH NOWAIT;
RAISERROR(N'Starting keeper_HumanEvents... inactive sessions', 0, 1) WITH NOWAIT;
END;
-
+
EXECUTE sys.sp_executesql
@the_sleeper_must_awaken;
END;
diff --git a/sp_PressureDetector/sp_PressureDetector.sql b/sp_PressureDetector/sp_PressureDetector.sql
index f8e9f22a..6e139f3c 100644
--- a/sp_PressureDetector/sp_PressureDetector.sql
+++ b/sp_PressureDetector/sp_PressureDetector.sql
@@ -4319,7 +4319,7 @@ OPTION(MAXDOP 1, RECOMPILE);',
bi.login_name,
wait_time_ms = bi.wait_time,
wait_type = NULLIF(bi.wait_type, N'MISCELLANEOUS'),
- bi.wait_resource,
+ bi.wait_resource,
reads = ISNULL(der.reads, 0),
writes = ISNULL(der.writes, 0),
logical_reads = ISNULL(der.logical_reads, bi.physical_io),
diff --git a/sp_QuickieStore/sp_QuickieStore.sql b/sp_QuickieStore/sp_QuickieStore.sql
index fed9af18..bc58225c 100644
--- a/sp_QuickieStore/sp_QuickieStore.sql
+++ b/sp_QuickieStore/sp_QuickieStore.sql
@@ -7036,7 +7036,7 @@ SELECT
qsp.is_trivial_plan,
qsp.is_parallel_plan,
qsp.is_forced_plan,
- toggle_forcing =
+ toggle_forcing =
CASE
qsp.is_forced_plan
WHEN 1