indexing internals

22
Indexing Internals Denny Cherry [email protected] twitter.com/mrdenny

Upload: farrah

Post on 23-Feb-2016

44 views

Category:

Documents


0 download

DESCRIPTION

Indexing Internals. Denny Cherry [email protected] twitter.com/ mrdenny. About Me. Author or Coauthor of 4 books 6+ SQL Mag articles Dozens of other articles Microsoft MVP since Oct 2008 Microsoft Certified Master Founder of SQL Excursions Sr. DBA for Phreesia. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Indexing Internals

Indexing InternalsDenny Cherry

[email protected]/mrdenny

Page 2: Indexing Internals

2

About MeAuthor or Coauthor of 4 books6+ SQL Mag articlesDozens of other articlesMicrosoft MVP since Oct 2008Microsoft Certified MasterFounder of SQL ExcursionsSr. DBA for Phreesia

Page 3: Indexing Internals

What we’ll be covering…Clustered IndexesNon-Clustered Indexes

Filtered Indexes

Page 4: Indexing Internals

What we won’t be covering…Spacial IndexesFull Text IndexesCompressed Indexes

Page 5: Indexing Internals

Structures…Indexes are made up of B-Trees which make

the index navigableIndexes are almost always made up of at

least two data pages.A Root PageA Leaf PageClustered Indexes also have Data Pages

Lets look at some pretty pictures…

Page 6: Indexing Internals

Clustered Index

Page 7: Indexing Internals

Clustered Index Data PageContains one row for every row in the tableContains all in row dataContains pointers to out of row data

TEXTNTEXTIMAGE

Contains pointers to overflow dataXMLVARCHAR(MAX)NVARCHAR(MAX)VARBINARY(MAX)

Page 8: Indexing Internals

Slot ArrayShows what row within the page each row

occupiesContains the Clustered Index value and row

id only

Page 9: Indexing Internals

Clustered Index Intermediate LevelsContains one row, for each page below itEach row contains…

Clustered Key ValueFile Id (2 bytes)Page Id (4 bytes)Row Overhead (At least one byte)

Page 10: Indexing Internals

Row Overhead?1 Byte by defaultNulls?Variable Width Data Types?

Page 11: Indexing Internals

Clustered Index Root PageOnly a single root page can existContains one row, for each page below itEach row contains…

Clustered Key ValueFile Id (2 bytes)Page Id (4 bytes)Row Overhead (At least one byte)

Page 12: Indexing Internals

Navigating The Clustered Index

Page 13: Indexing Internals

Splitting the Root Page

Page 14: Indexing Internals

Uniqueifier … Non-Unique clustered indexes have an extra

column called the uniqueifier which ensures that values within the index are unique.

Uniqueifier is only used for rows which are not unique. EmpId Uniqufier

1  

2  

3  

4 0

4 1

5  

6  

7 0

7 1

8  

Page 15: Indexing Internals

Non-Clustered Index

Page 16: Indexing Internals

Nonclustered Index Intermediate PageContains one row for every row in the tableContains indexed value and clustered index

key or RID

Page 17: Indexing Internals

NonClustered Index Root PageOnly a single root page can existContains one row, for each page below itEach row contains…

Indexed Key ValueClustered Key Value or RID (if index is not

unique)File Id (2 bytes)Page Id (4 bytes)Row Overhead (At least one byte)

Page 18: Indexing Internals

Navigating The NonClustered Index

Page 19: Indexing Internals

Navigating The Clustered Index

Page 20: Indexing Internals

B-Tree SizesEach B-Tree page can store info about X child

pages…INT = 8096/13 bytes = 622 pagesBIGINT = 8096/17 bytes = 476 pagesGUID = 8096/25 bytes = 323 pages

Page 21: Indexing Internals

Sample Index SizeRoot Level = 1 pageIntermediate Level = 7 pagesData Pages = 11233 pages

Another page level requires 7,650,600 data pages for a fourth level

Page 22: Indexing Internals

Denny [email protected]

http://itke.techtarget.com/sql-server

Please fill out the survey at http://speakerrate.com/mrdenny.