IT tutorials
 
Technology
 

SQL Server 2012 : The Path of the Query (part 4) - Filter by 2 x NC Indexes, Filter by Ordered Composite Index

11/6/2013 8:35:31 PM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

Query Path 7 — Filter by 2 x NC Indexes

A common indexing dilemma is how to index for multiple where clause criteria. Is it better to create one composite index that includes both key columns? Or do two single key column indexes perform better? Query Paths 7 through 9 evaluate the options.

The following code redefines the indexes: one index keyed on ProductID and one keyed on StartDate.

DROP INDEX Production.WorkOrder.IX_WorkOrder_ProductID;

CREATE INDEX IX_WorkOrder_ProductID
ON Production.WorkOrder (ProductID);

CREATE INDEX IX_WorkOrder_StartDate
ON Production.WorkOrder (StartDate);

With these indexes in place, this query filters by both key columns:

SELECT WorkOrderID, StartDate
FROM Production.WorkOrder
WHERE ProductID = 757
AND StartDate = ‘01/04/2006';

To use both indexes, SQL Server uses a merge join to request rows from each index seek and then correlates the data to return the rows that meet both criteria, as shown in Figure 10. This is known as index-intersection. SQL Server makes use of both indexes via separate operations to serve the query.

Figure 10 Filtering by two indexes adds a merge join into the mix.

45.14

Examining the performance stat in Table 1, multiple indexes have a query optimizer cost of .12 and use four logical reads.

For infrequent queries, Query Path 7, with its multiple indexes, is more than adequate and much better than no index at all. However, for those few queries that run constantly, the next query path is a better solution for multiple criteria.

Query Path 8 — Filter by Ordered Composite Index

For the raw performance, the fastest solution to the multiple-where-clause-criteria problem is a single composite index as demonstrated in Query Path 8.

Creating a composite index with ProductID and StartDate as key columns sets up the test:

DROP INDEX Production.WorkOrder.IX_WorkOrder_ProductID
DROP INDEX Production.WorkOrder.IX_WorkOrder_StartDate

CREATE INDEX IX_WorkOrder_ProductID
ON Production.WorkOrder (ProductID, StartDate);

Rerunning the same query,

SELECT WorkOrderID, StartDate
FROM Production.WorkOrder
WHERE ProductID = 757
AND StartDate = ‘2006-01-04';

The query execution plan, as shown in Figure , is a simple single index seek operation, and it performs wonderfully.

Figure 11 Filtering two criteria using a composite index performs like greased lighting.

45.15
 
Others
 
- SQL Server 2012 : The Path of the Query (part 3) - Bookmark Lookup
- SQL Server 2012 : The Path of the Query (part 2) - Range Seek Query, Filter by Nonkey Column
- SQL Server 2012 : The Path of the Query (part 1) - Fetch All, Clustered Index Seek
- SQL Server 2012 : Indexing Basics (part 2) - Index Selectivity, Query Operators
- SQL Server 2012 : Indexing Basics (part 1) - The B-Tree Index, Clustered Indexes, Nonclustered Indexes
- Windows 7 : Using Internet Explorer 8 - Using Multimedia Browsing and Downloading (part 3)
- Windows 7 : Using Internet Explorer 8 - Using Multimedia Browsing and Downloading (part 2)
- Windows 7 : Using Internet Explorer 8 - Using Multimedia Browsing and Downloading (part 1)
- Windows Server 2012 : Highly available, easy-to-manage multi-server platform - Management efficiency (part 3) - PowerShell 3.0
- Windows Server 2012 : Highly available, easy-to-manage multi-server platform - Management efficiency (part 2) - Simplified Active Directory administration
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us