1- -- Compile Date: 03/24/2025 13:48:58 UTC
1+ -- Compile Date: 03/24/2025 14:11:31 UTC
22SET ANSI_NULLS ON;
33SET ANSI_PADDING ON;
44SET ANSI_WARNINGS ON;
@@ -26174,7 +26174,13 @@ DECLARE
2617426174 @requires_secondary_processing bit,
2617526175 @split_sql nvarchar(max),
2617626176 @error_msg nvarchar(2000),
26177- @conflict_list nvarchar(max) = N'';
26177+ @conflict_list nvarchar(max) = N'',
26178+ @database_cursor CURSOR,
26179+ @filter_cursor CURSOR,
26180+ @dynamic_sql nvarchar(max) = N'',
26181+ @secondary_sql nvarchar(max) = N'',
26182+ @temp_target_table nvarchar(100),
26183+ @exist_or_not_exist nvarchar(20);
2617826184
2617926185/*
2618026186In cases where we are escaping @query_text_search and
@@ -26740,9 +26746,6 @@ BEGIN
2674026746 END;
2674126747END;
2674226748
26743- DECLARE
26744- @database_cursor CURSOR;
26745-
2674626749SET
2674726750 @database_cursor =
2674826751 CURSOR
@@ -27019,7 +27022,8 @@ SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;',
2701927022 ) AS ids
2702027023 CROSS APPLY ids.nodes(''x'') AS x (x)
2702127024 ) AS ids
27022- OPTION(RECOMPILE);',
27025+ OPTION(RECOMPILE);
27026+ ',
2702327027 @string_split_strings = N'
2702427028 SELECT DISTINCT
2702527029 ids =
@@ -27063,7 +27067,8 @@ SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;',
2706327067 ) AS ids
2706427068 CROSS APPLY ids.nodes(''x'') AS x (x)
2706527069 ) AS ids
27066- OPTION(RECOMPILE);',
27070+ OPTION(RECOMPILE);
27071+ ',
2706727072 @troubleshoot_insert = N'
2706827073 INSERT
2706927074 #troubleshoot_performance
@@ -27078,15 +27083,17 @@ SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;',
2707827083 @current_table,
2707927084 GETDATE()
2708027085 )
27081- OPTION(RECOMPILE);',
27086+ OPTION(RECOMPILE);
27087+ ',
2708227088 @troubleshoot_update = N'
2708327089 UPDATE
2708427090 tp
2708527091 SET
2708627092 tp.end_time = GETDATE()
2708727093 FROM #troubleshoot_performance AS tp
2708827094 WHERE tp.current_table = @current_table
27089- OPTION(RECOMPILE);',
27095+ OPTION(RECOMPILE);
27096+ ',
2709027097 @troubleshoot_info = N'
2709127098 SELECT
2709227099 (
@@ -27105,7 +27112,8 @@ SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;',
2710527112 PATH(N''''),
2710627113 TYPE
2710727114 ).query(''.[1]'') AS current_query
27108- OPTION(RECOMPILE);',
27115+ OPTION(RECOMPILE);
27116+ ',
2710927117 @rc = 0,
2711027118 @em = @expert_mode,
2711127119 @fo = @format_output,
@@ -28530,9 +28538,6 @@ OR @ignore_plan_hashes IS NOT NULL
2853028538OR @ignore_sql_handles IS NOT NULL
2853128539)
2853228540BEGIN
28533- DECLARE
28534- @filter_cursor CURSOR;
28535-
2853628541 SET @filter_cursor =
2853728542 CURSOR
2853828543 LOCAL
@@ -28605,7 +28610,7 @@ BEGIN
2860528610 END;
2860628611
2860728612 /* Execute the dynamic SQL to populate the temporary table */
28608- DECLARE @dynamic_sql nvarchar(max) = N'
28613+ SET @dynamic_sql = N'
2860928614 INSERT INTO
2861028615 ' + @temp_table + N'
2861128616 WITH
@@ -28649,9 +28654,6 @@ BEGIN
2864928654 @current_table = 'inserting #include_plan_ids for ' + @param_name;
2865028655
2865128656 /* Build appropriate SQL based on parameter type */
28652- DECLARE
28653- @secondary_sql nvarchar(max) = N'';
28654-
2865528657 IF @param_name = 'include_query_ids'
2865628658 OR @param_name = 'ignore_query_ids'
2865728659 BEGIN
@@ -28672,7 +28674,7 @@ BEGIN
2867228674 N'_query_ids AS iqi
2867328675 WHERE iqi.query_id = qsp.query_id
2867428676 )
28675- OPTION(RECOMPILE);';
28677+ OPTION(RECOMPILE);' + @nc10 ;
2867628678 END;
2867728679 ELSE
2867828680 IF @param_name = 'include_query_hashes'
@@ -28702,7 +28704,7 @@ BEGIN
2870228704 WHERE iqh.query_hash = qsq.query_hash
2870328705 )
2870428706 )
28705- OPTION(RECOMPILE);';
28707+ OPTION(RECOMPILE);' + @nc10 ;
2870628708 END;
2870728709 ELSE
2870828710 IF @param_name = 'include_plan_hashes'
@@ -28724,7 +28726,7 @@ BEGIN
2872428726 END + N'_plan_hashes AS iph
2872528727 WHERE iph.plan_hash = qsp.query_plan_hash
2872628728 )
28727- OPTION(RECOMPILE);';
28729+ OPTION(RECOMPILE);' + @nc10 ;
2872828730 END;
2872928731 ELSE
2873028732 IF
@@ -28761,7 +28763,7 @@ BEGIN
2876128763 )
2876228764 )
2876328765 )
28764- OPTION(RECOMPILE);';
28766+ OPTION(RECOMPILE);' + @nc10 ;
2876528767 END;
2876628768
2876728769 /* Process secondary sql if defined */
@@ -28805,14 +28807,14 @@ BEGIN
2880528807 END;
2880628808
2880728809 /* Update where clause if needed */
28808- DECLARE
28809- @temp_target_table nvarchar(100) =
28810+ SELECT
28811+ @temp_target_table =
2881028812 CASE
2881128813 WHEN @is_include = 1
2881228814 THEN N'#include_plan_ids'
2881328815 ELSE N'#ignore_plan_ids'
2881428816 END,
28815- @exist_or_not_exist nvarchar(20) =
28817+ @exist_or_not_exist =
2881628818 CASE
2881728819 WHEN @is_include = 1
2881828820 THEN N'EXISTS'
@@ -32211,7 +32213,7 @@ WHERE EXISTS
3221132213 AND qsp.database_id = qsq.database_id
3221232214 WHERE qsq.context_settings_id = qcs.context_settings_id
3221332215 )
32214- OPTION(RECOMPILE);';
32216+ OPTION(RECOMPILE);' + @nc10 ;
3221532217
3221632218INSERT
3221732219 #query_context_settings
@@ -33156,8 +33158,7 @@ ORDER BY
3315633158 END END
3315733159 END
3315833160 + N' DESC
33159- OPTION(RECOMPILE);'
33160- + @nc10
33161+ OPTION(RECOMPILE);' + @nc10
3316133162 );
3316233163
3316333164 IF @debug = 1
@@ -33267,7 +33268,7 @@ BEGIN
3326733268 FROM #query_store_plan_feedback AS qspf
3326833269 ORDER BY
3326933270 qspf.plan_id
33270- OPTION(RECOMPILE);';
33271+ OPTION(RECOMPILE);' + @nc10 ;
3327133272
3327233273 IF @debug = 1
3327333274 BEGIN
@@ -33325,7 +33326,7 @@ BEGIN
3332533326 FROM #query_store_query_hints AS qsqh
3332633327 ORDER BY
3332733328 qsqh.query_id
33328- OPTION(RECOMPILE);';
33329+ OPTION(RECOMPILE);' + @nc10 ;
3332933330
3333033331 IF @debug = 1
3333133332 BEGIN
@@ -33373,7 +33374,7 @@ BEGIN
3337333374 FROM #query_store_query_variant AS qsqv
3337433375 ORDER BY
3337533376 qsqv.parent_query_id
33376- OPTION(RECOMPILE);';
33377+ OPTION(RECOMPILE);' + @nc10 ;
3337733378
3337833379 IF @debug = 1
3337933380 BEGIN
@@ -33664,7 +33665,7 @@ BEGIN
3366433665 WHERE x.n = 1
3366533666 ORDER BY
3366633667 x.query_id
33667- OPTION(RECOMPILE);';
33668+ OPTION(RECOMPILE);' + @nc10 ;
3366833669
3366933670 IF @debug = 1
3367033671 BEGIN
@@ -33880,7 +33881,7 @@ BEGIN
3388033881 )
3388133882 ORDER BY
3388233883 qsq.query_id
33883- OPTION(RECOMPILE);'
33884+ OPTION(RECOMPILE);' + @nc10
3388433885 );
3388533886
3388633887 IF @debug = 1
@@ -33925,7 +33926,7 @@ BEGIN
3392533926 (
3392633927 nvarchar(max),
3392733928 N'
33928- SELECT DISTINCT
33929+ SELECT
3392933930 source =
3393033931 ''query_store_wait_stats_by_query'',
3393133932 database_name =
@@ -34039,7 +34040,7 @@ BEGIN
3403934040 ORDER BY
3404034041 qsws.plan_id,
3404134042 qsws.total_query_wait_time_ms DESC
34042- OPTION(RECOMPILE);'
34043+ OPTION(RECOMPILE);' + @nc10
3404334044 );
3404434045
3404534046 IF @debug = 1
@@ -34178,7 +34179,7 @@ BEGIN
3417834179 qsws.database_id
3417934180 ORDER BY
3418034181 SUM(qsws.total_query_wait_time_ms) DESC
34181- OPTION(RECOMPILE);'
34182+ OPTION(RECOMPILE);' + @nc10
3418234183 );
3418334184
3418434185 IF @debug = 1
@@ -34278,7 +34279,7 @@ BEGIN
3427834279 N'
3427934280 dqso.size_based_cleanup_mode_desc
3428034281 FROM #database_query_store_options AS dqso
34281- OPTION(RECOMPILE);'
34282+ OPTION(RECOMPILE);' + @nc10
3428234283 );
3428334284
3428434285 IF @debug = 1
0 commit comments