This repository has been archived by the owner on Nov 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinit-db.sql
92 lines (69 loc) · 2.56 KB
/
init-db.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
USE WideWorldImporters;
-- Insert one OrderLine that with PackageTypeID=(0) will cause regression
INSERT INTO Warehouse.PackageTypes (PackageTypeID, PackageTypeName, LastEditedBy)
VALUES (0, 'FLGP', 1);
INSERT INTO Sales.OrderLines(OrderId, StockItemID, Description, PAckageTypeID, quantity, unitprice, taxrate, PickedQuantity,LastEditedBy)
SELECT TOP 1 OrderID, StockItemID, Description, PackageTypeID = 0, Quantity, UnitPrice, taxrate , PickedQuantity,LastEditedBy
FROM Sales.OrderLines;
-- Add PackageTypeID column into the NCCI index on Sales.OrderLines table
DROP INDEX IF EXISTS [NCCX_Sales_OrderLines] ON [Sales].[OrderLines]
CREATE NONCLUSTERED COLUMNSTORE INDEX [NCCX_Sales_OrderLines] ON [Sales].[OrderLines]
(
[OrderID],
[StockItemID],
[Description],
[Quantity],
[UnitPrice],
[PickedQuantity],
[PackageTypeID] -- adding package type id for demo purpose
)WITH (DROP_EXISTING = OFF, COMPRESSION_DELAY = 0)
GO
CREATE OR ALTER PROCEDURE [dbo].[initialize]
AS BEGIN
ALTER DATABASE SCOPED CONFIGURATION CLEAR PROCEDURE_CACHE;
ALTER DATABASE current SET QUERY_STORE CLEAR ALL;
END
GO
CREATE OR ALTER PROCEDURE [dbo].[report] (@packagetypeid int)
AS BEGIN
EXEC sp_executesql N'select avg([UnitPrice]*[Quantity])
from Sales.OrderLines
where PackageTypeID = @packagetypeid', N'@packagetypeid int', @packagetypeid;
END
GO
CREATE OR ALTER PROCEDURE [dbo].[regression]
AS BEGIN
ALTER DATABASE SCOPED CONFIGURATION CLEAR PROCEDURE_CACHE;
BEGIN
declare @packagetypeid int = 0;
exec report @packagetypeid;
END
END
GO
CREATE OR ALTER PROCEDURE [dbo].[auto_tuning_on]
AS BEGIN
ALTER DATABASE current SET AUTOMATIC_TUNING ( FORCE_LAST_GOOD_PLAN = ON);
ALTER DATABASE SCOPED CONFIGURATION CLEAR PROCEDURE_CACHE;
ALTER DATABASE current SET QUERY_STORE CLEAR ALL;
END
GO
CREATE OR ALTER PROCEDURE [dbo].[auto_tuning_off]
AS BEGIN
ALTER DATABASE current SET AUTOMATIC_TUNING ( FORCE_LAST_GOOD_PLAN = OFF);
ALTER DATABASE SCOPED CONFIGURATION CLEAR PROCEDURE_CACHE;
ALTER DATABASE current SET QUERY_STORE CLEAR ALL;
END
GO
/*
CREATE EVENT SESSION [APC - plans that are not corrected] ON DATABASE
ADD EVENT qds.automatic_tuning_plan_regression_detection_check_completed(
WHERE ((([is_regression_detected]=(1))
AND ([is_regression_corrected]=(0)))
AND ([option_id]=(0))))
-- Use file target only on SQL Server 2017:
-- ADD TARGET package0.event_file(SET filename=N'plans_that_are_not_corrected')
ADD TARGET package0.ring_buffer (SET max_memory = 1000)
WITH (STARTUP_STATE=ON);
GO
ALTER EVENT SESSION [APC - plans that are not corrected] ON SERVER STATE = start;
*/