{ "metadata": { "kernelspec": { "name": "SQL", "display_name": "SQL", "language": "sql" }, "language_info": { "name": "sql", "version": "" } }, "nbformat_minor": 2, "nbformat": 4, "cells": [ { "cell_type": "markdown", "source": [ "# Batch Mode on rowstore\r\n", "Batch mode on rowstore enables batch mode execution for analytic workloads without requiring columnstore indexes. This feature supports batch mode execution and bitmap filters for on-disk heaps and B-tree indexes. Batch mode on rowstore enables support for all existing batch mode-enabled operators. Batch mode on Rowstore is a feature under the [**Intelligent Query Processing**](https://aka.ms/iqp) suite of features. \r\n", "\r\n", "This example will show you how upgrading to **Database Compatibility Level = 150** could improve performance of the following workloads due to batch mode on rowstore:\r\n", "* A significant part of the workload consists of analytical queries. Usually, these queries have operators like joins or aggregates that process hundreds of thousands of rows or more.\r\n", "* The workload is CPU bound. If the bottleneck is I/O, we still recommend that you consider a columnstore index, if possible.\r\n", "* Creating a columnstore index adds too much overhead to the transactional part of your workload. Or, creating a columnstore index isn't feasible because your application depends on a feature that's not yet supported with columnstore indexes.\r\n", "\r\n", "More information about this feature is available [here](https://docs.microsoft.com/en-us/sql/relational-databases/performance/intelligent-query-processing?view=sql-server-ver15#batch-mode-on-rowstore)." ], "metadata": { "azdata_cell_guid": "7870ea3f-b017-46d9-bec6-15369f4ade69" } }, { "cell_type": "markdown", "source": [ "**Step 1**: You could choose to use a container to evaluate this feature. Create an instance of SQL Server 2019 using a Docker image and restore the AdventureWorks database backup\r\n", "\r\n", "You will need the **WideWorldImportersDW** database for this exercise. If you don't have this sample database, then you download the sample database [here](https://github.com/Microsoft/sql-server-samples/releases/download/wide-world-importers-v1.0/WideWorldImportersDW-Full.bak \"WideWorldImportersDW-Full download\")\r\n", "\r\n", "Restore the copied WideWorldImportersDW database backup into the container and restore the backup.\r\n", "\r\n", "##### Docker Commands\r\n", ">docker pull mcr.microsoft.com/mssql/server:2019-latest\r\n", "\r\n", ">docker run -e \"ACCEPT_EULA=Y\" -e \"SA_PASSWORD=`\" -p 1445:1433 --name sql2019demo -d mcr.microsoft.com/mssql/server:2019-latest\r\n", "\r\n", ">docker cp \".\\Downloads\\WideWorldImportersDW-Full.bak\" sql2019demo:/var/opt/mssql/data\r\n", "" ], "metadata": { "azdata_cell_guid": "975f5a9f-300f-450b-8981-cebb9ed6c719" } }, { "cell_type": "code", "source": [ "-- Restore the AdventureWorks2017.bak file \r\n", "declare @datafilepath varchar(8000) = CAST(SERVERPROPERTY('InstanceDefaultDataPath') as varchar(4000)) + 'WideWorldImportersDW.mdf'\r\n", "declare @logfilepath varchar(8000) = CAST(SERVERPROPERTY('InstanceDefaultLogPath') as varchar(4000)) + 'WideWorldImportersDW.ldf'\r\n", "declare @inmemfilepath varchar(8000) = CAST(SERVERPROPERTY('InstanceDefaultLogPath') as varchar(4000)) + 'WideWorldImportersDW_InMemory_Data_1'\r\n", "declare @secondaryfilepath varchar(8000) = CAST(SERVERPROPERTY('InstanceDefaultLogPath') as varchar(4000))+ 'WideWorldImportersDW_2.ndf'\r\n", "-- Replace the path with the appropriate file\r\n", "declare @backupfile varchar(8000) = 'WideWorldImportersDW-Full.bak'\r\n", "restore database WideWorldImportersDW\r\n", "from disk = @backupfile\r\n", "with move 'WWI_Primary' to @datafilepath,\r\n", "move 'WWI_UserData' to @secondaryfilepath,\r\n", "move 'WWIDW_InMemory_Data_1' to @inmemfilepath,\r\n", "move 'WWI_Log' to @logfilepath,\r\n", "stats = 10, REPLACE" ], "metadata": { "azdata_cell_guid": "b48b5a47-55d7-4c3c-ba51-2efa8d801029" }, "outputs": [], "execution_count": 7 }, { "cell_type": "markdown", "source": [ "**Step 2:** See scalar UDF performance issues using an example\r\n", "The below query calls scalar UDFs to get the the list price and remaining stock of the products in the invetory. You will notice that it returns over 121,000 rows.\r\n", "" ], "metadata": { "azdata_cell_guid": "4e07d47f-3833-40dd-8203-1d43af8bacd8" } }, { "cell_type": "code", "source": [ "USE WideWorldImportersDW;\r\n", "GO\r\n", "\r\n", "/*\r\n", "Assumes a fresh restore of WideWorldImportersDW\r\n", "*/\r\n", "\r\n", "IF OBJECT_ID('Fact.OrderHistory') IS NULL BEGIN\r\n", " SELECT [Order Key], [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]\r\n", " INTO Fact.OrderHistory\r\n", " FROM Fact.[Order];\r\n", "END;\r\n", "\r\n", "ALTER TABLE Fact.OrderHistory\r\n", "ADD CONSTRAINT PK_Fact_OrderHistory PRIMARY KEY NONCLUSTERED([Order Key] ASC, [Order Date Key] ASC)WITH(DATA_COMPRESSION=PAGE);\r\n", "GO\r\n", "\r\n", "CREATE INDEX IX_Stock_Item_Key\r\n", "ON Fact.OrderHistory([Stock Item Key])\r\n", "INCLUDE(Quantity)\r\n", "WITH(DATA_COMPRESSION=PAGE);\r\n", "GO\r\n", "\r\n", "CREATE INDEX IX_OrderHistory_Quantity\r\n", "ON Fact.OrderHistory([Quantity])\r\n", "INCLUDE([Order Key])\r\n", "WITH(DATA_COMPRESSION=PAGE);\r\n", "GO\r\n", "\r\n", "\r\n", "/*\r\n", "\tReality check... Starting count should be 231,412\r\n", "*/\r\n", "\r\n", "SELECT COUNT(*) FROM Fact.OrderHistory;\r\n", "GO\r\n", "/*\r\n", "\tMake this table bigger (exec as desired)\r\n", "\tNotice the \"GO 4\"\r\n", "*/\r\n", "\r\n", "INSERT Fact.OrderHistory([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])\r\n", "SELECT [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]\r\n", "FROM Fact.OrderHistory;\r\n", "GO 4\r\n", "\r\n", "/*\r\n", "\tShould be 3,702,592\r\n", "*/\r\n", "SELECT COUNT(*) FROM Fact.OrderHistory;\r\n", "GO\r\n", "\r\n", "IF OBJECT_ID('Fact.OrderHistoryExtended') IS NULL BEGIN\r\n", " SELECT [Order Key], [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]\r\n", " INTO Fact.OrderHistoryExtended\r\n", " FROM Fact.[OrderHistory];\r\n", "END;\r\n", "\r\n", "ALTER TABLE Fact.OrderHistoryExtended\r\n", "ADD CONSTRAINT PK_Fact_OrderHistoryExtended PRIMARY KEY NONCLUSTERED([Order Key] ASC, [Order Date Key] ASC)\r\n", "WITH(DATA_COMPRESSION=PAGE);\r\n", "GO\r\n", "\r\n", "CREATE INDEX IX_Stock_Item_Key\r\n", "ON Fact.OrderHistoryExtended([Stock Item Key])\r\n", "INCLUDE(Quantity);\r\n", "GO\r\n", "\r\n", "/*\r\n", "\tShould be 3,702,592\r\n", "*/\r\n", "SELECT COUNT(*) FROM Fact.OrderHistoryExtended;\r\n", "GO\r\n", "\r\n", "/*\r\n", "\tMake this table bigger (exec as desired)\r\n", "\tNotice the \"GO 3\"\r\n", "*/\r\n", "\r\n", "INSERT Fact.OrderHistoryExtended([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])\r\n", "SELECT [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]\r\n", "FROM Fact.OrderHistoryExtended;\r\n", "GO 3\r\n", "\r\n", "\r\n", "/*\r\n", "\tShould be 29,620,736\r\n", "*/\r\n", "\r\n", "SELECT COUNT(*) FROM Fact.OrderHistoryExtended;\r\n", "GO\r\n", "\r\n", "UPDATE Fact.OrderHistoryExtended\r\n", "SET [WWI Order ID] = [Order Key];\r\n", "GO\r\n", "\r\n", "-- Repeat until log shrinks\r\n", "\r\n", "CHECKPOINT\r\n", "GO\r\n", "\r\n", "" ], "metadata": { "azdata_cell_guid": "a7421321-3652-49c5-b83a-e25e69c48aed" }, "outputs": [], "execution_count": 3 }, { "cell_type": "markdown", "source": [ "**Step 3**: Execute the query without Batch Mode for Rowstore. This is done by using a query hint \"**DISALLOW_BATCH_MODE**\" to disable the feature." ], "metadata": { "azdata_cell_guid": "cc613f99-f3c2-462f-93df-bd197de31bbc" } }, { "cell_type": "code", "source": [ "USE [WideWorldImportersDW];\r\n", "GO\r\n", "ALTER DATABASE [WideWorldImportersDW] SET COMPATIBILITY_LEVEL = 150;\r\n", "GO\r\n", "\r\n", "ALTER DATABASE SCOPED CONFIGURATION CLEAR PROCEDURE_CACHE;\r\n", "GO\r\n", "-- Row mode due to hint\r\n", "SELECT\t[Tax Rate],\r\n", "\t\t[Lineage Key],\r\n", "\t\t[Salesperson Key],\r\n", "\tSUM([Quantity])\t\t\t\t\tAS SUM_QTY,\r\n", "\tSUM([Unit Price])\t\t\t\tAS SUM_BASE_PRICE,\r\n", "\tCOUNT(*)\t\t\t\t\tAS COUNT_ORDER\r\n", "FROM\t[Fact].[OrderHistoryExtended]\r\n", "WHERE\t[Order Date Key]\t<= dateadd(dd, -73, '2015-11-13')\r\n", "GROUP\tBY\t[Tax Rate],\r\n", "\t\t[Lineage Key],\r\n", "\t\t[Salesperson Key]\r\n", "ORDER\tBY\t[Tax Rate],\r\n", "\t\t[Lineage Key],\r\n", "\t\t[Salesperson Key]\r\n", "OPTION (RECOMPILE, USE HINT('DISALLOW_BATCH_MODE'));\r\n", "" ], "metadata": { "azdata_cell_guid": "71483984-6bdd-4866-8ddc-e40fe692c0db" }, "outputs": [ { "output_type": "display_data", "data": { "text/html": "Commands completed successfully." }, "metadata": {} }, { "output_type": "display_data", "data": { "text/html": "Commands completed successfully." }, "metadata": {} }, { "output_type": "display_data", "data": { "text/html": "Commands completed successfully." }, "metadata": {} }, { "output_type": "display_data", "data": { "text/html": "(100 rows affected)" }, "metadata": {} }, { "output_type": "display_data", "data": { "text/html": "Total execution time: 00:00:19.584" }, "metadata": {} }, { "output_type": "execute_result", "metadata": {}, "execution_count": 8, "data": { "application/vnd.dataresource+json": { "schema": { "fields": [ { "name": "Tax Rate" }, { "name": "Lineage Key" }, { "name": "Salesperson Key" }, { "name": "SUM_QTY" }, { "name": "SUM_BASE_PRICE" }, { "name": "COUNT_ORDER" } ] }, "data": [ { "0": "15.000", "1": "9", "2": "4", "3": "433280", "4": "243367.68", "5": "9216" }, { "0": "15.000", "1": "9", "2": "6", "3": "836480", "4": "543988.48", "5": "18432" }, { "0": "15.000", "1": "9", "2": "7", "3": "724480", "4": "846118.40", "5": "24576" }, { "0": "15.000", "1": "9", "2": "8", "3": "862080", "4": "1028780.80", "5": "22144" }, { "0": "15.000", "1": "9", "2": "9", "3": "1101056", "4": "924917.76", "5": "28928" }, { "0": "15.000", "1": "9", "2": "11", "3": "2279296", "4": "3886913.28", "5": "62848" }, { "0": "15.000", "1": "9", "2": "12", "3": "3262592", "4": "3852878.08", "5": "85888" }, { "0": "15.000", "1": "9", "2": "15", "3": "5484800", "4": "6343098.88", "5": "144256" }, { "0": "15.000", "1": "9", "2": "19", "3": "91831040", "4": "107590420.48", "5": "2310528" }, { "0": "15.000", "1": "9", "2": "21", "3": "1240960", "4": "2060285.44", "5": "37632" }, { "0": "15.000", "1": "9", "2": "23", "3": "1003520", "4": "1541052.16", "5": "29696" }, { "0": "15.000", "1": "9", "2": "25", "3": "2986624", "4": "2914885.12", "5": "73344" }, { "0": "15.000", "1": "9", "2": "26", "3": "497536", "4": "725172.48", "5": "12416" }, { "0": "15.000", "1": "9", "2": "27", "3": "598016", "4": "798522.88", "5": "14592" }, { "0": "15.000", "1": "9", "2": "28", "3": "1233152", "4": "1474490.88", "5": "31488" }, { "0": "15.000", "1": "9", "2": "29", "3": "387968", "4": "304568.32", "5": "10880" }, { "0": "15.000", "1": "9", "2": "30", "3": "1549312", "4": "2156144.64", "5": "47232" }, { "0": "15.000", "1": "9", "2": "31", "3": "2215296", "4": "2227068.16", "5": "50560" }, { "0": "15.000", "1": "9", "2": "35", "3": "2724736", "4": "3383616.00", "5": "72960" }, { "0": "15.000", "1": "9", "2": "36", "3": "11016320", "4": "12551537.92", "5": "276992" }, { "0": "15.000", "1": "9", "2": "38", "3": "1519744", "4": "1955315.20", "5": "39552" }, { "0": "15.000", "1": "9", "2": "39", "3": "31888384", "4": "34617245.44", "5": "785664" }, { "0": "15.000", "1": "9", "2": "40", "3": "6807424", "4": "7944593.92", "5": "176896" }, { "0": "15.000", "1": "9", "2": "41", "3": "2219136", "4": "3174849.28", "5": "63232" }, { "0": "15.000", "1": "9", "2": "45", "3": "338176", "4": "382839.04", "5": "7808" }, { "0": "15.000", "1": "9", "2": "46", "3": "112128", "4": "111915.52", "5": "2176" }, { "0": "15.000", "1": "9", "2": "47", "3": "3255680", "4": "2629954.56", "5": "75776" }, { "0": "15.000", "1": "9", "2": "48", "3": "2595968", "4": "2310150.40", "5": "60928" }, { "0": "15.000", "1": "9", "2": "49", "3": "14758528", "4": "17928881.92", "5": "368768" }, { "0": "15.000", "1": "9", "2": "50", "3": "804352", "4": "926225.92", "5": "19968" }, { "0": "15.000", "1": "9", "2": "51", "3": "4007808", "4": "4360591.36", "5": "97408" }, { "0": "15.000", "1": "9", "2": "52", "3": "5863424", "4": "7464648.96", "5": "156160" }, { "0": "15.000", "1": "9", "2": "54", "3": "2736768", "4": "3351491.84", "5": "72320" }, { "0": "15.000", "1": "9", "2": "56", "3": "285824", "4": "253144.32", "5": "7552" }, { "0": "15.000", "1": "9", "2": "57", "3": "2298240", "4": "2447610.88", "5": "58240" }, { "0": "15.000", "1": "9", "2": "58", "3": "2144768", "4": "1723477.76", "5": "50048" }, { "0": "15.000", "1": "9", "2": "61", "3": "3732224", "4": "4086886.40", "5": "86016" }, { "0": "15.000", "1": "9", "2": "62", "3": "12672128", "4": "13904339.20", "5": "304000" }, { "0": "15.000", "1": "9", "2": "63", "3": "10126208", "4": "10138237.44", "5": "243200" }, { "0": "15.000", "1": "9", "2": "65", "3": "6787456", "4": "7473853.44", "5": "171136" }, { "0": "15.000", "1": "9", "2": "68", "3": "4638720", "4": "4848647.68", "5": "107008" }, { "0": "15.000", "1": "9", "2": "70", "3": "14884864", "4": "16764665.60", "5": "379776" }, { "0": "15.000", "1": "9", "2": "72", "3": "2565888", "4": "2336160.00", "5": "55936" }, { "0": "15.000", "1": "9", "2": "74", "3": "15317888", "4": "19187417.60", "5": "384768" }, { "0": "15.000", "1": "9", "2": "76", "3": "6481280", "4": "8637446.40", "5": "169088" }, { "0": "15.000", "1": "9", "2": "77", "3": "7128320", "4": "7693249.28", "5": "169984" }, { "0": "15.000", "1": "9", "2": "78", "3": "5061376", "4": "5629213.44", "5": "121856" }, { "0": "15.000", "1": "9", "2": "80", "3": "7743104", "4": "8722903.04", "5": "203264" }, { "0": "15.000", "1": "9", "2": "81", "3": "28808064", "4": "32882525.44", "5": "706048" }, { "0": "15.000", "1": "9", "2": "83", "3": "12662272", "4": "14586407.68", "5": "330880" }, { "0": "15.000", "1": "9", "2": "84", "3": "6509184", "4": "8482062.08", "5": "169856" }, { "0": "15.000", "1": "9", "2": "85", "3": "4782592", "4": "4991431.68", "5": "116864" }, { "0": "15.000", "1": "9", "2": "86", "3": "27021696", "4": "30225996.80", "5": "682624" }, { "0": "15.000", "1": "9", "2": "89", "3": "1578752", "4": "2027873.28", "5": "36096" }, { "0": "15.000", "1": "9", "2": "90", "3": "33806464", "4": "39663014.40", "5": "856704" }, { "0": "15.000", "1": "9", "2": "91", "3": "4442752", "4": "5842634.24", "5": "112768" }, { "0": "15.000", "1": "9", "2": "93", "3": "28200192", "4": "33006179.84", "5": "713984" }, { "0": "15.000", "1": "9", "2": "94", "3": "12681600", "4": "13601986.56", "5": "303232" }, { "0": "15.000", "1": "9", "2": "96", "3": "666624", "4": "473141.76", "5": "14464" }, { "0": "15.000", "1": "9", "2": "97", "3": "11993088", "4": "13300569.60", "5": "303104" }, { "0": "15.000", "1": "9", "2": "101", "3": "7575168", "4": "7600646.40", "5": "196992" }, { "0": "15.000", "1": "9", "2": "102", "3": "27441920", "4": "33995997.44", "5": "703872" }, { "0": "15.000", "1": "9", "2": "103", "3": "7057280", "4": "8503637.76", "5": "185088" }, { "0": "15.000", "1": "9", "2": "105", "3": "29710848", "4": "34073157.12", "5": "735872" }, { "0": "15.000", "1": "9", "2": "106", "3": "8104704", "4": "9812775.68", "5": "220416" }, { "0": "15.000", "1": "9", "2": "107", "3": "2590464", "4": "3028149.76", "5": "61952" }, { "0": "15.000", "1": "9", "2": "108", "3": "40156160", "4": "45593496.32", "5": "1001600" }, { "0": "15.000", "1": "9", "2": "115", "3": "2452096", "4": "2226137.60", "5": "60800" }, { "0": "15.000", "1": "9", "2": "116", "3": "23243392", "4": "24868823.04", "5": "564736" }, { "0": "15.000", "1": "9", "2": "118", "3": "14240128", "4": "15111184.64", "5": "353408" }, { "0": "15.000", "1": "9", "2": "119", "3": "40846720", "4": "45264224.00", "5": "1027456" }, { "0": "15.000", "1": "9", "2": "122", "3": "6732544", "4": "7716145.92", "5": "164992" }, { "0": "15.000", "1": "9", "2": "126", "3": "7082880", "4": "8110862.08", "5": "171008" }, { "0": "15.000", "1": "9", "2": "127", "3": "24211712", "4": "28525308.16", "5": "616576" }, { "0": "15.000", "1": "9", "2": "129", "3": "31437312", "4": "34298964.48", "5": "767488" }, { "0": "15.000", "1": "9", "2": "130", "3": "390272", "4": "315754.24", "5": "10880" }, { "0": "15.000", "1": "9", "2": "134", "3": "19598208", "4": "22598796.80", "5": "491520" }, { "0": "15.000", "1": "9", "2": "136", "3": "357248", "4": "296313.60", "5": "9856" }, { "0": "15.000", "1": "9", "2": "138", "3": "4697088", "4": "5400261.12", "5": "118144" }, { "0": "15.000", "1": "9", "2": "140", "3": "17321984", "4": "19747557.12", "5": "433280" }, { "0": "15.000", "1": "9", "2": "143", "3": "22007296", "4": "26812788.48", "5": "567040" }, { "0": "15.000", "1": "9", "2": "144", "3": "7777664", "4": "9402172.16", "5": "193152" }, { "0": "15.000", "1": "9", "2": "145", "3": "15399680", "4": "17946855.68", "5": "388096" }, { "0": "15.000", "1": "9", "2": "149", "3": "2256896", "4": "2663919.36", "5": "60416" }, { "0": "15.000", "1": "9", "2": "150", "3": "10869632", "4": "12971114.24", "5": "281344" }, { "0": "15.000", "1": "9", "2": "151", "3": "11137920", "4": "11154696.96", "5": "269568" }, { "0": "15.000", "1": "9", "2": "152", "3": "11700480", "4": "13719448.32", "5": "285056" }, { "0": "15.000", "1": "9", "2": "154", "3": "8281344", "4": "8556992.00", "5": "212864" }, { "0": "15.000", "1": "9", "2": "155", "3": "8951424", "4": "9563397.12", "5": "219264" }, { "0": "15.000", "1": "9", "2": "156", "3": "6004608", "4": "5900654.08", "5": "152192" }, { "0": "15.000", "1": "9", "2": "158", "3": "500480", "4": "65113.60", "5": "4352" }, { "0": "15.000", "1": "9", "2": "161", "3": "253952", "4": "56025.60", "5": "2816" }, { "0": "15.000", "1": "9", "2": "163", "3": "248320", "4": "48179.20", "5": "2688" }, { "0": "15.000", "1": "9", "2": "165", "3": "102016", "4": "12416.00", "5": "896" }, { "0": "15.000", "1": "9", "2": "167", "3": "16896", "4": "4608.00", "5": "256" }, { "0": "15.000", "1": "9", "2": "168", "3": "141184", "4": "21619.20", "5": "1408" }, { "0": "15.000", "1": "9", "2": "170", "3": "75776", "4": "13760.00", "5": "768" }, { "0": "15.000", "1": "9", "2": "171", "3": "112512", "4": "14681.60", "5": "1024" }, { "0": "15.000", "1": "9", "2": "172", "3": "77824", "4": "10137.60", "5": "768" }, { "0": "15.000", "1": "9", "2": "174", "3": "7680", "4": "2304.00", "5": "128" } ] }, "text/html": "
Tax RateLineage KeySalesperson KeySUM_QTYSUM_BASE_PRICECOUNT_ORDER
15.00094433280243367.689216
15.00096836480543988.4818432
15.00097724480846118.4024576
15.000988620801028780.8022144
15.000991101056924917.7628928
15.00091122792963886913.2862848
15.00091232625923852878.0885888
15.00091554848006343098.88144256
15.00091991831040107590420.482310528
15.00092112409602060285.4437632
15.00092310035201541052.1629696
15.00092529866242914885.1273344
15.000926497536725172.4812416
15.000927598016798522.8814592
15.00092812331521474490.8831488
15.000929387968304568.3210880
15.00093015493122156144.6447232
15.00093122152962227068.1650560
15.00093527247363383616.0072960
15.0009361101632012551537.92276992
15.00093815197441955315.2039552
15.0009393188838434617245.44785664
15.00094068074247944593.92176896
15.00094122191363174849.2863232
15.000945338176382839.047808
15.000946112128111915.522176
15.00094732556802629954.5675776
15.00094825959682310150.4060928
15.0009491475852817928881.92368768
15.000950804352926225.9219968
15.00095140078084360591.3697408
15.00095258634247464648.96156160
15.00095427367683351491.8472320
15.000956285824253144.327552
15.00095722982402447610.8858240
15.00095821447681723477.7650048
15.00096137322244086886.4086016
15.0009621267212813904339.20304000
15.0009631012620810138237.44243200
15.00096567874567473853.44171136
15.00096846387204848647.68107008
15.0009701488486416764665.60379776
15.00097225658882336160.0055936
15.0009741531788819187417.60384768
15.00097664812808637446.40169088
15.00097771283207693249.28169984
15.00097850613765629213.44121856
15.00098077431048722903.04203264
15.0009812880806432882525.44706048
15.0009831266227214586407.68330880
15.00098465091848482062.08169856
15.00098547825924991431.68116864
15.0009862702169630225996.80682624
15.00098915787522027873.2836096
15.0009903380646439663014.40856704
15.00099144427525842634.24112768
15.0009932820019233006179.84713984
15.0009941268160013601986.56303232
15.000996666624473141.7614464
15.0009971199308813300569.60303104
15.000910175751687600646.40196992
15.00091022744192033995997.44703872
15.000910370572808503637.76185088
15.00091052971084834073157.12735872
15.000910681047049812775.68220416
15.000910725904643028149.7661952
15.00091084015616045593496.321001600
15.000911524520962226137.6060800
15.00091162324339224868823.04564736
15.00091181424012815111184.64353408
15.00091194084672045264224.001027456
15.000912267325447716145.92164992
15.000912670828808110862.08171008
15.00091272421171228525308.16616576
15.00091293143731234298964.48767488
15.0009130390272315754.2410880
15.00091341959820822598796.80491520
15.0009136357248296313.609856
15.000913846970885400261.12118144
15.00091401732198419747557.12433280
15.00091432200729626812788.48567040
15.000914477776649402172.16193152
15.00091451539968017946855.68388096
15.000914922568962663919.3660416
15.00091501086963212971114.24281344
15.00091511113792011154696.96269568
15.00091521170048013719448.32285056
15.000915482813448556992.00212864
15.000915589514249563397.12219264
15.000915660046085900654.08152192
15.000915850048065113.604352
15.000916125395256025.602816
15.000916324832048179.202688
15.000916510201612416.00896
15.0009167168964608.00256
15.000916814118421619.201408
15.00091707577613760.00768
15.000917111251214681.601024
15.00091727782410137.60768
15.000917476802304.00128
" } } ], "execution_count": 8 }, { "cell_type": "markdown", "source": [ "**Step 4**: Let us run the same query from Step 3 but now with Batchmode for Rowstore. " ], "metadata": { "azdata_cell_guid": "6140b74a-e79d-4108-9cba-415f66ed85a3" } }, { "cell_type": "code", "source": [ "ALTER DATABASE [WideWorldImportersDW] SET COMPATIBILITY_LEVEL = 150;\r\n", "GO\r\n", "\r\n", "ALTER DATABASE SCOPED CONFIGURATION CLEAR PROCEDURE_CACHE;\r\n", "GO\r\n", "\r\n", "USE [WideWorldImportersDW]\r\n", "GO\r\n", "-- Batch mode on rowstore eligible\r\n", "SELECT\t[Tax Rate],\r\n", "\t\t[Lineage Key],\r\n", "\t\t[Salesperson Key],\r\n", "\tSUM([Quantity])\t\t\t\t\tAS SUM_QTY,\r\n", "\tSUM([Unit Price])\t\t\t\tAS SUM_BASE_PRICE,\r\n", "\tCOUNT(*)\t\t\t\t\tAS COUNT_ORDER\r\n", "FROM\t[Fact].[OrderHistoryExtended]\r\n", "WHERE\t[Order Date Key]\t<= dateadd(dd, -73, '2015-11-13')\r\n", "GROUP\tBY\t[Tax Rate],\r\n", "\t\t[Lineage Key],\r\n", "\t\t[Salesperson Key]\r\n", "ORDER\tBY\t[Tax Rate],\r\n", "\t\t[Lineage Key],\r\n", "\t\t[Salesperson Key]\r\n", "OPTION (RECOMPILE);" ], "metadata": { "azdata_cell_guid": "d37ad2f6-5a09-4418-8ba2-47f954af18e8" }, "outputs": [ { "output_type": "display_data", "data": { "text/html": "Commands completed successfully." }, "metadata": {} }, { "output_type": "display_data", "data": { "text/html": "Commands completed successfully." }, "metadata": {} }, { "output_type": "display_data", "data": { "text/html": "Commands completed successfully." }, "metadata": {} }, { "output_type": "display_data", "data": { "text/html": "(100 rows affected)" }, "metadata": {} }, { "output_type": "display_data", "data": { "text/html": "Total execution time: 00:00:05.395" }, "metadata": {} }, { "output_type": "execute_result", "metadata": {}, "execution_count": 9, "data": { "application/vnd.dataresource+json": { "schema": { "fields": [ { "name": "Tax Rate" }, { "name": "Lineage Key" }, { "name": "Salesperson Key" }, { "name": "SUM_QTY" }, { "name": "SUM_BASE_PRICE" }, { "name": "COUNT_ORDER" } ] }, "data": [ { "0": "15.000", "1": "9", "2": "4", "3": "433280", "4": "243367.68", "5": "9216" }, { "0": "15.000", "1": "9", "2": "6", "3": "836480", "4": "543988.48", "5": "18432" }, { "0": "15.000", "1": "9", "2": "7", "3": "724480", "4": "846118.40", "5": "24576" }, { "0": "15.000", "1": "9", "2": "8", "3": "862080", "4": "1028780.80", "5": "22144" }, { "0": "15.000", "1": "9", "2": "9", "3": "1101056", "4": "924917.76", "5": "28928" }, { "0": "15.000", "1": "9", "2": "11", "3": "2279296", "4": "3886913.28", "5": "62848" }, { "0": "15.000", "1": "9", "2": "12", "3": "3262592", "4": "3852878.08", "5": "85888" }, { "0": "15.000", "1": "9", "2": "15", "3": "5484800", "4": "6343098.88", "5": "144256" }, { "0": "15.000", "1": "9", "2": "19", "3": "91831040", "4": "107590420.48", "5": "2310528" }, { "0": "15.000", "1": "9", "2": "21", "3": "1240960", "4": "2060285.44", "5": "37632" }, { "0": "15.000", "1": "9", "2": "23", "3": "1003520", "4": "1541052.16", "5": "29696" }, { "0": "15.000", "1": "9", "2": "25", "3": "2986624", "4": "2914885.12", "5": "73344" }, { "0": "15.000", "1": "9", "2": "26", "3": "497536", "4": "725172.48", "5": "12416" }, { "0": "15.000", "1": "9", "2": "27", "3": "598016", "4": "798522.88", "5": "14592" }, { "0": "15.000", "1": "9", "2": "28", "3": "1233152", "4": "1474490.88", "5": "31488" }, { "0": "15.000", "1": "9", "2": "29", "3": "387968", "4": "304568.32", "5": "10880" }, { "0": "15.000", "1": "9", "2": "30", "3": "1549312", "4": "2156144.64", "5": "47232" }, { "0": "15.000", "1": "9", "2": "31", "3": "2215296", "4": "2227068.16", "5": "50560" }, { "0": "15.000", "1": "9", "2": "35", "3": "2724736", "4": "3383616.00", "5": "72960" }, { "0": "15.000", "1": "9", "2": "36", "3": "11016320", "4": "12551537.92", "5": "276992" }, { "0": "15.000", "1": "9", "2": "38", "3": "1519744", "4": "1955315.20", "5": "39552" }, { "0": "15.000", "1": "9", "2": "39", "3": "31888384", "4": "34617245.44", "5": "785664" }, { "0": "15.000", "1": "9", "2": "40", "3": "6807424", "4": "7944593.92", "5": "176896" }, { "0": "15.000", "1": "9", "2": "41", "3": "2219136", "4": "3174849.28", "5": "63232" }, { "0": "15.000", "1": "9", "2": "45", "3": "338176", "4": "382839.04", "5": "7808" }, { "0": "15.000", "1": "9", "2": "46", "3": "112128", "4": "111915.52", "5": "2176" }, { "0": "15.000", "1": "9", "2": "47", "3": "3255680", "4": "2629954.56", "5": "75776" }, { "0": "15.000", "1": "9", "2": "48", "3": "2595968", "4": "2310150.40", "5": "60928" }, { "0": "15.000", "1": "9", "2": "49", "3": "14758528", "4": "17928881.92", "5": "368768" }, { "0": "15.000", "1": "9", "2": "50", "3": "804352", "4": "926225.92", "5": "19968" }, { "0": "15.000", "1": "9", "2": "51", "3": "4007808", "4": "4360591.36", "5": "97408" }, { "0": "15.000", "1": "9", "2": "52", "3": "5863424", "4": "7464648.96", "5": "156160" }, { "0": "15.000", "1": "9", "2": "54", "3": "2736768", "4": "3351491.84", "5": "72320" }, { "0": "15.000", "1": "9", "2": "56", "3": "285824", "4": "253144.32", "5": "7552" }, { "0": "15.000", "1": "9", "2": "57", "3": "2298240", "4": "2447610.88", "5": "58240" }, { "0": "15.000", "1": "9", "2": "58", "3": "2144768", "4": "1723477.76", "5": "50048" }, { "0": "15.000", "1": "9", "2": "61", "3": "3732224", "4": "4086886.40", "5": "86016" }, { "0": "15.000", "1": "9", "2": "62", "3": "12672128", "4": "13904339.20", "5": "304000" }, { "0": "15.000", "1": "9", "2": "63", "3": "10126208", "4": "10138237.44", "5": "243200" }, { "0": "15.000", "1": "9", "2": "65", "3": "6787456", "4": "7473853.44", "5": "171136" }, { "0": "15.000", "1": "9", "2": "68", "3": "4638720", "4": "4848647.68", "5": "107008" }, { "0": "15.000", "1": "9", "2": "70", "3": "14884864", "4": "16764665.60", "5": "379776" }, { "0": "15.000", "1": "9", "2": "72", "3": "2565888", "4": "2336160.00", "5": "55936" }, { "0": "15.000", "1": "9", "2": "74", "3": "15317888", "4": "19187417.60", "5": "384768" }, { "0": "15.000", "1": "9", "2": "76", "3": "6481280", "4": "8637446.40", "5": "169088" }, { "0": "15.000", "1": "9", "2": "77", "3": "7128320", "4": "7693249.28", "5": "169984" }, { "0": "15.000", "1": "9", "2": "78", "3": "5061376", "4": "5629213.44", "5": "121856" }, { "0": "15.000", "1": "9", "2": "80", "3": "7743104", "4": "8722903.04", "5": "203264" }, { "0": "15.000", "1": "9", "2": "81", "3": "28808064", "4": "32882525.44", "5": "706048" }, { "0": "15.000", "1": "9", "2": "83", "3": "12662272", "4": "14586407.68", "5": "330880" }, { "0": "15.000", "1": "9", "2": "84", "3": "6509184", "4": "8482062.08", "5": "169856" }, { "0": "15.000", "1": "9", "2": "85", "3": "4782592", "4": "4991431.68", "5": "116864" }, { "0": "15.000", "1": "9", "2": "86", "3": "27021696", "4": "30225996.80", "5": "682624" }, { "0": "15.000", "1": "9", "2": "89", "3": "1578752", "4": "2027873.28", "5": "36096" }, { "0": "15.000", "1": "9", "2": "90", "3": "33806464", "4": "39663014.40", "5": "856704" }, { "0": "15.000", "1": "9", "2": "91", "3": "4442752", "4": "5842634.24", "5": "112768" }, { "0": "15.000", "1": "9", "2": "93", "3": "28200192", "4": "33006179.84", "5": "713984" }, { "0": "15.000", "1": "9", "2": "94", "3": "12681600", "4": "13601986.56", "5": "303232" }, { "0": "15.000", "1": "9", "2": "96", "3": "666624", "4": "473141.76", "5": "14464" }, { "0": "15.000", "1": "9", "2": "97", "3": "11993088", "4": "13300569.60", "5": "303104" }, { "0": "15.000", "1": "9", "2": "101", "3": "7575168", "4": "7600646.40", "5": "196992" }, { "0": "15.000", "1": "9", "2": "102", "3": "27441920", "4": "33995997.44", "5": "703872" }, { "0": "15.000", "1": "9", "2": "103", "3": "7057280", "4": "8503637.76", "5": "185088" }, { "0": "15.000", "1": "9", "2": "105", "3": "29710848", "4": "34073157.12", "5": "735872" }, { "0": "15.000", "1": "9", "2": "106", "3": "8104704", "4": "9812775.68", "5": "220416" }, { "0": "15.000", "1": "9", "2": "107", "3": "2590464", "4": "3028149.76", "5": "61952" }, { "0": "15.000", "1": "9", "2": "108", "3": "40156160", "4": "45593496.32", "5": "1001600" }, { "0": "15.000", "1": "9", "2": "115", "3": "2452096", "4": "2226137.60", "5": "60800" }, { "0": "15.000", "1": "9", "2": "116", "3": "23243392", "4": "24868823.04", "5": "564736" }, { "0": "15.000", "1": "9", "2": "118", "3": "14240128", "4": "15111184.64", "5": "353408" }, { "0": "15.000", "1": "9", "2": "119", "3": "40846720", "4": "45264224.00", "5": "1027456" }, { "0": "15.000", "1": "9", "2": "122", "3": "6732544", "4": "7716145.92", "5": "164992" }, { "0": "15.000", "1": "9", "2": "126", "3": "7082880", "4": "8110862.08", "5": "171008" }, { "0": "15.000", "1": "9", "2": "127", "3": "24211712", "4": "28525308.16", "5": "616576" }, { "0": "15.000", "1": "9", "2": "129", "3": "31437312", "4": "34298964.48", "5": "767488" }, { "0": "15.000", "1": "9", "2": "130", "3": "390272", "4": "315754.24", "5": "10880" }, { "0": "15.000", "1": "9", "2": "134", "3": "19598208", "4": "22598796.80", "5": "491520" }, { "0": "15.000", "1": "9", "2": "136", "3": "357248", "4": "296313.60", "5": "9856" }, { "0": "15.000", "1": "9", "2": "138", "3": "4697088", "4": "5400261.12", "5": "118144" }, { "0": "15.000", "1": "9", "2": "140", "3": "17321984", "4": "19747557.12", "5": "433280" }, { "0": "15.000", "1": "9", "2": "143", "3": "22007296", "4": "26812788.48", "5": "567040" }, { "0": "15.000", "1": "9", "2": "144", "3": "7777664", "4": "9402172.16", "5": "193152" }, { "0": "15.000", "1": "9", "2": "145", "3": "15399680", "4": "17946855.68", "5": "388096" }, { "0": "15.000", "1": "9", "2": "149", "3": "2256896", "4": "2663919.36", "5": "60416" }, { "0": "15.000", "1": "9", "2": "150", "3": "10869632", "4": "12971114.24", "5": "281344" }, { "0": "15.000", "1": "9", "2": "151", "3": "11137920", "4": "11154696.96", "5": "269568" }, { "0": "15.000", "1": "9", "2": "152", "3": "11700480", "4": "13719448.32", "5": "285056" }, { "0": "15.000", "1": "9", "2": "154", "3": "8281344", "4": "8556992.00", "5": "212864" }, { "0": "15.000", "1": "9", "2": "155", "3": "8951424", "4": "9563397.12", "5": "219264" }, { "0": "15.000", "1": "9", "2": "156", "3": "6004608", "4": "5900654.08", "5": "152192" }, { "0": "15.000", "1": "9", "2": "158", "3": "500480", "4": "65113.60", "5": "4352" }, { "0": "15.000", "1": "9", "2": "161", "3": "253952", "4": "56025.60", "5": "2816" }, { "0": "15.000", "1": "9", "2": "163", "3": "248320", "4": "48179.20", "5": "2688" }, { "0": "15.000", "1": "9", "2": "165", "3": "102016", "4": "12416.00", "5": "896" }, { "0": "15.000", "1": "9", "2": "167", "3": "16896", "4": "4608.00", "5": "256" }, { "0": "15.000", "1": "9", "2": "168", "3": "141184", "4": "21619.20", "5": "1408" }, { "0": "15.000", "1": "9", "2": "170", "3": "75776", "4": "13760.00", "5": "768" }, { "0": "15.000", "1": "9", "2": "171", "3": "112512", "4": "14681.60", "5": "1024" }, { "0": "15.000", "1": "9", "2": "172", "3": "77824", "4": "10137.60", "5": "768" }, { "0": "15.000", "1": "9", "2": "174", "3": "7680", "4": "2304.00", "5": "128" } ] }, "text/html": "
Tax RateLineage KeySalesperson KeySUM_QTYSUM_BASE_PRICECOUNT_ORDER
15.00094433280243367.689216
15.00096836480543988.4818432
15.00097724480846118.4024576
15.000988620801028780.8022144
15.000991101056924917.7628928
15.00091122792963886913.2862848
15.00091232625923852878.0885888
15.00091554848006343098.88144256
15.00091991831040107590420.482310528
15.00092112409602060285.4437632
15.00092310035201541052.1629696
15.00092529866242914885.1273344
15.000926497536725172.4812416
15.000927598016798522.8814592
15.00092812331521474490.8831488
15.000929387968304568.3210880
15.00093015493122156144.6447232
15.00093122152962227068.1650560
15.00093527247363383616.0072960
15.0009361101632012551537.92276992
15.00093815197441955315.2039552
15.0009393188838434617245.44785664
15.00094068074247944593.92176896
15.00094122191363174849.2863232
15.000945338176382839.047808
15.000946112128111915.522176
15.00094732556802629954.5675776
15.00094825959682310150.4060928
15.0009491475852817928881.92368768
15.000950804352926225.9219968
15.00095140078084360591.3697408
15.00095258634247464648.96156160
15.00095427367683351491.8472320
15.000956285824253144.327552
15.00095722982402447610.8858240
15.00095821447681723477.7650048
15.00096137322244086886.4086016
15.0009621267212813904339.20304000
15.0009631012620810138237.44243200
15.00096567874567473853.44171136
15.00096846387204848647.68107008
15.0009701488486416764665.60379776
15.00097225658882336160.0055936
15.0009741531788819187417.60384768
15.00097664812808637446.40169088
15.00097771283207693249.28169984
15.00097850613765629213.44121856
15.00098077431048722903.04203264
15.0009812880806432882525.44706048
15.0009831266227214586407.68330880
15.00098465091848482062.08169856
15.00098547825924991431.68116864
15.0009862702169630225996.80682624
15.00098915787522027873.2836096
15.0009903380646439663014.40856704
15.00099144427525842634.24112768
15.0009932820019233006179.84713984
15.0009941268160013601986.56303232
15.000996666624473141.7614464
15.0009971199308813300569.60303104
15.000910175751687600646.40196992
15.00091022744192033995997.44703872
15.000910370572808503637.76185088
15.00091052971084834073157.12735872
15.000910681047049812775.68220416
15.000910725904643028149.7661952
15.00091084015616045593496.321001600
15.000911524520962226137.6060800
15.00091162324339224868823.04564736
15.00091181424012815111184.64353408
15.00091194084672045264224.001027456
15.000912267325447716145.92164992
15.000912670828808110862.08171008
15.00091272421171228525308.16616576
15.00091293143731234298964.48767488
15.0009130390272315754.2410880
15.00091341959820822598796.80491520
15.0009136357248296313.609856
15.000913846970885400261.12118144
15.00091401732198419747557.12433280
15.00091432200729626812788.48567040
15.000914477776649402172.16193152
15.00091451539968017946855.68388096
15.000914922568962663919.3660416
15.00091501086963212971114.24281344
15.00091511113792011154696.96269568
15.00091521170048013719448.32285056
15.000915482813448556992.00212864
15.000915589514249563397.12219264
15.000915660046085900654.08152192
15.000915850048065113.604352
15.000916125395256025.602816
15.000916324832048179.202688
15.000916510201612416.00896
15.0009167168964608.00256
15.000916814118421619.201408
15.00091707577613760.00768
15.000917111251214681.601024
15.00091727782410137.60768
15.000917476802304.00128
" } } ], "execution_count": 9 }, { "cell_type": "markdown", "source": [ "### As you can see from the execution times, the query with Batch Mode for Rowstore finished much faster!" ], "metadata": { "azdata_cell_guid": "0992ad26-d475-47ef-9b3e-5b9ccd429013" } } ] }