From a5a0f04f5ac6282175d3e44b3d94dad9c6328954 Mon Sep 17 00:00:00 2001 From: Erik Darling <2136037+erikdarlingdata@users.noreply.github.com> Date: Fri, 13 Feb 2026 00:31:06 -0500 Subject: [PATCH 1/3] Update sp_QuickieStore.sql MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Issue #661: Add sys.database_automatic_tuning_configurations to sp_QuickieStore expert mode 4 changes to sp_QuickieStore.sql: 1. Temp table (line ~1483): #database_automatic_tuning_configurations with correct data types (notably sql_variant column type_value is stored as nvarchar(120) with explicit CONVERT, and state is integer — the Microsoft docs were wrong about the types) 2. Data population (line ~8552): Inside IF @sql_2022_views = 1, queries sys.database_automatic_tuning_configurations with no WHERE filter (database-level config, not per-query) 3. Expert mode output (line ~9364): Shows the result set when @expert_mode = 1 and data exists. Silently skips when empty (empty is normal) 4. Debug output (line ~11715): Standard debug pattern with "is empty" message Tested and working on both sql2022 (16.0.4222) and sql2025 (17.0.4015) — the initial sp_configure_automatic_tuning failure on sql2022 was bad parameter syntax, not a version limitation. The feature works identically on both versions. --- sp_QuickieStore/sp_QuickieStore.sql | 140 ++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) diff --git a/sp_QuickieStore/sp_QuickieStore.sql b/sp_QuickieStore/sp_QuickieStore.sql index 48e5756f..a08d2275 100644 --- a/sp_QuickieStore/sp_QuickieStore.sql +++ b/sp_QuickieStore/sp_QuickieStore.sql @@ -1477,6 +1477,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 */ @@ -8533,6 +8548,80 @@ 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 +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 @@ -9271,6 +9360,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 @@ -11596,6 +11713,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 From 8a79384e7fa88b857bffae080c47f713868bf31a Mon Sep 17 00:00:00 2001 From: ReeceGoding <67124261+ReeceGoding@users.noreply.github.com> Date: Sun, 22 Feb 2026 22:35:09 +0000 Subject: [PATCH 2/3] Tweak #661 so we respect our filters when querying sys.database_automatic_tuning_configurations. --- sp_QuickieStore/sp_QuickieStore.sql | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/sp_QuickieStore/sp_QuickieStore.sql b/sp_QuickieStore/sp_QuickieStore.sql index a08d2275..fcc9c1f2 100644 --- a/sp_QuickieStore/sp_QuickieStore.sql +++ b/sp_QuickieStore/sp_QuickieStore.sql @@ -8580,6 +8580,13 @@ SELECT 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 datc.type_value = qsp.query_id + ) OPTION(RECOMPILE);' + @nc10; IF @debug = 1 From 3b4cb73bde3dcf9f4bd4823e43cf0e2389ac095f Mon Sep 17 00:00:00 2001 From: Erik Darling <2136037+erikdarlingdata@users.noreply.github.com> Date: Tue, 24 Feb 2026 07:40:14 -0500 Subject: [PATCH 3/3] Use TRY_CAST for type_value comparison in automatic tuning filter Avoids implicit nvarchar-to-bigint conversion; TRY_CAST works at all compat levels unlike TRY_CONVERT which requires >= 130. Co-Authored-By: Claude Opus 4.6 --- sp_QuickieStore/sp_QuickieStore.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sp_QuickieStore/sp_QuickieStore.sql b/sp_QuickieStore/sp_QuickieStore.sql index fcc9c1f2..9814e960 100644 --- a/sp_QuickieStore/sp_QuickieStore.sql +++ b/sp_QuickieStore/sp_QuickieStore.sql @@ -8585,7 +8585,7 @@ WHERE EXISTS SELECT 1/0 FROM #query_store_plan AS qsp - WHERE datc.type_value = qsp.query_id + WHERE TRY_CAST(datc.type_value AS bigint) = qsp.query_id ) OPTION(RECOMPILE);' + @nc10;