- Home
- Products
- Integration
- Tutorial
- Barcode FAQ
- Purchase
- Company
Lesson 2: Optimizing Index Strategies in Visual Studio .NET
Lesson 2: Optimizing Index Strategies GS1 - 12 Creator In Visual Studio .NET Using Barcode encoder for VS .NET Control to generate, create UCC - 12 image in Visual Studio .NET applications. www.OnBarcode.comUPC-A Reader In .NET Framework Using Barcode reader for .NET framework Control to read, scan read, scan image in Visual Studio .NET applications. www.OnBarcode.comTable 7-8 Printing Barcode In Visual Studio .NET Using Barcode encoder for Visual Studio .NET Control to generate, create bar code image in VS .NET applications. www.OnBarcode.comRecognize Barcode In Visual Studio .NET Using Barcode decoder for Visual Studio .NET Control to read, scan read, scan image in Visual Studio .NET applications. www.OnBarcode.comLevels of the IncludedColumns Index
GS1 - 12 Encoder In Visual C# Using Barcode creation for Visual Studio .NET Control to generate, create Universal Product Code version A image in Visual Studio .NET applications. www.OnBarcode.comUPC-A Encoder In .NET Framework Using Barcode creator for ASP.NET Control to generate, create UPCA image in ASP.NET applications. www.OnBarcode.comDefinition
UPC Symbol Creation In VB.NET Using Barcode creator for VS .NET Control to generate, create GTIN - 12 image in Visual Studio .NET applications. www.OnBarcode.comEAN / UCC - 13 Creator In Visual Studio .NET Using Barcode drawer for .NET framework Control to generate, create European Article Number 13 image in Visual Studio .NET applications. www.OnBarcode.comSELECT o.PKCol, i.Col2 FROM Test.OtherTable AS o INNER JOIN Test.IncludedColumnsTest AS i WITH(INDEX(IncludedColumns)) ON o.Col1 = i.Col1 WHERE o.PKCol BETWEEN 1 AND 10000; SELECT o.PKCol, i.Col2 FROM Test.OtherTable AS o INNER JOIN Test.IncludedColumnsTest AS i WITH(INDEX(NoIncludedColumns)) ON o.Col1 = i.Col1 WHERE o.PKCol BETWEEN 1 AND 10000; SELECT o.PKCol, i.Col2 FROM Test.OtherTable AS o INNER JOIN Test.IncludedColumnsTest AS i WITH(INDEX(NotCovered)) ON o.Col1 = i.Col1 WHERE o.PKCol BETWEEN 1 AND 10000; Barcode Creator In VS .NET Using Barcode maker for .NET framework Control to generate, create bar code image in Visual Studio .NET applications. www.OnBarcode.comQR Code 2d Barcode Encoder In .NET Using Barcode creation for .NET framework Control to generate, create QR Code image in .NET framework applications. www.OnBarcode.comQuery # Query #1 Index: IncludedColumns The execution plan is shown in Figure 7-5. Linear Barcode Generation In .NET Using Barcode generator for Visual Studio .NET Control to generate, create Linear image in .NET applications. www.OnBarcode.comIdentcode Generator In VS .NET Using Barcode creator for Visual Studio .NET Control to generate, create Identcode image in .NET applications. www.OnBarcode.comPage reads 32,726 pages
GS1 128 Creation In Java Using Barcode generation for Java Control to generate, create USS-128 image in Java applications. www.OnBarcode.comDecode ECC200 In Java Using Barcode recognizer for Java Control to read, scan read, scan image in Java applications. www.OnBarcode.comQuery #2 Index: NoIncludedColumns The execution plan is shown in Figure 7-5. Creating PDF 417 In Java Using Barcode generation for Java Control to generate, create PDF417 image in Java applications. www.OnBarcode.comPainting Code 128 Code Set A In .NET Using Barcode encoder for Reporting Service Control to generate, create Code 128C image in Reporting Service applications. www.OnBarcode.com53,994 pages
Painting Bar Code In Visual Basic .NET Using Barcode maker for .NET framework Control to generate, create bar code image in .NET framework applications. www.OnBarcode.comUPC-A Recognizer In Visual Studio .NET Using Barcode scanner for Visual Studio .NET Control to read, scan read, scan image in .NET applications. www.OnBarcode.comQuery #3 Index: NotCovered The execution plan is shown in Figure 7-5. Painting UPC - 13 In Java Using Barcode maker for Android Control to generate, create EAN / UCC - 13 image in Android applications. www.OnBarcode.comEncode UPC A In Java Using Barcode creator for Eclipse BIRT Control to generate, create UPC A image in Eclipse BIRT applications. www.OnBarcode.com62,617 pages
7
Optimizing SQL Server 2005 Performance
Figure 7-5 Execution plans for Queries 1 3 in SQL Server Management Studio
Query #1, with the IncludedColumns index, is the best-performing query with 32,726 page reads. Query #2, with the NoIncludedColumns index, used 53,994 page reads. As you can see, the difference in the number of page reads between the two indexes is roughly the same as the difference in index levels (40 percent). Query #3, with the NotCovered index, is the worst-performing query with 62,617 page reads because of the extra reads necessary to fetch the data that was not found in the index from the table. (Note the extra Nested Loops Join in the execution plan of Query #3.) Using Clustered Indexes
Because a clustered index is the actual table reading from the clustered index, it never results in lookups. Therefore, the clustered index should generally be defined on columns that are often queried and typically return a lot of data. This is because the problem of lookups and fetching a large number of rows doesn t exist. Two good candidates for the clustered index are either the most frequently queried foreign key column of the table (a search on a foreign key Lesson 2: Optimizing Index Strategies
typically returns many rows) or the most frequently searched date column. (Date searches generally return a large number of rows as well.) Another important consideration when selecting the column or columns on which to create the clustered index is that the key size of the clustered index should be as small as possible. If a clustered index exists on a table, all non-clustered indexes on that table will use the key of the clustered index as the row pointer from the non-clustered index to the table. If a clustered index does not exist, the Row Identifier is used, which takes up eight bytes of storage in each row of each non-clustered index. This can significantly increase size for larger tables. Consider the following: You have a table with 40,000,000 rows. The table has five non-clustered indexes. The clustered index key is 60 bytes wide. (This is not uncommon when you have clustered indexes that span a few columns.) The total size of all row pointers from the non-clustered indexes on this table (only the pointers) would be: 40,000,000 * 5 * 60 = 12,000,000,000 bytes (close to 12 gigabytes) If the clustered index was changed to be on only one column with a smaller data type, such as an integer for a foreign key, each row pointer would be only four bytes. Because four bytes is added to all duplicates of the clustered index key to keep it unique internally, the calculation uses eight bytes as the new clustered index key size. 40,000,000 * 5 * 8 = 1,600,000,000 bytes (close to 1.5 gigabytes) The difference in storage needed is more than 10 gigabytes. Exam Tip For the exam, it s important to know the difference in non-clustered indexes depending on whether a clustered index exists on the table. Read Performance vs. Write Performance
The addition of indexes typically only helps boost read performance. Write performance is typically degraded because the indexes must be kept up-to-date with the data in the table. If a table has five non-clustered indexes defined on it, an insert into that table is really six inserts: one for the table and one for each index. The same goes for deletes. With update statements, only indexes that contain the columns that are updated by the update statement must be touched.
|
|