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(7852)
Learning SQL by Alan Beaulieu(5412)
Weapons of Math Destruction by Cathy O'Neil(5038)
Big Data Analysis with Python by Ivan Marin(3014)
Blockchain Basics by Daniel Drescher(2891)
Hands-On Machine Learning for Algorithmic Trading by Stefan Jansen(2519)
Pandas Cookbook by Theodore Petrou(2502)
Building Statistical Models in Python by Huy Hoang Nguyen & Paul N Adams & Stuart J Miller(2486)
Mastering Python for Finance by Unknown(2476)
Azure Data and AI Architect Handbook by Olivier Mertens & Breght Van Baelen(2457)
Serverless Machine Learning with Amazon Redshift ML by Debu Panda & Phil Bates & Bhanu Pittampally & Sumeet Joshi(2391)
How The Mind Works by Steven Pinker(2214)
Data Wrangling on AWS by Navnit Shukla | Sankar M | Sam Palani(2173)
Data Engineering with dbt by Roberto Zagni(2062)
Building Machine Learning Systems with Python by Richert Willi Coelho Luis Pedro(2059)
Driving Data Quality with Data Contracts by Andrew Jones(2039)
Network Science with Python and NetworkX Quick Start Guide by Edward L. Platt(1975)
Python Natural Language Processing by Jalaj Thanaki(1892)
Machine Learning Model Serving Patterns and Best Practices by Md Johirul Islam(1837)