Skip to content

Commit 03a96aa

Browse files
committed
Automatic tuning updated for RC1 version
1 parent 2d269d4 commit 03a96aa

File tree

2 files changed

+33
-19
lines changed

2 files changed

+33
-19
lines changed

samples/features/automatic-tuning/force-last-good-plan/sql-scripts/demo-full.sql

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ EXEC [dbo].[initialize]
99
* Plan regression identification.
1010
********************************************************/
1111

12-
-- 1. Start workload - execute procedure 30 times:
12+
-- 1. Start workload - execute procedure 30-300 times:
1313
begin
1414
declare @packagetypeid int = 7;
1515
exec dbo.report @packagetypeid
@@ -34,15 +34,16 @@ go 20
3434

3535
-- 4. Find recommendation recommended by database:
3636
SELECT planForceDetails.query_id, reason, score,
37-
JSON_VALUE(details, '$.implementationDetails.script') script,
37+
JSON_VALUE(details, '$.implementationDetails.script') [correction script],
3838
planForceDetails.[new plan_id], planForceDetails.[recommended plan_id]
3939
FROM sys.dm_db_tuning_recommendations
4040
CROSS APPLY OPENJSON (Details, '$.planForceDetails')
4141
WITH ( [query_id] int '$.queryId',
4242
[new plan_id] int '$.regressedPlanId',
43-
[recommended plan_id] int '$.forcedPlanId'
43+
[recommended plan_id] int '$.recommendedPlanId'
4444
) as planForceDetails;
4545

46+
4647
-- Note: User can apply script and force the recommended plan to correct the error.
4748
<<Insert T-SQL from the script column here and execute the script>>
4849
-- e.g.: exec sp_query_store_force_plan @query_id = 3, @plan_id = 1
@@ -66,7 +67,7 @@ go 20
6667
/********************************************************
6768
* RESET - clear everything
6869
********************************************************/
69-
EXEC [dbo].[initialize]
70+
EXEC [dbo].[initialize];
7071

7172
-- Enable automatic tuning on the database:
7273
ALTER DATABASE current
@@ -77,20 +78,20 @@ SELECT name, desired_state_desc, actual_state_desc, reason_desc
7778
FROM sys.database_automatic_tuning_options;
7879

7980

80-
-- 1. Start workload - execute procedure 20 times like in the phase I
81+
-- 1. Start workload - execute procedure 30-300 times like in the phase I
8182
begin
8283
declare @packagetypeid int = 7;
8384
exec dbo.report @packagetypeid
8485
end
8586
go 300
8687

8788
-- 2. Execute the procedure that causes plan regression
88-
exec dbo.regression
89+
exec dbo.regression;
8990

9091
-- 3. Start workload again - verify that it is slower.
9192
begin
9293
declare @packagetypeid int = 7;
93-
exec dbo.report @packagetypeid
94+
exec dbo.report @packagetypeid;
9495
end
9596
go 20
9697

@@ -105,7 +106,7 @@ FROM sys.dm_db_tuning_recommendations
105106
CROSS APPLY OPENJSON (Details, '$.planForceDetails')
106107
WITH ( [query_id] int '$.queryId',
107108
[new plan_id] int '$.regressedPlanId',
108-
[recommended plan_id] int '$.forcedPlanId'
109+
[recommended plan_id] int '$.recommendedPlanId'
109110
) as planForceDetails;
110111

111112

samples/features/automatic-tuning/force-last-good-plan/sql-scripts/setup.sql

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,18 @@ CREATE NONCLUSTERED COLUMNSTORE INDEX [NCCX_Sales_OrderLines] ON [Sales].[OrderL
1313
)WITH (DROP_EXISTING = OFF, COMPRESSION_DELAY = 0) ON [USERDATA]
1414
GO
1515

16-
CREATE procedure [dbo].[initialize]
16+
CREATE OR ALTER PROCEDURE [dbo].[initialize]
1717
as begin
1818

19-
DBCC FREEPROCCACHE;
19+
ALTER DATABASE SCOPED CONFIGURATION CLEAR PROCEDURE_CACHE;
2020
ALTER DATABASE current SET QUERY_STORE CLEAR ALL;
2121
ALTER DATABASE current SET AUTOMATIC_TUNING ( FORCE_LAST_GOOD_PLAN = OFF);
2222

2323
end
2424
GO
2525

26-
CREATE procedure [dbo].[report] (@packagetypeid int)
26+
27+
CREATE OR ALTER PROCEDURE [dbo].[report] (@packagetypeid int)
2728
as begin
2829

2930
select avg([UnitPrice]*[Quantity])
@@ -34,35 +35,47 @@ end
3435
GO
3536

3637

37-
CREATE procedure [dbo].[regression]
38+
CREATE OR ALTER PROCEDURE [dbo].[regression]
3839
as begin
3940

40-
DBCC FREEPROCCACHE;
41+
ALTER DATABASE SCOPED CONFIGURATION CLEAR PROCEDURE_CACHE;
4142
begin
4243
declare @packagetypeid int = 1;
43-
exec report @packagetypeid
44+
exec report @packagetypeid;
4445
end
4546

4647
end
4748
GO
4849

49-
CREATE procedure [dbo].[auto_tuning_on]
50+
CREATE OR ALTER PROCEDURE [dbo].[auto_tuning_on]
5051
as begin
5152

5253
ALTER DATABASE current SET AUTOMATIC_TUNING ( FORCE_LAST_GOOD_PLAN = ON);
53-
DBCC FREEPROCCACHE;
54+
ALTER DATABASE SCOPED CONFIGURATION CLEAR PROCEDURE_CACHE;
5455
ALTER DATABASE current SET QUERY_STORE CLEAR ALL;
5556

5657
end
5758
GO
5859

5960

60-
CREATE procedure [dbo].[auto_tuning_off]
61+
CREATE OR ALTER PROCEDURE [dbo].[auto_tuning_off]
6162
as begin
6263

6364
ALTER DATABASE current SET AUTOMATIC_TUNING ( FORCE_LAST_GOOD_PLAN = OFF);
64-
DBCC FREEPROCCACHE;
65+
ALTER DATABASE SCOPED CONFIGURATION CLEAR PROCEDURE_CACHE;
6566
ALTER DATABASE current SET QUERY_STORE CLEAR ALL;
6667

6768
end
68-
GO
69+
GO
70+
71+
CREATE EVENT SESSION [APC - plans that are not corrected] ON SERVER
72+
73+
ADD EVENT qds.automatic_tuning_plan_regression_detection_check_completed(
74+
WHERE ((([is_regression_detected]=(1))
75+
AND ([is_regression_corrected]=(0)))
76+
AND ([option_id]=(1))))
77+
ADD TARGET package0.event_file(SET filename=N'plans_that_are_not_corrected')
78+
WITH (STARTUP_STATE=ON);
79+
GO
80+
81+
ALTER EVENT SESSION [APC - plans that are not corrected] ON SERVER STATE = start;

0 commit comments

Comments
 (0)