Skip to content

Commit 35dd2f2

Browse files
committed
Added unload plan
1 parent 451673c commit 35dd2f2

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

After-Installing-SQL-Server-2017_CU3/ClearAffectedPlans_BeforeCU3_Upgrade.sql

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,21 @@ BEGIN
2323
-- PRINT 'Working on database ' + @userDB
2424

2525
EXEC ('USE [' + @userDB + '];
26-
DECLARE @clearPlan bigint;
26+
DECLARE @clearPlan bigint, @clearQry bigint;
2727
IF EXISTS (SELECT [actual_state] FROM sys.database_query_store_options WHERE [actual_state] IN (1,2))
2828
BEGIN
2929
IF EXISTS (SELECT plan_id FROM sys.query_store_plan WHERE engine_version = ''14.0.3008.27'')
3030
BEGIN
3131
DROP TABLE IF EXISTS #tmpclearPlans;
3232
33-
SELECT plan_id, 0 AS [IsDone]
33+
SELECT plan_id, query_id, 0 AS [IsDone]
3434
INTO #tmpclearPlans
3535
FROM sys.query_store_plan WHERE engine_version = ''14.0.3008.27''
3636
3737
WHILE (SELECT COUNT(plan_id) FROM #tmpclearPlans WHERE [IsDone] = 0) > 0
3838
BEGIN
39-
SELECT TOP 1 @clearPlan = plan_id FROM #tmpclearPlans WHERE [IsDone] = 0
40-
EXECUTE sys.sp_query_store_unforce_plan @clearPlan;
39+
SELECT TOP 1 @clearPlan = plan_id, @clearQry = query_id FROM #tmpclearPlans WHERE [IsDone] = 0
40+
EXECUTE sys.sp_query_store_unforce_plan @clearQry, @clearPlan;
4141
EXECUTE sys.sp_query_store_remove_plan @clearPlan;
4242
4343
UPDATE #tmpclearPlans

0 commit comments

Comments
 (0)