Skip to content

Commit e59d108

Browse files
author
pmasl
committed
Adding IQP demos
cc/ josackmsft
1 parent 676755e commit e59d108

6 files changed

Lines changed: 303 additions & 0 deletions
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
-- ***************************************************** --
2+
-- Purpose of this script: make WideWorldImportersDW
3+
-- bigger - so you can see more impactful
4+
-- Intelligent QP demonstrations (aka.ms/iqp)
5+
--
6+
-- Script last updated 10/02/2018
7+
--
8+
-- Database backup source: aka.ms/wwibak
9+
--
10+
-- Initial database file to restore before beginning this script:
11+
-- WideWorldImportersDW-Full.bak
12+
-- ***************************************************** --
13+
14+
USE WideWorldImportersDW;
15+
GO
16+
17+
/*
18+
Assumes a fresh restore of WideWorldImportersDW
19+
*/
20+
21+
IF OBJECT_ID('Fact.OrderHistory') IS NULL BEGIN
22+
SELECT [Order Key], [City Key], [Customer Key], [Stock Item Key], [Order Date Key], [Picked Date Key], [Salesperson Key], [Picker Key], [WWI Order ID], [WWI Backorder ID], Description, Package, Quantity, [Unit Price], [Tax Rate], [Total Excluding Tax], [Tax Amount], [Total Including Tax], [Lineage Key]
23+
INTO Fact.OrderHistory
24+
FROM Fact.[Order];
25+
END;
26+
27+
ALTER TABLE Fact.OrderHistory
28+
ADD CONSTRAINT PK_Fact_OrderHistory PRIMARY KEY NONCLUSTERED([Order Key] ASC, [Order Date Key] ASC)WITH(DATA_COMPRESSION=PAGE);
29+
GO
30+
31+
CREATE INDEX IX_Stock_Item_Key
32+
ON Fact.OrderHistory([Stock Item Key])
33+
INCLUDE(Quantity)
34+
WITH(DATA_COMPRESSION=PAGE);
35+
GO
36+
37+
CREATE INDEX IX_OrderHistory_Quantity
38+
ON Fact.OrderHistory([Quantity])
39+
INCLUDE([Order Key])
40+
WITH(DATA_COMPRESSION=PAGE);
41+
GO
42+
43+
/*
44+
Reality check... Starting count should be 231,412
45+
*/
46+
SELECT COUNT(*) FROM Fact.OrderHistory;
47+
GO
48+
49+
/*
50+
Make this table bigger (exec as desired)
51+
Notice the "GO 4"
52+
*/
53+
INSERT Fact.OrderHistory([City Key], [Customer Key], [Stock Item Key], [Order Date Key], [Picked Date Key], [Salesperson Key], [Picker Key], [WWI Order ID], [WWI Backorder ID], Description, Package, Quantity, [Unit Price], [Tax Rate], [Total Excluding Tax], [Tax Amount], [Total Including Tax], [Lineage Key])
54+
SELECT [City Key], [Customer Key], [Stock Item Key], [Order Date Key], [Picked Date Key], [Salesperson Key], [Picker Key], [WWI Order ID], [WWI Backorder ID], Description, Package, Quantity, [Unit Price], [Tax Rate], [Total Excluding Tax], [Tax Amount], [Total Including Tax], [Lineage Key]
55+
FROM Fact.OrderHistory;
56+
GO 4
57+
58+
/*
59+
Should be 3,702,592
60+
*/
61+
SELECT COUNT(*) FROM Fact.OrderHistory;
62+
GO
63+
64+
IF OBJECT_ID('Fact.OrderHistoryExtended') IS NULL BEGIN
65+
SELECT [Order Key], [City Key], [Customer Key], [Stock Item Key], [Order Date Key], [Picked Date Key], [Salesperson Key], [Picker Key], [WWI Order ID], [WWI Backorder ID], Description, Package, Quantity, [Unit Price], [Tax Rate], [Total Excluding Tax], [Tax Amount], [Total Including Tax], [Lineage Key]
66+
INTO Fact.OrderHistoryExtended
67+
FROM Fact.[OrderHistory];
68+
END;
69+
70+
ALTER TABLE Fact.OrderHistoryExtended
71+
ADD CONSTRAINT PK_Fact_OrderHistoryExtended PRIMARY KEY NONCLUSTERED([Order Key] ASC, [Order Date Key] ASC)
72+
WITH(DATA_COMPRESSION=PAGE);
73+
GO
74+
75+
CREATE INDEX IX_Stock_Item_Key
76+
ON Fact.OrderHistoryExtended([Stock Item Key])
77+
INCLUDE(Quantity);
78+
GO
79+
80+
/*
81+
Should be 3,702,592
82+
*/
83+
SELECT COUNT(*) FROM Fact.OrderHistoryExtended;
84+
GO
85+
86+
/*
87+
Make this table bigger (exec as desired)
88+
Notice the "GO 3"
89+
*/
90+
INSERT Fact.OrderHistoryExtended([City Key], [Customer Key], [Stock Item Key], [Order Date Key], [Picked Date Key], [Salesperson Key], [Picker Key], [WWI Order ID], [WWI Backorder ID], Description, Package, Quantity, [Unit Price], [Tax Rate], [Total Excluding Tax], [Tax Amount], [Total Including Tax], [Lineage Key])
91+
SELECT [City Key], [Customer Key], [Stock Item Key], [Order Date Key], [Picked Date Key], [Salesperson Key], [Picker Key], [WWI Order ID], [WWI Backorder ID], Description, Package, Quantity, [Unit Price], [Tax Rate], [Total Excluding Tax], [Tax Amount], [Total Including Tax], [Lineage Key]
92+
FROM Fact.OrderHistoryExtended;
93+
GO 3
94+
95+
/*
96+
Should be 29,620,736
97+
*/
98+
SELECT COUNT(*) FROM Fact.OrderHistoryExtended;
99+
GO
100+
101+
UPDATE Fact.OrderHistoryExtended
102+
SET [WWI Order ID] = [Order Key];
103+
GO
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
-- ******************************************************** --
2+
-- Approximate count distinct
3+
4+
-- See https://aka.ms/IQP for more background
5+
6+
-- Demo scripts: https://aka.ms/IQPDemos
7+
8+
-- Demo uses SQL Server 2019 Public Preview and also works on Azure SQL DB
9+
10+
-- Email IntelligentQP@microsoft.com for questions\feedback
11+
-- ******************************************************** --
12+
USE WideWorldImportersDW;
13+
GO
14+
15+
-- Compare execution time and distinct counts
16+
SELECT COUNT(DISTINCT [WWI Order ID])
17+
FROM [Fact].[OrderHistoryExtended]
18+
OPTION (USE HINT('DISALLOW_BATCH_MODE'), RECOMPILE); -- Isolating out BMOR
19+
20+
SELECT APPROX_COUNT_DISTINCT([WWI Order ID])
21+
FROM [Fact].[OrderHistoryExtended]
22+
OPTION (USE HINT('DISALLOW_BATCH_MODE'), RECOMPILE); -- Isolating out BMOR
23+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
-- ******************************************************** --
2+
-- Batch mode on rowstore
3+
4+
-- See https://aka.ms/IQP for more background
5+
6+
-- Demo scripts: https://aka.ms/IQPDemos
7+
8+
-- This demo is on SQL Server 2019 Public Preview and coming soon to Azure SQL DB
9+
10+
-- Email IntelligentQP@microsoft.com for questions\feedback
11+
-- ******************************************************** --
12+
13+
ALTER DATABASE [WideWorldImportersDW] SET COMPATIBILITY_LEVEL = 150;
14+
GO
15+
16+
ALTER DATABASE SCOPED CONFIGURATION CLEAR PROCEDURE_CACHE;
17+
GO
18+
19+
-- Row mode due to hint
20+
SELECT [Tax Rate],
21+
[Lineage Key],
22+
SUM([Quantity]) AS SUM_QTY,
23+
SUM([Unit Price]) AS SUM_BASE_PRICE,
24+
COUNT(*) AS COUNT_ORDER
25+
FROM [Fact].[OrderHistoryExtended]
26+
WHERE [Order Date Key] <= dateadd(dd, -73, '2015-11-13')
27+
GROUP BY [Tax Rate],
28+
[Lineage Key]
29+
ORDER BY [Tax Rate],
30+
[Lineage Key]
31+
OPTION (RECOMPILE, USE HINT('DISALLOW_BATCH_MODE'));
32+
33+
-- Batch mode on rowstore eligible
34+
SELECT [Tax Rate],
35+
[Lineage Key],
36+
[Salesperson Key],
37+
SUM([Quantity]) AS SUM_QTY,
38+
SUM([Unit Price]) AS SUM_BASE_PRICE,
39+
COUNT(*) AS COUNT_ORDER
40+
FROM [Fact].[OrderHistoryExtended]
41+
WHERE [Order Date Key] <= dateadd(dd, -73, '2015-11-13')
42+
GROUP BY [Tax Rate],
43+
[Lineage Key],
44+
[Salesperson Key]
45+
ORDER BY [Tax Rate],
46+
[Lineage Key],
47+
[Salesperson Key]
48+
OPTION (RECOMPILE);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
-- ******************************************************** --
2+
-- Row mode memory grant feedback
3+
4+
-- See https://aka.ms/IQP for more background
5+
-- Demo scripts: https://aka.ms/IQPDemos
6+
7+
-- This demo is on SQL Server 2019 Public Preview and works in Azure SQL DB too
8+
-- SSMS v17.9 or higher
9+
10+
-- Email IntelligentQP@microsoft.com for questions\feedback
11+
-- ******************************************************** --
12+
13+
ALTER DATABASE WideWorldImportersDW SET COMPATIBILITY_LEVEL = 150;
14+
GO
15+
16+
ALTER DATABASE SCOPED CONFIGURATION CLEAR PROCEDURE_CACHE;
17+
GO
18+
19+
USE WideWorldImportersDW;
20+
GO
21+
22+
-- Simulate out-of-date stats
23+
UPDATE STATISTICS Fact.OrderHistory
24+
WITH ROWCOUNT = 1;
25+
GO
26+
27+
-- Include actual execution plan
28+
-- Execute once to see spills (row mode)
29+
-- Execute a second time to see correction
30+
SELECT
31+
fo.[Order Key], fo.Description,
32+
si.[Lead Time Days]
33+
FROM Fact.OrderHistory AS fo
34+
INNER HASH JOIN Dimension.[Stock Item] AS si
35+
ON fo.[Stock Item Key] = si.[Stock Item Key]
36+
WHERE fo.[Lineage Key] = 9
37+
AND si.[Lead Time Days] > 19;
38+
39+
-- Cleanup
40+
UPDATE STATISTICS Fact.OrderHistory
41+
WITH ROWCOUNT = 3702672;
42+
GO
43+
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
-- ******************************************************** --
2+
-- Table variable deferred compilation
3+
4+
-- See https://aka.ms/IQP for more background
5+
6+
-- Demo scripts: https://aka.ms/IQPDemos
7+
8+
-- This demo is on SQL Server 2019 Public Preview and works in Azure SQL DB too
9+
10+
-- Email IntelligentQP@microsoft.com for questions\feedback
11+
-- ******************************************************** --
12+
13+
USE [master];
14+
GO
15+
16+
ALTER DATABASE [WideWorldImportersDW] SET COMPATIBILITY_LEVEL = 140;
17+
GO
18+
19+
USE [WideWorldImportersDW];
20+
GO
21+
22+
DECLARE @Order TABLE
23+
([Order Key] BIGINT NOT NULL,
24+
[Quantity] INT NOT NULL
25+
);
26+
27+
INSERT @Order
28+
SELECT [Order Key], [Quantity]
29+
FROM [Fact].[OrderHistory]
30+
WHERE [Quantity] > 1;
31+
32+
-- Look at estimated rows, speed, join algorithm
33+
SELECT oh.[Order Key], oh.[Order Date Key],
34+
oh.[Unit Price], o.Quantity
35+
FROM Fact.OrderHistoryExtended AS oh
36+
INNER JOIN @Order AS o
37+
ON o.[Order Key] = oh.[Order Key]
38+
WHERE oh.[Unit Price] > 0.10
39+
ORDER BY oh.[Unit Price] DESC;
40+
GO
41+
42+
USE [master]
43+
GO
44+
45+
ALTER DATABASE [WideWorldImportersDW] SET COMPATIBILITY_LEVEL = 150
46+
GO
47+
48+
USE [WideWorldImportersDW]
49+
GO
50+
51+
DECLARE @Order TABLE
52+
([Order Key] BIGINT NOT NULL,
53+
[Quantity] INT NOT NULL
54+
);
55+
56+
INSERT @Order
57+
SELECT [Order Key], [Quantity]
58+
FROM [Fact].[OrderHistory]
59+
WHERE [Quantity] > 99;
60+
61+
-- Look at estimated rows, speed, join algorithm
62+
SELECT oh.[Order Key], oh.[Order Date Key],
63+
oh.[Unit Price], o.Quantity
64+
FROM Fact.OrderHistoryExtended AS oh
65+
INNER JOIN @Order AS o
66+
ON o.[Order Key] = oh.[Order Key]
67+
WHERE oh.[Unit Price] > 0.10
68+
ORDER BY oh.[Unit Price] DESC;
69+
GO
70+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Intelligent Query Processing Demos
2+
3+
Here are the instructions to prepare for demonstrating Intelligent QP's latest round of features:
4+
5+
1) Download WideWorldImportersDW-Full.bak from https://aka.ms/wwidwbak
6+
7+
2) Enlarge the database using the following script: https://aka.ms/wwidwenlarge
8+
9+
Demos (with more on the way!):
10+
11+
- [Row mode memory grant feedback](Intelligent%20QP%20Demos%20WideWorldImportersDW%20Public%20Preview%20-%20Row%20Mode%20MGF.sql)
12+
- [Batch mode on rowstore](Intelligent%20QP%20Demos%20WideWorldImportersDW%20Public%20Preview%20-%20Batch%20Mode%20on%20Rowstore.sql)
13+
- [APPROX_COUNT_DISTINCT](Intelligent%20QP%20Demos%20WideWorldImportersDW%20Public%20Preview%20-%20APPROX_COUNT_DISTINCT.sql)
14+
- [Table variable deferred compilation](Intelligent%20QP%20Demos%20WideWorldImportersDW%20Public%20Preview%20-%20TVDC.sql)
15+
16+
Email IntelligentQP@microsoft.com if questions in the meantime.

0 commit comments

Comments
 (0)