Updated IQP demos

This commit is contained in:
pmasl
2019-06-20 12:42:52 -07:00
parent 175e3c1591
commit c8a7012f5b
5 changed files with 26 additions and 15 deletions
@@ -100,4 +100,10 @@ GO
UPDATE Fact.OrderHistoryExtended
SET [WWI Order ID] = [Order Key];
GO
-- Repeat until log shrinks
CHECKPOINT
GO
DBCC SHRINKFILE (N'WWI_Log' , 0, TRUNCATEONLY)
GO
@@ -17,7 +17,7 @@
USE [WideWorldImportersDW];
GO
CREATE FUNCTION [Fact].[WhatIfOutlierEventQuantity](@event VARCHAR(15), @beginOrderDateKey DATE, @endOrderDateKey DATE)
CREATE OR ALTER FUNCTION [Fact].[ufn_WhatIfOutlierEventQuantity](@event VARCHAR(15), @beginOrderDateKey DATE, @endOrderDateKey DATE)
RETURNS @OutlierEventQuantity TABLE (
[Order Key] [bigint],
[City Key] [int] NOT NULL,
@@ -122,10 +122,10 @@ GO
USE [WideWorldImportersDW];
GO
SELECT [fo].[Order Key], [fo].[Description], [fo].[Package],
SELECT [fo].[Order Key], [fo].[Description], [fo].[Package],
[fo].[Quantity], [foo].[OutlierEventQuantity]
FROM [Fact].[Order] AS [fo]
INNER JOIN [Fact].[WhatIfOutlierEventQuantity]('Mild Recession',
FROM [Fact].[Order] AS [fo]
INNER JOIN [Fact].[ufn_WhatIfOutlierEventQuantity]('Mild Recession',
'1-01-2013',
'10-15-2014') AS [foo] ON [fo].[Order Key] = [foo].[Order Key]
AND [fo].[City Key] = [foo].[City Key]
@@ -137,7 +137,7 @@ INNER JOIN [Fact].[WhatIfOutlierEventQuantity]('Mild Recession',
AND [fo].[Picker Key] = [foo].[Picker Key]
INNER JOIN [Dimension].[Stock Item] AS [si]
ON [fo].[Stock Item Key] = [si].[Stock Item Key]
WHERE [si].[Lead Time Days] > 0
WHERE [si].[Lead Time Days] > 0
AND [fo].[Quantity] > 50;
GO
@@ -153,10 +153,10 @@ GO
USE [WideWorldImportersDW];
GO
SELECT [fo].[Order Key], [fo].[Description], [fo].[Package],
SELECT [fo].[Order Key], [fo].[Description], [fo].[Package],
[fo].[Quantity], [foo].[OutlierEventQuantity]
FROM [Fact].[Order] AS [fo]
INNER JOIN [Fact].[WhatIfOutlierEventQuantity]('Mild Recession',
FROM [Fact].[Order] AS [fo]
INNER JOIN [Fact].[ufn_WhatIfOutlierEventQuantity]('Mild Recession',
'1-01-2013',
'10-15-2014') AS [foo] ON [fo].[Order Key] = [foo].[Order Key]
AND [fo].[City Key] = [foo].[City Key]
@@ -168,6 +168,6 @@ INNER JOIN [Fact].[WhatIfOutlierEventQuantity]('Mild Recession',
AND [fo].[Picker Key] = [foo].[Picker Key]
INNER JOIN [Dimension].[Stock Item] AS [si]
ON [fo].[Stock Item Key] = [si].[Stock Item Key]
WHERE [si].[Lead Time Days] > 0
WHERE [si].[Lead Time Days] > 0
AND [fo].[Quantity] > 50;
GO
@@ -26,7 +26,7 @@ Adapted from SQL Server Books Online
https://docs.microsoft.com/sql/relational-databases/user-defined-functions/scalar-udf-inlining?view=sqlallproducts-allversions
*/
CREATE OR ALTER FUNCTION
dbo.customer_category(@CustomerKey INT)
dbo.ufn_customer_category(@CustomerKey INT)
RETURNS CHAR(10) AS
BEGIN
DECLARE @total_amount DECIMAL(18,2);
@@ -48,20 +48,25 @@ BEGIN
END
GO
SELECT * FROM sys.sql_modules
WHERE object_id = OBJECT_ID('ufn_customer_category')
GO
-- Before (show actual query execution plan for legacy behavior)
SELECT TOP 100
[Customer Key], [Customer],
dbo.customer_category([Customer Key]) AS [Discount Price]
dbo.ufn_customer_category([Customer Key]) AS [Discount Price]
FROM [Dimension].[Customer]
ORDER BY [Customer Key]
OPTION (RECOMPILE,USE HINT('DISABLE_TSQL_SCALAR_UDF_INLINING'));
GO
-- After (show actual query execution plan for Scalar UDF Inlining)
SELECT TOP 100
[Customer Key], [Customer],
dbo.customer_category([Customer Key]) AS [Discount Price]
dbo.ufn_customer_category([Customer Key]) AS [Discount Price]
FROM [Dimension].[Customer]
ORDER BY [Customer Key]
OPTION (RECOMPILE);
GO
@@ -13,7 +13,7 @@
USE [master];
GO
ALTER DATABASE [WideWorldImportersDW] SET COMPATIBILITY_LEVEL = 150;
ALTER DATABASE [WideWorldImportersDW] SET COMPATIBILITY_LEVEL = 140;
GO
ALTER DATABASE SCOPED CONFIGURATION CLEAR PROCEDURE_CACHE;
@@ -30,7 +30,7 @@ DECLARE @Order TABLE
INSERT @Order
SELECT [Order Key], [Quantity]
FROM [Fact].[OrderHistory]
WHERE [Quantity] > 1;
WHERE [Quantity] > 99;
-- Look at estimated rows, speed, join algorithm
SELECT oh.[Order Key], oh.[Order Date Key],