SQL Server Advanced Troubleshooting and Performance Tuning by Dmitri Korotkevitch
Author:Dmitri Korotkevitch [Dmitri Korotkevitch]
Language: eng
Format: epub, pdf
Publisher: O'Reilly Media, Inc.
Published: 2022-04-25T00:00:00+00:00
Figure 5-21. Indexing example: Plan with the index on Customers table
There are three predicates with Orders table columns. Two of themâon the CustomerId and OrderDate columnsâare selective, and thus good candidates for the index. You can define the index with either (CustomerId, OrderDate) or (OrderDate, CustomerId) column order.
To choose, consider how data will be sorted in the index. With the first option, (CustomerId, OrderDate), SQL Server sorts the data by CustomerId first. Then the orders for each customer are sorted by OrderDate. With the second option, the data will be sorted by OrderDate across all customers.
Both indexes will allow index seek in the Orders table. However, the first index is more efficient for our query. SQL Server will be able to do a range scan for orders that belong to this single customer for the time interval defined by @StartDate and @EndDate. With the second index, SQL Server would have to read all orders in that time interval for all customers, which would force it to scan more data.
Itâs good to add the Fulfilled column to the index as an included column, to evaluate the predicate as part of the seek operation. In this case, Iâd also include the Amount column â it is small enough and would not increase the size of the index much.
Figure 5-22 shows the final execution plan after the following index has been created: CREATE INDEX IDX_Orders_CustomerId_OrderDate ON dbo.Orders(CustomerId, OrderDate) INCLUDE (Fulfilled, Amount).
Download
SQL Server Advanced Troubleshooting and Performance Tuning by Dmitri Korotkevitch.pdf
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8298)
Azure Data and AI Architect Handbook by Olivier Mertens & Breght Van Baelen(6736)
Building Statistical Models in Python by Huy Hoang Nguyen & Paul N Adams & Stuart J Miller(6713)
Serverless Machine Learning with Amazon Redshift ML by Debu Panda & Phil Bates & Bhanu Pittampally & Sumeet Joshi(6588)
Data Wrangling on AWS by Navnit Shukla | Sankar M | Sam Palani(6371)
Driving Data Quality with Data Contracts by Andrew Jones(6321)
Machine Learning Model Serving Patterns and Best Practices by Md Johirul Islam(6086)
Learning SQL by Alan Beaulieu(5994)
Weapons of Math Destruction by Cathy O'Neil(5779)
Big Data Analysis with Python by Ivan Marin(5362)
Data Engineering with dbt by Roberto Zagni(4359)
Solidity Programming Essentials by Ritesh Modi(4008)
Time Series Analysis with Python Cookbook by Tarek A. Atwan(3866)
Pandas Cookbook by Theodore Petrou(3577)
Blockchain Basics by Daniel Drescher(3294)
Hands-On Machine Learning for Algorithmic Trading by Stefan Jansen(2905)
Feature Store for Machine Learning by Jayanth Kumar M J(2814)
Learn T-SQL Querying by Pam Lahoud & Pedro Lopes(2796)
Mastering Python for Finance by Unknown(2744)
