mirror of
https://github.com/Microsoft/sql-server-samples.git
synced 2025-12-08 14:58:54 +00:00
31 lines
828 B
Transact-SQL
31 lines
828 B
Transact-SQL
-- ******************************************************** --
|
|
-- Approximate count distinct
|
|
|
|
-- See https://aka.ms/IQP for more background
|
|
|
|
-- Demo scripts: https://aka.ms/IQPDemos
|
|
|
|
-- Demo uses SQL Server 2019 and Azure SQL DB
|
|
|
|
-- Email IntelligentQP@microsoft.com for questions\feedback
|
|
-- ******************************************************** --
|
|
|
|
USE [master];
|
|
GO
|
|
|
|
ALTER DATABASE [WideWorldImportersDW] SET COMPATIBILITY_LEVEL = 150;
|
|
GO
|
|
|
|
USE [WideWorldImportersDW];
|
|
GO
|
|
|
|
-- Compare execution time and distinct counts
|
|
SELECT COUNT(DISTINCT [WWI Order ID])
|
|
FROM [Fact].[OrderHistoryExtended]
|
|
OPTION (USE HINT('DISALLOW_BATCH_MODE'), RECOMPILE); -- Isolating out BMOR
|
|
|
|
SELECT APPROX_COUNT_DISTINCT([WWI Order ID])
|
|
FROM [Fact].[OrderHistoryExtended]
|
|
OPTION (USE HINT('DISALLOW_BATCH_MODE'), RECOMPILE); -- Isolating out BMOR
|
|
|