mirror of
https://github.com/Microsoft/sql-server-samples.git
synced 2025-12-08 14:58:54 +00:00
Updated IQP demos
This commit is contained in:
+6
@@ -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
|
||||
+9
-9
@@ -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
|
||||
|
||||
+9
-4
@@ -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
|
||||
|
||||
|
||||
+2
-2
@@ -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],
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user