Skip to content

Commit c8a7012

Browse files
author
pmasl
committed
Updated IQP demos
1 parent 175e3c1 commit c8a7012

5 files changed

Lines changed: 26 additions & 15 deletions

samples/features/intelligent-query-processing/Intelligent QP Demos Enlarging WideWorldImportersDW.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,10 @@ GO
100100

101101
UPDATE Fact.OrderHistoryExtended
102102
SET [WWI Order ID] = [Order Key];
103+
GO
104+
105+
-- Repeat until log shrinks
106+
CHECKPOINT
107+
GO
108+
DBCC SHRINKFILE (N'WWI_Log' , 0, TRUNCATEONLY)
103109
GO

samples/features/intelligent-query-processing/Intelligent QP Demos WideWorldImportersDW Public Preview - Interleaved Execution.sql

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
USE [WideWorldImportersDW];
1818
GO
1919

20-
CREATE FUNCTION [Fact].[WhatIfOutlierEventQuantity](@event VARCHAR(15), @beginOrderDateKey DATE, @endOrderDateKey DATE)
20+
CREATE OR ALTER FUNCTION [Fact].[ufn_WhatIfOutlierEventQuantity](@event VARCHAR(15), @beginOrderDateKey DATE, @endOrderDateKey DATE)
2121
RETURNS @OutlierEventQuantity TABLE (
2222
[Order Key] [bigint],
2323
[City Key] [int] NOT NULL,
@@ -122,10 +122,10 @@ GO
122122
USE [WideWorldImportersDW];
123123
GO
124124

125-
SELECT [fo].[Order Key], [fo].[Description], [fo].[Package],
125+
SELECT [fo].[Order Key], [fo].[Description], [fo].[Package],
126126
[fo].[Quantity], [foo].[OutlierEventQuantity]
127-
FROM [Fact].[Order] AS [fo]
128-
INNER JOIN [Fact].[WhatIfOutlierEventQuantity]('Mild Recession',
127+
FROM [Fact].[Order] AS [fo]
128+
INNER JOIN [Fact].[ufn_WhatIfOutlierEventQuantity]('Mild Recession',
129129
'1-01-2013',
130130
'10-15-2014') AS [foo] ON [fo].[Order Key] = [foo].[Order Key]
131131
AND [fo].[City Key] = [foo].[City Key]
@@ -137,7 +137,7 @@ INNER JOIN [Fact].[WhatIfOutlierEventQuantity]('Mild Recession',
137137
AND [fo].[Picker Key] = [foo].[Picker Key]
138138
INNER JOIN [Dimension].[Stock Item] AS [si]
139139
ON [fo].[Stock Item Key] = [si].[Stock Item Key]
140-
WHERE [si].[Lead Time Days] > 0
140+
WHERE [si].[Lead Time Days] > 0
141141
AND [fo].[Quantity] > 50;
142142
GO
143143

@@ -153,10 +153,10 @@ GO
153153
USE [WideWorldImportersDW];
154154
GO
155155

156-
SELECT [fo].[Order Key], [fo].[Description], [fo].[Package],
156+
SELECT [fo].[Order Key], [fo].[Description], [fo].[Package],
157157
[fo].[Quantity], [foo].[OutlierEventQuantity]
158-
FROM [Fact].[Order] AS [fo]
159-
INNER JOIN [Fact].[WhatIfOutlierEventQuantity]('Mild Recession',
158+
FROM [Fact].[Order] AS [fo]
159+
INNER JOIN [Fact].[ufn_WhatIfOutlierEventQuantity]('Mild Recession',
160160
'1-01-2013',
161161
'10-15-2014') AS [foo] ON [fo].[Order Key] = [foo].[Order Key]
162162
AND [fo].[City Key] = [foo].[City Key]
@@ -168,6 +168,6 @@ INNER JOIN [Fact].[WhatIfOutlierEventQuantity]('Mild Recession',
168168
AND [fo].[Picker Key] = [foo].[Picker Key]
169169
INNER JOIN [Dimension].[Stock Item] AS [si]
170170
ON [fo].[Stock Item Key] = [si].[Stock Item Key]
171-
WHERE [si].[Lead Time Days] > 0
171+
WHERE [si].[Lead Time Days] > 0
172172
AND [fo].[Quantity] > 50;
173173
GO

samples/features/intelligent-query-processing/Intelligent QP Demos WideWorldImportersDW Public Preview - Scalar UDF Inlining.sql

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Adapted from SQL Server Books Online
2626
https://docs.microsoft.com/sql/relational-databases/user-defined-functions/scalar-udf-inlining?view=sqlallproducts-allversions
2727
*/
2828
CREATE OR ALTER FUNCTION
29-
dbo.customer_category(@CustomerKey INT)
29+
dbo.ufn_customer_category(@CustomerKey INT)
3030
RETURNS CHAR(10) AS
3131
BEGIN
3232
DECLARE @total_amount DECIMAL(18,2);
@@ -48,20 +48,25 @@ BEGIN
4848
END
4949
GO
5050

51+
SELECT * FROM sys.sql_modules
52+
WHERE object_id = OBJECT_ID('ufn_customer_category')
53+
GO
54+
5155
-- Before (show actual query execution plan for legacy behavior)
5256
SELECT TOP 100
5357
[Customer Key], [Customer],
54-
dbo.customer_category([Customer Key]) AS [Discount Price]
58+
dbo.ufn_customer_category([Customer Key]) AS [Discount Price]
5559
FROM [Dimension].[Customer]
5660
ORDER BY [Customer Key]
5761
OPTION (RECOMPILE,USE HINT('DISABLE_TSQL_SCALAR_UDF_INLINING'));
62+
GO
5863

5964
-- After (show actual query execution plan for Scalar UDF Inlining)
6065
SELECT TOP 100
6166
[Customer Key], [Customer],
62-
dbo.customer_category([Customer Key]) AS [Discount Price]
67+
dbo.ufn_customer_category([Customer Key]) AS [Discount Price]
6368
FROM [Dimension].[Customer]
6469
ORDER BY [Customer Key]
6570
OPTION (RECOMPILE);
66-
71+
GO
6772

samples/features/intelligent-query-processing/Intelligent QP Demos WideWorldImportersDW Public Preview - TVDC.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
USE [master];
1414
GO
1515

16-
ALTER DATABASE [WideWorldImportersDW] SET COMPATIBILITY_LEVEL = 150;
16+
ALTER DATABASE [WideWorldImportersDW] SET COMPATIBILITY_LEVEL = 140;
1717
GO
1818

1919
ALTER DATABASE SCOPED CONFIGURATION CLEAR PROCEDURE_CACHE;
@@ -30,7 +30,7 @@ DECLARE @Order TABLE
3030
INSERT @Order
3131
SELECT [Order Key], [Quantity]
3232
FROM [Fact].[OrderHistory]
33-
WHERE [Quantity] > 1;
33+
WHERE [Quantity] > 99;
3434

3535
-- Look at estimated rows, speed, join algorithm
3636
SELECT oh.[Order Key], oh.[Order Date Key],
1 KB
Binary file not shown.

0 commit comments

Comments
 (0)