Chris Shaw CShaw@Xtivia.com @SQLShaw Index Feng Shui Chris Shaw CShaw@Xtivia.com @SQLShaw
Rules of the Dojo Stop me and ask questions. If it takes to long we may need to take it to a side bar. Feel free to e-mail me Cshaw@xtivia.com. Scripts can be downloaded from my blog.
Sensei (About) CShaw@Xtivia.com 6 SQL Server MVP Awards @SQLShaw http://chrisshaw.wordpress.com 6 SQL Server MVP Awards 17 years of experience
Expectations Use this session as a launching pad. There is a lot of information in here, and we don’t have time to cover all of it.
What is an index Think of a book, if you are looking for Brain Surgery in a Medical book, where do you find the information you need? Could the page numbers be considered an index? Is the table of contents in the front of the book considered an index? What if there wasn’t an index or a TOC? How long would that take? Think about your MP3 player, is that an index?
B-tree Root Intermediate Leaf
Primary Index Types Heap Clustered Indexes Non-Clustered Indexes A Table without a clustered index Clustered Indexes All the data in sorted in the Leaf Node Non-Clustered Indexes Contains rows identified in the index other data is retrieved by a lookup.
Leaf Node Heap Clustered Indexes Non-Clustered Indexes
Leaf Node Heap Clustered Indexes Non-Clustered Indexes
Index Types and Strategies Column Store New in 2012 Modified in 2014 Covering All the data you need is in the index Filtered Ability to remove rows that are not needed
Column Store Ideal for OLAP databases New Index type in SQL Server 2012 Enterprise Edition Non-Updateable SQL Server 2014 Updateable
Column Store Data is stored by column not by row Data is non-clustered Data is non-Unique
Covering Indexes Most often used to match specific Queries. Select [Name], [City], [State], [Cell], [Email] From Customers Allows the index to return all required data without additional I/O Big increase in performance Easy to overuse
Covering Indexes
Filtered Indexes Allow indexing of only relevant data. ex. Index only non-null data Improves Maintenance Performance Improved Storage Improved Query Plans
Additional Index Terms Selectivity The unique quality of data in a row Fill Factors The percentage of data on a page 80% fill factor leaves 20% free space 0 and 100 % are the same or are they? Page Splits Seeks Optimal use of the index Scans (RBAR) Analyzing each row.
Common Indexing Issues Not being maintained - Index is there just fragmented As a table grows the search's slow Demo - Fragmented Indexes To much maintenance Not enough Indexes Slow Searches Demo - Missing Indexes To Many Indexes - When indexes hurt. Slow Insert Statements Demo - Demo Index Usage Indexes that get you only half way there. Book Mark Lookups
Entering the Zen Best decisions are made with complete information. Gather information using: DMV's Query Plans Performance Monitor Statistics IO Showplan_All
Demo
Maintenance Maintenance Plans Difference between rebuild and re-organize?
Index FAQ Is the PK required to be clustered? What about Statistics? How Often should I re-index. What about online re-indexing?
Thank You Questions Cshaw@Xtivia.com @SQLShaw