Skip to content

Commit 12b13d4

Browse files
committed
Merge branch 'resolve-conflict'
2 parents 26e9c39 + 2cb7d56 commit 12b13d4

25 files changed

Lines changed: 1151 additions & 909 deletions

.gitignore

Lines changed: 443 additions & 439 deletions
Large diffs are not rendered by default.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
-- bigger - so you can see more impactful
44
-- Intelligent QP demonstrations (aka.ms/iqp)
55
--
6-
-- Script last updated 10/02/2018
6+
-- Script last updated 05/03/2019
77
--
88
-- Database backup source: aka.ms/wwibak
99
--
@@ -100,4 +100,4 @@ GO
100100

101101
UPDATE Fact.OrderHistoryExtended
102102
SET [WWI Order ID] = [Order Key];
103-
GO
103+
GO

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,17 @@
99

1010
-- Email IntelligentQP@microsoft.com for questions\feedback
1111
-- ******************************************************** --
12-
USE WideWorldImportersDW;
12+
13+
USE [master];
14+
GO
15+
16+
ALTER DATABASE [WideWorldImportersDW] SET COMPATIBILITY_LEVEL = 150;
17+
GO
18+
19+
ALTER DATABASE SCOPED CONFIGURATION CLEAR PROCEDURE_CACHE;
20+
GO
21+
22+
USE [WideWorldImportersDW];
1323
GO
1424

1525
-- Compare execution time and distinct counts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
-- ******************************************************** --
2+
-- Batch mode Adaptive Join
3+
4+
-- See https://aka.ms/IQP for more background
5+
6+
-- Demo scripts: https://aka.ms/IQPDemos
7+
8+
-- This demo is on SQL Server 2017 and Azure SQL DB
9+
10+
-- Email IntelligentQP@microsoft.com for questions\feedback
11+
-- ******************************************************** --
12+
13+
USE [master];
14+
GO
15+
16+
ALTER DATABASE [WideWorldImportersDW] SET COMPATIBILITY_LEVEL = 140;
17+
GO
18+
19+
ALTER DATABASE SCOPED CONFIGURATION CLEAR PROCEDURE_CACHE;
20+
GO
21+
22+
USE [WideWorldImportersDW];
23+
GO
24+
25+
-- Show with Live Query Stats
26+
SELECT [fo].[Order Key], [si].[Lead Time Days], [fo].[Quantity]
27+
FROM [Fact].[Order] AS [fo]
28+
INNER JOIN [Dimension].[Stock Item] AS [si]
29+
ON [fo].[Stock Item Key] = [si].[Stock Item Key]
30+
WHERE [fo].[Quantity] = 360;
31+
GO
32+
33+
-- Inserting quantity row that doesn't exist in the table yet
34+
DELETE [Fact].[Order]
35+
WHERE Quantity = 361;
36+
37+
INSERT [Fact].[Order]
38+
([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])
39+
SELECT TOP 5 [City Key], [Customer Key], [Stock Item Key],
40+
[Order Date Key], [Picked Date Key], [Salesperson Key],
41+
[Picker Key], [WWI Order ID], [WWI Backorder ID],
42+
Description, Package, 361, [Unit Price], [Tax Rate],
43+
[Total Excluding Tax], [Tax Amount], [Total Including Tax],
44+
[Lineage Key]
45+
FROM [Fact].[Order];
46+
GO
47+
48+
-- Show with Live Query Stats
49+
SELECT [fo].[Order Key], [si].[Lead Time Days], [fo].[Quantity]
50+
FROM [Fact].[Order] AS [fo]
51+
INNER JOIN [Dimension].[Stock Item] AS [si]
52+
ON [fo].[Stock Item Key] = [si].[Stock Item Key]
53+
WHERE [fo].[Quantity] = 361;
54+
GO
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
-- ******************************************************** --
2+
-- Batch mode Memory Grant Feedback
3+
4+
-- See https://aka.ms/IQP for more background
5+
6+
-- Demo scripts: https://aka.ms/IQPDemos
7+
8+
-- This demo is on SQL Server 2017 and Azure SQL DB
9+
10+
-- Email IntelligentQP@microsoft.com for questions\feedback
11+
-- ******************************************************** --
12+
13+
USE [master];
14+
GO
15+
16+
ALTER DATABASE [WideWorldImportersDW] SET COMPATIBILITY_LEVEL = 140;
17+
GO
18+
19+
ALTER DATABASE SCOPED CONFIGURATION CLEAR PROCEDURE_CACHE;
20+
GO
21+
22+
USE [WideWorldImportersDW];
23+
GO
24+
25+
-- Intentionally forcing a row underestimate
26+
CREATE OR ALTER PROCEDURE [FactOrderByLineageKey]
27+
@LineageKey INT
28+
AS
29+
SELECT [fo].[Order Key], [fo].[Description]
30+
FROM [Fact].[Order] AS [fo]
31+
INNER HASH JOIN [Dimension].[Stock Item] AS [si]
32+
ON [fo].[Stock Item Key] = [si].[Stock Item Key]
33+
WHERE [fo].[Lineage Key] = @LineageKey
34+
AND [si].[Lead Time Days] > 0
35+
ORDER BY [fo].[Stock Item Key], [fo].[Order Date Key] DESC
36+
OPTION (MAXDOP 1);
37+
GO
38+
39+
-- Compiled and executed using a lineage key that doesn't have rows
40+
EXEC [FactOrderByLineageKey] 8;
41+
GO
42+
43+
-- Execute this query a few times - each time looking at
44+
-- the plan to see impact on spills, memory grant size, and run time
45+
EXEC [FactOrderByLineageKey] 9;
46+
GO

samples/features/intelligent-query-processing/Intelligent QP Demos WideWorldImportersDW Public Preview - Batch Mode on Rowstore.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,18 @@
1010
-- Email IntelligentQP@microsoft.com for questions\feedback
1111
-- ******************************************************** --
1212

13+
USE [master];
14+
GO
15+
1316
ALTER DATABASE [WideWorldImportersDW] SET COMPATIBILITY_LEVEL = 150;
1417
GO
1518

1619
ALTER DATABASE SCOPED CONFIGURATION CLEAR PROCEDURE_CACHE;
1720
GO
1821

22+
USE [WideWorldImportersDW];
23+
GO
24+
1925
-- Row mode due to hint
2026
SELECT [Tax Rate],
2127
[Lineage Key],
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
-- ******************************************************** --
2+
-- Interleaved Execution
3+
4+
-- See https://aka.ms/IQP for more background
5+
6+
-- Demo scripts: https://aka.ms/IQPDemos
7+
8+
-- This demo is on SQL Server 2017 and Azure SQL DB
9+
10+
-- Email IntelligentQP@microsoft.com for questions\feedback
11+
-- ******************************************************** --
12+
13+
/*
14+
Create MSTVF
15+
*/
16+
17+
USE [WideWorldImportersDW];
18+
GO
19+
20+
CREATE FUNCTION [Fact].[WhatIfOutlierEventQuantity](@event VARCHAR(15), @beginOrderDateKey DATE, @endOrderDateKey DATE)
21+
RETURNS @OutlierEventQuantity TABLE (
22+
[Order Key] [bigint],
23+
[City Key] [int] NOT NULL,
24+
[Customer Key] [int] NOT NULL,
25+
[Stock Item Key] [int] NOT NULL,
26+
[Order Date Key] [date] NOT NULL,
27+
[Picked Date Key] [date] NULL,
28+
[Salesperson Key] [int] NOT NULL,
29+
[Picker Key] [int] NULL,
30+
[OutlierEventQuantity] [int] NOT NULL)
31+
AS
32+
BEGIN
33+
34+
-- Valid @event values
35+
-- 'Mild Recession'
36+
-- 'Hurricane - South Atlantic'
37+
-- 'Hurricane - East South Central'
38+
-- 'Hurricane - West South Central'
39+
IF @event = 'Mild Recession'
40+
INSERT @OutlierEventQuantity
41+
SELECT [o].[Order Key], [o].[City Key], [o].[Customer Key],
42+
[o].[Stock Item Key], [o].[Order Date Key], [o].[Picked Date Key],
43+
[o].[Salesperson Key], [o].[Picker Key],
44+
CASE
45+
WHEN [o].[Quantity] > 2 THEN [o].[Quantity] * .5
46+
ELSE [o].[Quantity]
47+
END
48+
FROM [Fact].[Order] AS [o]
49+
INNER JOIN [Dimension].[City] AS [c]
50+
ON [c].[City Key] = [o].[City Key]
51+
52+
IF @event = 'Hurricane - South Atlantic'
53+
INSERT @OutlierEventQuantity
54+
SELECT [o].[Order Key], [o].[City Key], [o].[Customer Key],
55+
[o].[Stock Item Key], [o].[Order Date Key], [o].[Picked Date Key],
56+
[o].[Salesperson Key], [o].[Picker Key],
57+
CASE
58+
WHEN [o].[Quantity] > 10 THEN [o].[Quantity] * .5
59+
ELSE [o].[Quantity]
60+
END
61+
FROM [Fact].[Order] AS [o]
62+
INNER JOIN [Dimension].[City] AS [c]
63+
ON [c].[City Key] = [o].[City Key]
64+
WHERE [c].[State Province] IN
65+
('Florida', 'Georgia', 'Maryland', 'North Carolina',
66+
'South Carolina', 'Virginia', 'West Virginia',
67+
'Delaware')
68+
AND [o].[Order Date Key] BETWEEN @beginOrderDateKey AND @endOrderDateKey
69+
70+
IF @event = 'Hurricane - East South Central'
71+
INSERT @OutlierEventQuantity
72+
SELECT [o].[Order Key], [o].[City Key], [o].[Customer Key],
73+
[o].[Stock Item Key], [o].[Order Date Key], [o].[Picked Date Key],
74+
[o].[Salesperson Key], [o].[Picker Key],
75+
CASE
76+
WHEN [o].[Quantity] > 50 THEN [o].[Quantity] * .5
77+
ELSE [o].[Quantity]
78+
END
79+
FROM [Fact].[Order] AS [o]
80+
INNER JOIN [Dimension].[City] AS [c]
81+
ON [c].[City Key] = [o].[City Key]
82+
INNER JOIN [Dimension].[Stock Item] AS [si]
83+
ON [si].[Stock Item Key] = [o].[Stock Item Key]
84+
WHERE [c].[State Province] IN
85+
('Alabama', 'Kentucky', 'Mississippi', 'Tennessee')
86+
AND [si].[Buying Package] = 'Carton'
87+
AND [o].[Order Date Key] BETWEEN @beginOrderDateKey AND @endOrderDateKey
88+
89+
IF @event = 'Hurricane - West South Central'
90+
INSERT @OutlierEventQuantity
91+
SELECT [o].[Order Key], [o].[City Key], [o].[Customer Key],
92+
[o].[Stock Item Key], [o].[Order Date Key], [o].[Picked Date Key],
93+
[o].[Salesperson Key], [o].[Picker Key],
94+
CASE
95+
WHEN [cu].[Customer] = 'Unknown' THEN 0
96+
WHEN [cu].[Customer] <> 'Unknown' AND
97+
[o].[Quantity] > 10 THEN [o].[Quantity] * .5
98+
ELSE [o].[Quantity]
99+
END
100+
FROM [Fact].[Order] AS [o]
101+
INNER JOIN [Dimension].[City] AS [c]
102+
ON [c].[City Key] = [o].[City Key]
103+
INNER JOIN [Dimension].[Customer] AS [cu]
104+
ON [cu].[Customer Key] = [o].[Customer Key]
105+
WHERE [c].[State Province] IN
106+
('Arkansas', 'Louisiana', 'Oklahoma', 'Texas')
107+
AND [o].[Order Date Key] BETWEEN @beginOrderDateKey AND @endOrderDateKey
108+
109+
RETURN
110+
END
111+
GO
112+
113+
USE [master];
114+
GO
115+
116+
ALTER DATABASE [WideWorldImportersDW] SET COMPATIBILITY_LEVEL = 130;
117+
GO
118+
119+
ALTER DATABASE SCOPED CONFIGURATION CLEAR PROCEDURE_CACHE;
120+
GO
121+
122+
USE [WideWorldImportersDW];
123+
GO
124+
125+
SELECT [fo].[Order Key], [fo].[Description], [fo].[Package],
126+
[fo].[Quantity], [foo].[OutlierEventQuantity]
127+
FROM [Fact].[Order] AS [fo]
128+
INNER JOIN [Fact].[WhatIfOutlierEventQuantity]('Mild Recession',
129+
'1-01-2013',
130+
'10-15-2014') AS [foo] ON [fo].[Order Key] = [foo].[Order Key]
131+
AND [fo].[City Key] = [foo].[City Key]
132+
AND [fo].[Customer Key] = [foo].[Customer Key]
133+
AND [fo].[Stock Item Key] = [foo].[Stock Item Key]
134+
AND [fo].[Order Date Key] = [foo].[Order Date Key]
135+
AND [fo].[Picked Date Key] = [foo].[Picked Date Key]
136+
AND [fo].[Salesperson Key] = [foo].[Salesperson Key]
137+
AND [fo].[Picker Key] = [foo].[Picker Key]
138+
INNER JOIN [Dimension].[Stock Item] AS [si]
139+
ON [fo].[Stock Item Key] = [si].[Stock Item Key]
140+
WHERE [si].[Lead Time Days] > 0
141+
AND [fo].[Quantity] > 50;
142+
GO
143+
144+
USE [master];
145+
GO
146+
147+
ALTER DATABASE [WideWorldImportersDW] SET COMPATIBILITY_LEVEL = 140;
148+
GO
149+
150+
ALTER DATABASE SCOPED CONFIGURATION CLEAR PROCEDURE_CACHE;
151+
GO
152+
153+
USE [WideWorldImportersDW];
154+
GO
155+
156+
SELECT [fo].[Order Key], [fo].[Description], [fo].[Package],
157+
[fo].[Quantity], [foo].[OutlierEventQuantity]
158+
FROM [Fact].[Order] AS [fo]
159+
INNER JOIN [Fact].[WhatIfOutlierEventQuantity]('Mild Recession',
160+
'1-01-2013',
161+
'10-15-2014') AS [foo] ON [fo].[Order Key] = [foo].[Order Key]
162+
AND [fo].[City Key] = [foo].[City Key]
163+
AND [fo].[Customer Key] = [foo].[Customer Key]
164+
AND [fo].[Stock Item Key] = [foo].[Stock Item Key]
165+
AND [fo].[Order Date Key] = [foo].[Order Date Key]
166+
AND [fo].[Picked Date Key] = [foo].[Picked Date Key]
167+
AND [fo].[Salesperson Key] = [foo].[Salesperson Key]
168+
AND [fo].[Picker Key] = [foo].[Picker Key]
169+
INNER JOIN [Dimension].[Stock Item] AS [si]
170+
ON [fo].[Stock Item Key] = [si].[Stock Item Key]
171+
WHERE [si].[Lead Time Days] > 0
172+
AND [fo].[Quantity] > 50;
173+
GO

samples/features/intelligent-query-processing/Intelligent QP Demos WideWorldImportersDW Public Preview - Row Mode MGF.sql

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,16 @@
1010
-- Email IntelligentQP@microsoft.com for questions\feedback
1111
-- ******************************************************** --
1212

13-
ALTER DATABASE WideWorldImportersDW SET COMPATIBILITY_LEVEL = 150;
13+
USE [master];
14+
GO
15+
16+
ALTER DATABASE [WideWorldImportersDW] SET COMPATIBILITY_LEVEL = 150;
1417
GO
1518

1619
ALTER DATABASE SCOPED CONFIGURATION CLEAR PROCEDURE_CACHE;
1720
GO
1821

19-
USE WideWorldImportersDW;
22+
USE [WideWorldImportersDW];
2023
GO
2124

2225
-- Simulate out-of-date stats
@@ -30,10 +33,10 @@ GO
3033
SELECT
3134
fo.[Order Key], fo.Description,
3235
si.[Lead Time Days]
33-
FROM Fact.OrderHistory AS fo
36+
FROM Fact.OrderHistory AS fo
3437
INNER HASH JOIN Dimension.[Stock Item] AS si
3538
ON fo.[Stock Item Key] = si.[Stock Item Key]
36-
WHERE fo.[Lineage Key] = 9
39+
WHERE fo.[Lineage Key] = 9
3740
AND si.[Lead Time Days] > 19;
3841

3942
-- Cleanup

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,21 @@
99

1010
-- Email IntelligentQP@microsoft.com for questions\feedback
1111
-- ******************************************************** --
12-
USE WideWorldImportersDW;
12+
USE [master];
1313
GO
1414

15-
ALTER DATABASE WideWorldImportersDW
16-
SET COMPATIBILITY_LEVEL = 150;
15+
ALTER DATABASE [WideWorldImportersDW] SET COMPATIBILITY_LEVEL = 150;
1716
GO
1817

19-
ALTER DATABASE SCOPED CONFIGURATION
20-
CLEAR PROCEDURE_CACHE;
18+
ALTER DATABASE SCOPED CONFIGURATION CLEAR PROCEDURE_CACHE;
2119
GO
20+
21+
USE [WideWorldImportersDW];
22+
GO
23+
2224
/*
2325
Adapted from SQL Server Books Online
24-
https://docs.microsoft.com/en-us/sql/relational-databases/user-defined-functions/scalar-udf-inlining?view=sqlallproducts-allversions
26+
https://docs.microsoft.com/sql/relational-databases/user-defined-functions/scalar-udf-inlining?view=sqlallproducts-allversions
2527
*/
2628
CREATE OR ALTER FUNCTION
2729
dbo.customer_category(@CustomerKey INT)

0 commit comments

Comments
 (0)