mirror of
https://github.com/Microsoft/sql-server-samples.git
synced 2025-12-08 14:58:54 +00:00
73 lines
1.6 KiB
Transact-SQL
73 lines
1.6 KiB
Transact-SQL
-- ******************************************************** --
|
|
-- Table variable deferred compilation
|
|
|
|
-- 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
|
|
|
|
-- Email IntelligentQP@microsoft.com for questions\feedback
|
|
-- ******************************************************** --
|
|
|
|
USE [master];
|
|
GO
|
|
|
|
ALTER DATABASE [WideWorldImportersDW] SET COMPATIBILITY_LEVEL = 140;
|
|
GO
|
|
|
|
ALTER DATABASE SCOPED CONFIGURATION CLEAR PROCEDURE_CACHE;
|
|
GO
|
|
|
|
USE [WideWorldImportersDW];
|
|
GO
|
|
|
|
DECLARE @Order TABLE
|
|
([Order Key] BIGINT NOT NULL,
|
|
[Quantity] INT NOT NULL
|
|
);
|
|
|
|
INSERT @Order
|
|
SELECT [Order Key], [Quantity]
|
|
FROM [Fact].[OrderHistory]
|
|
WHERE [Quantity] > 99;
|
|
|
|
-- Look at estimated rows, speed, join algorithm
|
|
SELECT oh.[Order Key], oh.[Order Date Key],
|
|
oh.[Unit Price], o.Quantity
|
|
FROM Fact.OrderHistoryExtended AS oh
|
|
INNER JOIN @Order AS o
|
|
ON o.[Order Key] = oh.[Order Key]
|
|
WHERE oh.[Unit Price] > 0.10
|
|
ORDER BY oh.[Unit Price] DESC;
|
|
GO
|
|
|
|
USE [master]
|
|
GO
|
|
|
|
ALTER DATABASE [WideWorldImportersDW] SET COMPATIBILITY_LEVEL = 150
|
|
GO
|
|
|
|
USE [WideWorldImportersDW]
|
|
GO
|
|
|
|
DECLARE @Order TABLE
|
|
([Order Key] BIGINT NOT NULL,
|
|
[Quantity] INT NOT NULL
|
|
);
|
|
|
|
INSERT @Order
|
|
SELECT [Order Key], [Quantity]
|
|
FROM [Fact].[OrderHistory]
|
|
WHERE [Quantity] > 99;
|
|
|
|
-- Look at estimated rows, speed, join algorithm
|
|
SELECT oh.[Order Key], oh.[Order Date Key],
|
|
oh.[Unit Price], o.Quantity
|
|
FROM Fact.OrderHistoryExtended AS oh
|
|
INNER JOIN @Order AS o
|
|
ON o.[Order Key] = oh.[Order Key]
|
|
WHERE oh.[Unit Price] > 0.10
|
|
ORDER BY oh.[Unit Price] DESC;
|
|
GO
|