Merge pull request #537 from Microsoft/pmasl

Adding IQP demos
This commit is contained in:
Pedro Lopes
2019-03-11 15:31:25 -07:00
committed by GitHub
6 changed files with 303 additions and 0 deletions
@@ -0,0 +1,103 @@
-- ***************************************************** --
-- Purpose of this script: make WideWorldImportersDW
-- bigger - so you can see more impactful
-- Intelligent QP demonstrations (aka.ms/iqp)
--
-- Script last updated 10/02/2018
--
-- Database backup source: aka.ms/wwibak
--
-- Initial database file to restore before beginning this script:
-- WideWorldImportersDW-Full.bak
-- ***************************************************** --
USE WideWorldImportersDW;
GO
/*
Assumes a fresh restore of WideWorldImportersDW
*/
IF OBJECT_ID('Fact.OrderHistory') IS NULL BEGIN
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]
INTO Fact.OrderHistory
FROM Fact.[Order];
END;
ALTER TABLE Fact.OrderHistory
ADD CONSTRAINT PK_Fact_OrderHistory PRIMARY KEY NONCLUSTERED([Order Key] ASC, [Order Date Key] ASC)WITH(DATA_COMPRESSION=PAGE);
GO
CREATE INDEX IX_Stock_Item_Key
ON Fact.OrderHistory([Stock Item Key])
INCLUDE(Quantity)
WITH(DATA_COMPRESSION=PAGE);
GO
CREATE INDEX IX_OrderHistory_Quantity
ON Fact.OrderHistory([Quantity])
INCLUDE([Order Key])
WITH(DATA_COMPRESSION=PAGE);
GO
/*
Reality check... Starting count should be 231,412
*/
SELECT COUNT(*) FROM Fact.OrderHistory;
GO
/*
Make this table bigger (exec as desired)
Notice the "GO 4"
*/
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])
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]
FROM Fact.OrderHistory;
GO 4
/*
Should be 3,702,592
*/
SELECT COUNT(*) FROM Fact.OrderHistory;
GO
IF OBJECT_ID('Fact.OrderHistoryExtended') IS NULL BEGIN
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]
INTO Fact.OrderHistoryExtended
FROM Fact.[OrderHistory];
END;
ALTER TABLE Fact.OrderHistoryExtended
ADD CONSTRAINT PK_Fact_OrderHistoryExtended PRIMARY KEY NONCLUSTERED([Order Key] ASC, [Order Date Key] ASC)
WITH(DATA_COMPRESSION=PAGE);
GO
CREATE INDEX IX_Stock_Item_Key
ON Fact.OrderHistoryExtended([Stock Item Key])
INCLUDE(Quantity);
GO
/*
Should be 3,702,592
*/
SELECT COUNT(*) FROM Fact.OrderHistoryExtended;
GO
/*
Make this table bigger (exec as desired)
Notice the "GO 3"
*/
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])
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]
FROM Fact.OrderHistoryExtended;
GO 3
/*
Should be 29,620,736
*/
SELECT COUNT(*) FROM Fact.OrderHistoryExtended;
GO
UPDATE Fact.OrderHistoryExtended
SET [WWI Order ID] = [Order Key];
GO
@@ -0,0 +1,23 @@
-- ******************************************************** --
-- Approximate count distinct
-- See https://aka.ms/IQP for more background
-- Demo scripts: https://aka.ms/IQPDemos
-- Demo uses SQL Server 2019 Public Preview and also works on Azure SQL DB
-- Email IntelligentQP@microsoft.com for questions\feedback
-- ******************************************************** --
USE WideWorldImportersDW;
GO
-- Compare execution time and distinct counts
SELECT COUNT(DISTINCT [WWI Order ID])
FROM [Fact].[OrderHistoryExtended]
OPTION (USE HINT('DISALLOW_BATCH_MODE'), RECOMPILE); -- Isolating out BMOR
SELECT APPROX_COUNT_DISTINCT([WWI Order ID])
FROM [Fact].[OrderHistoryExtended]
OPTION (USE HINT('DISALLOW_BATCH_MODE'), RECOMPILE); -- Isolating out BMOR
@@ -0,0 +1,48 @@
-- ******************************************************** --
-- Batch mode on rowstore
-- See https://aka.ms/IQP for more background
-- Demo scripts: https://aka.ms/IQPDemos
-- This demo is on SQL Server 2019 Public Preview and coming soon to Azure SQL DB
-- Email IntelligentQP@microsoft.com for questions\feedback
-- ******************************************************** --
ALTER DATABASE [WideWorldImportersDW] SET COMPATIBILITY_LEVEL = 150;
GO
ALTER DATABASE SCOPED CONFIGURATION CLEAR PROCEDURE_CACHE;
GO
-- Row mode due to hint
SELECT [Tax Rate],
[Lineage Key],
SUM([Quantity]) AS SUM_QTY,
SUM([Unit Price]) AS SUM_BASE_PRICE,
COUNT(*) AS COUNT_ORDER
FROM [Fact].[OrderHistoryExtended]
WHERE [Order Date Key] <= dateadd(dd, -73, '2015-11-13')
GROUP BY [Tax Rate],
[Lineage Key]
ORDER BY [Tax Rate],
[Lineage Key]
OPTION (RECOMPILE, USE HINT('DISALLOW_BATCH_MODE'));
-- Batch mode on rowstore eligible
SELECT [Tax Rate],
[Lineage Key],
[Salesperson Key],
SUM([Quantity]) AS SUM_QTY,
SUM([Unit Price]) AS SUM_BASE_PRICE,
COUNT(*) AS COUNT_ORDER
FROM [Fact].[OrderHistoryExtended]
WHERE [Order Date Key] <= dateadd(dd, -73, '2015-11-13')
GROUP BY [Tax Rate],
[Lineage Key],
[Salesperson Key]
ORDER BY [Tax Rate],
[Lineage Key],
[Salesperson Key]
OPTION (RECOMPILE);
@@ -0,0 +1,43 @@
-- ******************************************************** --
-- Row mode memory grant feedback
-- See https://aka.ms/IQP for more background
-- Demo scripts: https://aka.ms/IQPDemos
-- This demo is on SQL Server 2019 Public Preview and works in Azure SQL DB too
-- SSMS v17.9 or higher
-- Email IntelligentQP@microsoft.com for questions\feedback
-- ******************************************************** --
ALTER DATABASE WideWorldImportersDW SET COMPATIBILITY_LEVEL = 150;
GO
ALTER DATABASE SCOPED CONFIGURATION CLEAR PROCEDURE_CACHE;
GO
USE WideWorldImportersDW;
GO
-- Simulate out-of-date stats
UPDATE STATISTICS Fact.OrderHistory
WITH ROWCOUNT = 1;
GO
-- Include actual execution plan
-- Execute once to see spills (row mode)
-- Execute a second time to see correction
SELECT
fo.[Order Key], fo.Description,
si.[Lead Time Days]
FROM Fact.OrderHistory AS fo
INNER HASH JOIN Dimension.[Stock Item] AS si
ON fo.[Stock Item Key] = si.[Stock Item Key]
WHERE fo.[Lineage Key] = 9
AND si.[Lead Time Days] > 19;
-- Cleanup
UPDATE STATISTICS Fact.OrderHistory
WITH ROWCOUNT = 3702672;
GO
@@ -0,0 +1,70 @@
-- ******************************************************** --
-- Table variable deferred compilation
-- See https://aka.ms/IQP for more background
-- Demo scripts: https://aka.ms/IQPDemos
-- This demo is on SQL Server 2019 Public Preview and works in Azure SQL DB too
-- Email IntelligentQP@microsoft.com for questions\feedback
-- ******************************************************** --
USE [master];
GO
ALTER DATABASE [WideWorldImportersDW] SET COMPATIBILITY_LEVEL = 140;
GO
USE [WideWorldImportersDW];
GO
DECLARE @Order TABLE
([Order Key] BIGINT NOT NULL,
[Quantity] INT NOT NULL
);
INSERT @Order
SELECT [Order Key], [Quantity]
FROM [Fact].[OrderHistory]
WHERE [Quantity] > 1;
-- Look at estimated rows, speed, join algorithm
SELECT oh.[Order Key], oh.[Order Date Key],
oh.[Unit Price], o.Quantity
FROM Fact.OrderHistoryExtended AS oh
INNER JOIN @Order AS o
ON o.[Order Key] = oh.[Order Key]
WHERE oh.[Unit Price] > 0.10
ORDER BY oh.[Unit Price] DESC;
GO
USE [master]
GO
ALTER DATABASE [WideWorldImportersDW] SET COMPATIBILITY_LEVEL = 150
GO
USE [WideWorldImportersDW]
GO
DECLARE @Order TABLE
([Order Key] BIGINT NOT NULL,
[Quantity] INT NOT NULL
);
INSERT @Order
SELECT [Order Key], [Quantity]
FROM [Fact].[OrderHistory]
WHERE [Quantity] > 99;
-- Look at estimated rows, speed, join algorithm
SELECT oh.[Order Key], oh.[Order Date Key],
oh.[Unit Price], o.Quantity
FROM Fact.OrderHistoryExtended AS oh
INNER JOIN @Order AS o
ON o.[Order Key] = oh.[Order Key]
WHERE oh.[Unit Price] > 0.10
ORDER BY oh.[Unit Price] DESC;
GO
@@ -0,0 +1,16 @@
# Intelligent Query Processing Demos
Here are the instructions to prepare for demonstrating Intelligent QP's latest round of features:
1) Download WideWorldImportersDW-Full.bak from https://aka.ms/wwidwbak
2) Enlarge the database using the following script: https://aka.ms/wwidwenlarge
Demos (with more on the way!):
- [Row mode memory grant feedback](Intelligent%20QP%20Demos%20WideWorldImportersDW%20Public%20Preview%20-%20Row%20Mode%20MGF.sql)
- [Batch mode on rowstore](Intelligent%20QP%20Demos%20WideWorldImportersDW%20Public%20Preview%20-%20Batch%20Mode%20on%20Rowstore.sql)
- [APPROX_COUNT_DISTINCT](Intelligent%20QP%20Demos%20WideWorldImportersDW%20Public%20Preview%20-%20APPROX_COUNT_DISTINCT.sql)
- [Table variable deferred compilation](Intelligent%20QP%20Demos%20WideWorldImportersDW%20Public%20Preview%20-%20TVDC.sql)
Email IntelligentQP@microsoft.com if questions in the meantime.