SlideShare uma empresa Scribd logo
1 de 29
The Art ofIndexing http://www.flickr.com/photos/h-k-d/2837128711/ Ken Simmons
Who is this guy? ,[object Object]
Developer
Author
SQL Server MVP
IT Industry for 10+ years,[object Object]
Provide strategies for creating indexes by taking  advantage of DMVs and the Plan Cache.
Cover the various ways indexes can degrade  performance along with options for finding and  removing them.,[object Object]
http://www.flickr.com/photos/marsi/2208227079/
The BoringTechnical Stuff http://www.flickr.com/photos/paraflyer/386529128/
Types of Indexes ,[object Object]
Non Clustered
Unique
Filtered
Full-Text
Spatial
XMLhttp://www.flickr.com/photos/leunix/518329490/
Types of Indexes ,[object Object]
Non Clustered
Unique
Filtered
Full-Text
Spatial
XMLhttp://www.flickr.com/photos/leunix/518329490/
Types of Indexes ,[object Object]
Non Clustered
Unique
Filtered
Full-Text

Mais conteúdo relacionado

Destaque

Evolution of a Main Street
Evolution of a Main StreetEvolution of a Main Street
Evolution of a Main StreetSDDA
 
Cultivating a Downtown Marketplace--Staunton, VA
Cultivating a Downtown Marketplace--Staunton, VA Cultivating a Downtown Marketplace--Staunton, VA
Cultivating a Downtown Marketplace--Staunton, VA SDDA
 
Evolution of a Main Street
Evolution of a Main StreetEvolution of a Main Street
Evolution of a Main StreetSDDA
 
Liberating genius by Tammy Dunbar
Liberating genius by Tammy DunbarLiberating genius by Tammy Dunbar
Liberating genius by Tammy DunbarKornelia Lohynova
 
Memories of our summer vacation
 Memories of our summer vacation  Memories of our summer vacation
Memories of our summer vacation Kornelia Lohynova
 
Entrepreneurship in education
Entrepreneurship in educationEntrepreneurship in education
Entrepreneurship in educationKornelia Lohynova
 
The erotic brain by adolf tobeña
The erotic brain by adolf tobeñaThe erotic brain by adolf tobeña
The erotic brain by adolf tobeñacultura 3.0
 

Destaque (8)

Evolution of a Main Street
Evolution of a Main StreetEvolution of a Main Street
Evolution of a Main Street
 
Cultivating a Downtown Marketplace--Staunton, VA
Cultivating a Downtown Marketplace--Staunton, VA Cultivating a Downtown Marketplace--Staunton, VA
Cultivating a Downtown Marketplace--Staunton, VA
 
Evolution of a Main Street
Evolution of a Main StreetEvolution of a Main Street
Evolution of a Main Street
 
Tricider
TriciderTricider
Tricider
 
Liberating genius by Tammy Dunbar
Liberating genius by Tammy DunbarLiberating genius by Tammy Dunbar
Liberating genius by Tammy Dunbar
 
Memories of our summer vacation
 Memories of our summer vacation  Memories of our summer vacation
Memories of our summer vacation
 
Entrepreneurship in education
Entrepreneurship in educationEntrepreneurship in education
Entrepreneurship in education
 
The erotic brain by adolf tobeña
The erotic brain by adolf tobeñaThe erotic brain by adolf tobeña
The erotic brain by adolf tobeña
 

Semelhante a The Art Of Indexing

Solr and ElasticSearch demo and speaker feb 2014
Solr  and ElasticSearch demo and speaker feb 2014Solr  and ElasticSearch demo and speaker feb 2014
Solr and ElasticSearch demo and speaker feb 2014nkabra
 
Developing with SQL Server Analysis Services 201310
Developing with SQL Server Analysis Services 201310Developing with SQL Server Analysis Services 201310
Developing with SQL Server Analysis Services 201310Mark Tabladillo
 
Software Craftsmanship - 1 Meeting
Software Craftsmanship - 1 MeetingSoftware Craftsmanship - 1 Meeting
Software Craftsmanship - 1 MeetingUri Lavi
 
ASP.NET MVC Development with S#arp Architecture
ASP.NET MVC Development with S#arp ArchitectureASP.NET MVC Development with S#arp Architecture
ASP.NET MVC Development with S#arp ArchitectureSandeep Sachan
 
Scalable and Modular CSS FTW!
Scalable and Modular CSS FTW!Scalable and Modular CSS FTW!
Scalable and Modular CSS FTW!FITC
 
BrazilJS Perf Doctor Talk
BrazilJS Perf Doctor TalkBrazilJS Perf Doctor Talk
BrazilJS Perf Doctor TalkJosh Holmes
 
Wix Machine Learning - Ran Romano
Wix Machine Learning - Ran RomanoWix Machine Learning - Ran Romano
Wix Machine Learning - Ran RomanoWix Engineering
 
It's Business Time: Givin' User Experience Love with CSS3
It's Business Time: Givin' User Experience Love with CSS3It's Business Time: Givin' User Experience Love with CSS3
It's Business Time: Givin' User Experience Love with CSS3Denise Jacobs
 
Pimp your content with structured data
Pimp your content with structured dataPimp your content with structured data
Pimp your content with structured dataloonytoons
 
Secrets of Enterprise Data Mining 201305
Secrets of Enterprise Data Mining 201305Secrets of Enterprise Data Mining 201305
Secrets of Enterprise Data Mining 201305Mark Tabladillo
 
CUST-3 Document Management with Share
CUST-3 Document Management with ShareCUST-3 Document Management with Share
CUST-3 Document Management with ShareAlfresco Software
 
Developing Lightning Components for Communities.pptx
Developing Lightning Components for Communities.pptxDeveloping Lightning Components for Communities.pptx
Developing Lightning Components for Communities.pptxDmitry Vinnik
 
Secrets of Enterprise Data Mining 201310
Secrets of Enterprise Data Mining 201310Secrets of Enterprise Data Mining 201310
Secrets of Enterprise Data Mining 201310Mark Tabladillo
 
WWW09 - Triplify Light-Weight Linked Data Publication from Relational Databases
WWW09 - Triplify Light-Weight Linked Data Publication from Relational DatabasesWWW09 - Triplify Light-Weight Linked Data Publication from Relational Databases
WWW09 - Triplify Light-Weight Linked Data Publication from Relational DatabasesSören Auer
 
The SharePoint & jQuery Guide
The SharePoint & jQuery GuideThe SharePoint & jQuery Guide
The SharePoint & jQuery GuideMark Rackley
 
The SharePoint and jQuery Guide by Mark Rackley - SPTechCon
The SharePoint and jQuery Guide by Mark Rackley - SPTechConThe SharePoint and jQuery Guide by Mark Rackley - SPTechCon
The SharePoint and jQuery Guide by Mark Rackley - SPTechConSPTechCon
 
2011 - SharePoint + jQuery
2011 - SharePoint + jQuery2011 - SharePoint + jQuery
2011 - SharePoint + jQueryChris O'Connor
 
Web Components: The Future of Web Development is Here
Web Components: The Future of Web Development is HereWeb Components: The Future of Web Development is Here
Web Components: The Future of Web Development is HereJohn Riviello
 

Semelhante a The Art Of Indexing (20)

Solr and ElasticSearch demo and speaker feb 2014
Solr  and ElasticSearch demo and speaker feb 2014Solr  and ElasticSearch demo and speaker feb 2014
Solr and ElasticSearch demo and speaker feb 2014
 
Developing with SQL Server Analysis Services 201310
Developing with SQL Server Analysis Services 201310Developing with SQL Server Analysis Services 201310
Developing with SQL Server Analysis Services 201310
 
Software Craftsmanship - 1 Meeting
Software Craftsmanship - 1 MeetingSoftware Craftsmanship - 1 Meeting
Software Craftsmanship - 1 Meeting
 
ASP.NET MVC Development with S#arp Architecture
ASP.NET MVC Development with S#arp ArchitectureASP.NET MVC Development with S#arp Architecture
ASP.NET MVC Development with S#arp Architecture
 
Www.sandeepsachan.com
Www.sandeepsachan.comWww.sandeepsachan.com
Www.sandeepsachan.com
 
Scalable and Modular CSS FTW!
Scalable and Modular CSS FTW!Scalable and Modular CSS FTW!
Scalable and Modular CSS FTW!
 
BrazilJS Perf Doctor Talk
BrazilJS Perf Doctor TalkBrazilJS Perf Doctor Talk
BrazilJS Perf Doctor Talk
 
Wix Machine Learning - Ran Romano
Wix Machine Learning - Ran RomanoWix Machine Learning - Ran Romano
Wix Machine Learning - Ran Romano
 
NCompass Live: CSS: A Brief Introduction
NCompass Live: CSS: A Brief Introduction NCompass Live: CSS: A Brief Introduction
NCompass Live: CSS: A Brief Introduction
 
It's Business Time: Givin' User Experience Love with CSS3
It's Business Time: Givin' User Experience Love with CSS3It's Business Time: Givin' User Experience Love with CSS3
It's Business Time: Givin' User Experience Love with CSS3
 
Pimp your content with structured data
Pimp your content with structured dataPimp your content with structured data
Pimp your content with structured data
 
Secrets of Enterprise Data Mining 201305
Secrets of Enterprise Data Mining 201305Secrets of Enterprise Data Mining 201305
Secrets of Enterprise Data Mining 201305
 
CUST-3 Document Management with Share
CUST-3 Document Management with ShareCUST-3 Document Management with Share
CUST-3 Document Management with Share
 
Developing Lightning Components for Communities.pptx
Developing Lightning Components for Communities.pptxDeveloping Lightning Components for Communities.pptx
Developing Lightning Components for Communities.pptx
 
Secrets of Enterprise Data Mining 201310
Secrets of Enterprise Data Mining 201310Secrets of Enterprise Data Mining 201310
Secrets of Enterprise Data Mining 201310
 
WWW09 - Triplify Light-Weight Linked Data Publication from Relational Databases
WWW09 - Triplify Light-Weight Linked Data Publication from Relational DatabasesWWW09 - Triplify Light-Weight Linked Data Publication from Relational Databases
WWW09 - Triplify Light-Weight Linked Data Publication from Relational Databases
 
The SharePoint & jQuery Guide
The SharePoint & jQuery GuideThe SharePoint & jQuery Guide
The SharePoint & jQuery Guide
 
The SharePoint and jQuery Guide by Mark Rackley - SPTechCon
The SharePoint and jQuery Guide by Mark Rackley - SPTechConThe SharePoint and jQuery Guide by Mark Rackley - SPTechCon
The SharePoint and jQuery Guide by Mark Rackley - SPTechCon
 
2011 - SharePoint + jQuery
2011 - SharePoint + jQuery2011 - SharePoint + jQuery
2011 - SharePoint + jQuery
 
Web Components: The Future of Web Development is Here
Web Components: The Future of Web Development is HereWeb Components: The Future of Web Development is Here
Web Components: The Future of Web Development is Here
 

The Art Of Indexing

Notas do Editor

  1. Before we jump directly into applying indexes and tuning queries, let’s take a look at the types of indexes that are available and when you might want to use them.
  2. As you can see, there are several types of Indexes, but we will be focusing on Clustered and Non Clustered Indexes and the relationship they have with each other.
  3. I like to think of Unique as an attribute of an index. Both Clustered and Non Clustered Indexes can be Unique. Unique indexes have some hidden benefits the query optimizer can use. For example, if you are performing a SELECT DISTINCT on a column that has a Unique Index, SQL Server knows the values are already distinct and doesn’t have to do a SORT operation to weed out records.Books Online even has Non Clustered Indexes with INCLUDE as a type of index, but to me, INCLUDE is really not a type of index, it is just a way for you to get more bang for your buck out of Non Clustered indexes.
  4. Filtered Indexes where introduced in SQL Server 2008 and are a good way to create that are less expensive to maintain. Filtered Indexes are an extension of Non Clustered Indexes and allow you to create an index on a subset of data. Filtered Indexes basically allow you to add a WHERE clause to a Non Clustered Index.
  5. Finally, Full-Text, Spatial, and XML indexes are more specialized indexes that are only used when called for in certain scenarios.
  6. If you notice, they have increased the maximum indexes per table from 250 to 1000. This is Inclusive of the Clustered Index, meaning you can have 1 Clustered Index and 249 Non Clustered Indexes in 2005 and 999 Non Clustered Indexes in 2008.The increase has a lot to do with the ability to add Filtered Indexes in 2008. You can create several different indexes on the same column with different ranges in each. Although in most circumstances, I wouldn’t even want to come close to these numbers because indexes have to be maintained and can cause negative performance impacts.To help reduce these performance impacts you can only create an index with 16 columns or 900 bytes, whichever comes first.
  7. Identity columns have all of the qualities that make a good Clustered Index. So, let’s take a look why.The Clustered Index is duplicated across all of your Non Clustered Indexes so you want to make it as efficient as possible.
  8. Having a Narrow Index means less data will be duplicated and you will be able to fit more data per page. Meaning Less I/O to read through your Indexes. This also leads to smaller databases, backups, and index maintenance times.
  9. So why does Unique matter? Clustered Indexes are not required to be unique, but if you add values to your clustered index that are not unique, SQL Server will add a 4 byte internal identifier called a uniquifier. This kind of goes against our keeping the index narrow thing.
  10. You don’t want to change the values in your Clustered Index for a couple of reasons. First of all, since the values of your Clustered Index are contained in your Non Clustered Indexes, every time you update your Clustered Index, all of your Non Clustered Indexes have to be updated. Secondly, the pointers in the Clustered Index have to be maintained. If the Clustered Index Key changes, the record has to change locations causing fragmentation.
  11. Finally, if the Clustered Index is increasing, data is always added to the end of the Index. This is good because if you insert records in the middle of your table, SQL Server has to make room for the records causing page splits and page splits lead to fragmented indexes.
  12. That leaves the job of the Non Clustered Index to cover all of the other commonly used queries that aren’t covered by the Clustered Index and if they can’t completely cover the query, they can at least efficiently find the record and link back to the Clustered Index to get any other information the query may need.
  13. USE AdventureWorksGO--CleanupIF EXISTS (SELECT name FROM sysindexes WHERE name = 'ix_PersonContact_LastName') DROP INDEX ix_PersonContact_LastName ON Person.Contact--SeekSELECT Phone, EmailAddressFROM Person.ContactWHERE ContactID = 42--ScanSELECT Phone, EmailAddressFROM Person.ContactWHERE LastName = 'Wruck'--**********Lookup*********************CREATE NONCLUSTERED INDEX ix_PersonContact_LastNameON Person.Contact (LastName)SELECT Phone, EmailAddressFROM Person.ContactWHERE LastName = 'Wruck'--***********Include (Covering)***********CREATE INDEX ix_PersonContact_LastNameON Person.Contact (LastName) INCLUDE(Phone, EmailAddress) WITH (DROP_EXISTING = ON)SELECT Phone, EmailAddressFROM Person.ContactWHERE LastName = 'Wruck'--***********Hint************************SELECT Phone, EmailAddressFROM Person.Contact WITH (INDEX(PK_Contact_ContactID))WHERE LastName = 'Wruck'SELECT Phone, EmailAddressFROM Person.ContactWHERE LastName = 'Wruck'--***************************************
  14. Select * is like developers throwing ninja stars at your server.Select * basically means that your query will ALWAYS have to do a lookup on the Clustered Index unless you add every column in the table to the Non-Clustered Index (which is generally not a very good idea).
  15. DMVs give you a better perspective of your entire systemExpose information about your server/databaseFor example, every time SQL Server thinks it needs an index, it is recorded or every time a index is used (scan, seek, lookup, update)Stats reset whenever SQL is restartedMay want to collect information to analyze over time
  16. Always look to make sure you are not going to create overlapping or duplicate indexes.You may be able to alter an existing index by simply adding an extra column to the INCLUDE.Consolidate Indexes whenever where you can.