Updated IQP demos

This commit is contained in:
pmasl
2020-02-07 11:19:29 -08:00
parent 87bf25de8a
commit 54771ccd56
10 changed files with 92 additions and 89 deletions
@@ -5,7 +5,7 @@
-- Demo scripts: https://aka.ms/IQPDemos
-- Demo uses SQL Server 2019 Public Preview and also works on Azure SQL DB
-- Demo uses SQL Server 2019 and Azure SQL DB
-- Email IntelligentQP@microsoft.com for questions\feedback
-- ******************************************************** --
@@ -35,13 +35,15 @@ DELETE [Fact].[Order]
WHERE Quantity = 361;
INSERT [Fact].[Order]
([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])
([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 TOP 5 [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, 361, [Unit Price], [Tax Rate],
[Total Excluding Tax], [Tax Amount], [Total Including Tax],
[Lineage Key]
[Order Date Key], [Picked Date Key], [Salesperson Key],
[Picker Key], [WWI Order ID], [WWI Backorder ID],
Description, Package, 361, [Unit Price], [Tax Rate],
[Total Excluding Tax], [Tax Amount], [Total Including Tax],
[Lineage Key]
FROM [Fact].[Order];
GO
@@ -0,0 +1,57 @@
-- ******************************************************** --
-- 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 and Azure SQL DB
-- Email IntelligentQP@microsoft.com for questions\feedback
-- ******************************************************** --
USE [master];
GO
ALTER DATABASE [WideWorldImportersDW] SET COMPATIBILITY_LEVEL = 150;
GO
ALTER DATABASE SCOPED CONFIGURATION CLEAR PROCEDURE_CACHE;
GO
USE [WideWorldImportersDW];
GO
-- Row mode due to hint
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, 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);
@@ -22,7 +22,7 @@ USE [WideWorldImportersDW];
GO
CREATE OR ALTER FUNCTION [Fact].[ufn_WhatIfOutlierEventQuantity]
(@event VARCHAR(30), @beginOrderDateKey DATE, @endOrderDateKey DATE)
(@event VARCHAR(30), @beginOrderDateKey DATE, @endOrderDateKey DATE)
RETURNS @OutlierEventQuantity TABLE (
[Order Key] [bigint],
[City Key] [int] NOT NULL,
@@ -68,13 +68,13 @@ BEGIN
INNER JOIN [Dimension].[City] AS [c]
ON [c].[City Key] = [o].[City Key]
WHERE [c].[State Province] IN
('Florida', 'Georgia', 'Maryland', 'North Carolina',
'South Carolina', 'Virginia', 'West Virginia',
'Delaware')
('Florida', 'Georgia', 'Maryland', 'North Carolina',
'South Carolina', 'Virginia', 'West Virginia',
'Delaware')
AND [o].[Order Date Key] BETWEEN @beginOrderDateKey AND @endOrderDateKey
IF @event = 'Hurricane - East South Central'
INSERT @OutlierEventQuantity
INSERT @OutlierEventQuantity
SELECT [o].[Order Key], [o].[City Key], [o].[Customer Key],
[o].[Stock Item Key], [o].[Order Date Key], [o].[Picked Date Key],
[o].[Salesperson Key], [o].[Picker Key],
@@ -86,14 +86,14 @@ BEGIN
INNER JOIN [Dimension].[City] AS [c]
ON [c].[City Key] = [o].[City Key]
INNER JOIN [Dimension].[Stock Item] AS [si]
ON [si].[Stock Item Key] = [o].[Stock Item Key]
ON [si].[Stock Item Key] = [o].[Stock Item Key]
WHERE [c].[State Province] IN
('Alabama', 'Kentucky', 'Mississippi', 'Tennessee')
AND [si].[Buying Package] = 'Carton'
AND [o].[Order Date Key] BETWEEN @beginOrderDateKey AND @endOrderDateKey
IF @event = 'Hurricane - West South Central'
INSERT @OutlierEventQuantity
INSERT @OutlierEventQuantity
SELECT [o].[Order Key], [o].[City Key], [o].[Customer Key],
[o].[Stock Item Key], [o].[Order Date Key], [o].[Picked Date Key],
[o].[Salesperson Key], [o].[Picker Key],
@@ -107,7 +107,7 @@ BEGIN
INNER JOIN [Dimension].[City] AS [c]
ON [c].[City Key] = [o].[City Key]
INNER JOIN [Dimension].[Customer] AS [cu]
ON [cu].[Customer Key] = [o].[Customer Key]
ON [cu].[Customer Key] = [o].[Customer Key]
WHERE [c].[State Province] IN
('Arkansas', 'Louisiana', 'Oklahoma', 'Texas')
AND [o].[Order Date Key] BETWEEN @beginOrderDateKey AND @endOrderDateKey
@@ -4,7 +4,7 @@
-- 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
-- This demo is on SQL Server 2019 and Azure SQL DB
-- SSMS v17.9 or higher
-- Email IntelligentQP@microsoft.com for questions\feedback
@@ -30,8 +30,7 @@ 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,
SELECT fo.[Order Key], fo.Description,
si.[Lead Time Days]
FROM Fact.OrderHistory AS fo
INNER HASH JOIN Dimension.[Stock Item] AS si
@@ -5,7 +5,7 @@
-- Demo scripts: https://aka.ms/IQPDemos
-- Demo uses SQL Server 2019 Public Preview and also works on Azure SQL DB
-- Demo uses SQL Server 2019 and Azure SQL DB
-- Email IntelligentQP@microsoft.com for questions\feedback
-- ******************************************************** --
@@ -23,28 +23,27 @@ GO
/*
Adapted from SQL Server Books Online
https://docs.microsoft.com/sql/relational-databases/user-defined-functions/scalar-udf-inlining?view=sqlallproducts-allversions
https://docs.microsoft.com/sql/relational-databases/user-defined-functions/scalar-udf-inlining
*/
CREATE OR ALTER FUNCTION
dbo.ufn_customer_category(@CustomerKey INT)
RETURNS CHAR(10) AS
BEGIN
DECLARE @total_amount DECIMAL(18,2);
DECLARE @category CHAR(10);
DECLARE @total_amount DECIMAL(18,2);
DECLARE @category CHAR(10);
SELECT @total_amount =
SUM([Total Including Tax])
SELECT @total_amount = SUM([Total Including Tax])
FROM [Fact].[OrderHistory]
WHERE [Customer Key] = @CustomerKey;
IF @total_amount < 500000
SET @category = 'REGULAR';
ELSE IF @total_amount < 1000000
SET @category = 'GOLD';
ELSE
SET @category = 'PLATINUM';
IF @total_amount < 500000
SET @category = 'REGULAR';
ELSE IF @total_amount < 1000000
SET @category = 'GOLD';
ELSE
SET @category = 'PLATINUM';
RETURN @category;
RETURN @category;
END
GO
@@ -5,7 +5,7 @@
-- Demo scripts: https://aka.ms/IQPDemos
-- This demo is on SQL Server 2019 Public Preview and works in Azure SQL DB too
-- This demo is on SQL Server 2019 and Azure SQL DB
-- Email IntelligentQP@microsoft.com for questions\feedback
-- ******************************************************** --
@@ -34,7 +34,7 @@ WHERE [Quantity] > 99;
-- Look at estimated rows, speed, join algorithm
SELECT oh.[Order Key], oh.[Order Date Key],
oh.[Unit Price], o.Quantity
oh.[Unit Price], o.Quantity
FROM Fact.OrderHistoryExtended AS oh
INNER JOIN @Order AS o
ON o.[Order Key] = oh.[Order Key]
@@ -59,11 +59,11 @@ DECLARE @Order TABLE
INSERT @Order
SELECT [Order Key], [Quantity]
FROM [Fact].[OrderHistory]
WHERE [Quantity] > 99;
WHERE [Quantity] > 99;
-- Look at estimated rows, speed, join algorithm
SELECT oh.[Order Key], oh.[Order Date Key],
oh.[Unit Price], o.Quantity
oh.[Unit Price], o.Quantity
FROM Fact.OrderHistoryExtended AS oh
INNER JOIN @Order AS o
ON o.[Order Key] = oh.[Order Key]
@@ -1,54 +0,0 @@
-- ******************************************************** --
-- 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
-- ******************************************************** --
USE [master];
GO
ALTER DATABASE [WideWorldImportersDW] SET COMPATIBILITY_LEVEL = 150;
GO
ALTER DATABASE SCOPED CONFIGURATION CLEAR PROCEDURE_CACHE;
GO
USE [WideWorldImportersDW];
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);