SlideShare a Scribd company logo
Index TuningBy Roi AssaRoi.Assa@888Holdings.com
Topics:Fragmentation typesHow to identify?How to analyze it?Resolving fragmentation issuesExamples…
Extents
Fragmentation Types
External FragmentationOccurs when an index leaf page is not in logical orderKnown as logical fragmentation as wellFor example:On Insert - it is possible that new keys will be inserted in between existing keysThis may cause new index pages to be created to accommodate any existing keys that were moved so that the new keys can be inserted in correct order
These new index pages usually will not be physically adjacent to the pages the moved keys were originally stored inExternal FragmentationIndex structure before any additional data inserts:An INSERT statement adds new data to the index (value=5). This insert will cause the index pages to be out of logical order. SELECT * FROM Table	WHERE Data BETWEEN 4 AND 10
Internal FragmentationInternal fragmentation occurs when the index pages are not being used to their maximum volume. Severe internal fragmentation can lead to increased index size and cause additional reads to be performed to return needed data.
These extra reads can lead to degradation in query performance. Internal FragmentationIndex structure before any additional data inserts:An INSERT statement adds new data to the index (value=5). This insert will cause the index page not to use the maximum volume.
How to identify?
How to identify?select *  from sys.dm_db_index_physical_stats(     { database_id | NULL | 0 | DEFAULT }    , { object_id | NULL | 0 | DEFAULT }    , { index_id | NULL | 0 | -1 | DEFAULT }    , { partition_number | NULL | 0 | DEFAULT }    , { mode | NULL | DEFAULT })
How to identify?Scanning Modes :LIMITED – The fastestIt scans all pages for a heap, but only the parent-level pages for an index, which are the pages above the leaf-levelSAMPLED – Returns statistics based on a 1 percent sample of all the pages in the index or heapDETAILEDScans all pages and returns all statistics.
How To Analyze It?
Resultsalloc_unit_type_desc
IN_ROW_DATA
LOB_DATA
ROW_OVERFLOW_DATA (varchar, nvarchar, varbinary, or sql_variant)
index_depth - Number of index levels
index_level - Current level of the index		(The nonleaf levels of indexes are only processed when mode = DETAILED)
Resultsavg_fragmentation_in_percent – Percentage of external fragmentation (out-of-order pages in the index)The lower the number the better > 5% and < = 30%   ALTER INDEX REORGANIZE		> 30%	              ALTER INDEX REBUILD WITH (ONLINE = ON)fragment_count - The number of fragments in the index (physically consecutive leaf pages)avg_fragment_size_in_pages - Average number of pages in one fragment in an index (page_count/ fragment_count)	Should be as high as possiblepage_count - Total number of index or data pages
Results (for Sampled and Detailed)avg_page_space_used_in_percent - Average percentage of available data storage space used in all pages (internal)	Should be as high as possibleghost_record_count - Number of ghost records ready for removal by the ghost cleanup task 	(records are in the pages physically but not there logically due to deletion or update)version_ghost_record_count - Counts those records which are logically not in the table but cannot be deleted yet due to an open transaction using row versioning (running on snapshot isolation level)
Results (for Sampled and Detailed)forwarded_record_count - Number of records in a heap that have forward pointers to another data location	(Occurs during an update, when there is not enough room to store the new row in the original location)SQL Server 2008compressed_page_count - The number of compressed pagesResolving Fragmentation Issues
Rebuilding Indexes (BOL)Rebuilding an index drops and re-creates the index

More Related Content

DOCX
Index in sql server
PPT
Database indexing framework
PPTX
Sql server lesson6
PPTX
Sql server ___________session_17(indexes)
ODP
Database index by Reema Gajjar
PPTX
Database index
PPTX
Database indexing techniques
PDF
Oracle SQL Part 3
Index in sql server
Database indexing framework
Sql server lesson6
Sql server ___________session_17(indexes)
Database index by Reema Gajjar
Database index
Database indexing techniques
Oracle SQL Part 3

What's hot (20)

PPT
Mysql Indexing
PPTX
Introduction of sql server indexing
PDF
Database Indexes
PDF
Oracle SQL Part 2
PPT
Lecture12 abap on line
PDF
"Using Indexes in SQL Server 2008" by Alexander Korotkiy, part 1
PPTX
Ms sql server tips 1 0
PPT
Fg d
DOC
SQL Joins
PPTX
Inner join and outer join
PDF
Ijebea14 228
PPTX
SQL Server Index and Partition Strategy
PDF
8 i index_tables
PDF
PPTX
MS Office Access Tutorial
PDF
Introduction to Databases - query optimizations for MySQL
PPT
Training MS Access 2007
PPTX
MS Access Ch 2 PPT
PPTX
Introduction - Database (MS Access)
PPT
Ms access tutorial
Mysql Indexing
Introduction of sql server indexing
Database Indexes
Oracle SQL Part 2
Lecture12 abap on line
"Using Indexes in SQL Server 2008" by Alexander Korotkiy, part 1
Ms sql server tips 1 0
Fg d
SQL Joins
Inner join and outer join
Ijebea14 228
SQL Server Index and Partition Strategy
8 i index_tables
MS Office Access Tutorial
Introduction to Databases - query optimizations for MySQL
Training MS Access 2007
MS Access Ch 2 PPT
Introduction - Database (MS Access)
Ms access tutorial
Ad

Viewers also liked (11)

PPTX
Advanced Index Tuning
PDF
Back2 Basic Tools
PPT
Temporal
PPS
Big data hadoop rdbms
PPT
5. Other Relational Languages in DBMS
PDF
Advanced MySQL Query and Schema Tuning
PDF
Temporal database
PDF
Performance tuning and optimization (ppt)
PPSX
Database Performance Tuning Introduction
PPTX
Object oriented database model
PPT
Object Oriented Dbms
Advanced Index Tuning
Back2 Basic Tools
Temporal
Big data hadoop rdbms
5. Other Relational Languages in DBMS
Advanced MySQL Query and Schema Tuning
Temporal database
Performance tuning and optimization (ppt)
Database Performance Tuning Introduction
Object oriented database model
Object Oriented Dbms
Ad

Similar to Index Tuning (20)

PPT
Indexing Strategies
PPTX
dotnetMALAGA - Sql query tuning guidelines
PPT
Module08
PPT
Module08
PPTX
Database Basics
PPTX
Database Performance
PPTX
Getting to know oracle database objects iot, mviews, clusters and more…
PPT
Optimizing Data Accessin Sq Lserver2005
PPT
Myth busters - performance tuning 102 2008
PDF
database.pdf
PPT
Sql Server Basics
PPT
Lucene basics
PPTX
Advance sqlite3
PDF
Indexing techniques
PDF
Sql Interview Questions
PDF
Sql
PDF
PDF
153680 sqlinterview
PDF
PDF
Brad McGehee Intepreting Execution Plans Mar09
Indexing Strategies
dotnetMALAGA - Sql query tuning guidelines
Module08
Module08
Database Basics
Database Performance
Getting to know oracle database objects iot, mviews, clusters and more…
Optimizing Data Accessin Sq Lserver2005
Myth busters - performance tuning 102 2008
database.pdf
Sql Server Basics
Lucene basics
Advance sqlite3
Indexing techniques
Sql Interview Questions
Sql
153680 sqlinterview
Brad McGehee Intepreting Execution Plans Mar09

More from sqlserver.co.il (20)

PDF
Windows azure sql_database_security_isug012013
PPTX
Things you can find in the plan cache
PPTX
Sql server user group news january 2013
PPTX
DAC 2012
PPTX
Query handlingbytheserver
PPTX
Adi Sapir ISUG 123 11/10/2012
PPTX
Products.intro.forum version
PPTX
SQL Explore 2012: P&T Part 3
PPTX
SQL Explore 2012: P&T Part 2
PPTX
SQL Explore 2012: P&T Part 1
PPTX
SQL Explore 2012 - Tzahi Hakikat and Keren Bartal: Extended Events
PPTX
SQL Explore 2012 - Michael Zilberstein: ColumnStore
PPTX
SQL Explore 2012 - Meir Dudai: DAC
PPTX
SQL Explore 2012 - Aviad Deri: Spatial
PPTX
מיכאל
PPTX
נועם
PPTX
PPTX
מיכאל
PDF
Bi303 data warehousing with fast track and pdw - Assaf Fraenkel
PPTX
DBCC - Dubi Lebel
Windows azure sql_database_security_isug012013
Things you can find in the plan cache
Sql server user group news january 2013
DAC 2012
Query handlingbytheserver
Adi Sapir ISUG 123 11/10/2012
Products.intro.forum version
SQL Explore 2012: P&T Part 3
SQL Explore 2012: P&T Part 2
SQL Explore 2012: P&T Part 1
SQL Explore 2012 - Tzahi Hakikat and Keren Bartal: Extended Events
SQL Explore 2012 - Michael Zilberstein: ColumnStore
SQL Explore 2012 - Meir Dudai: DAC
SQL Explore 2012 - Aviad Deri: Spatial
מיכאל
נועם
מיכאל
Bi303 data warehousing with fast track and pdw - Assaf Fraenkel
DBCC - Dubi Lebel

Recently uploaded (20)

PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
Spectroscopy.pptx food analysis technology
PPTX
sap open course for s4hana steps from ECC to s4
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPT
Teaching material agriculture food technology
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Empathic Computing: Creating Shared Understanding
PPTX
Big Data Technologies - Introduction.pptx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
Chapter 3 Spatial Domain Image Processing.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
Building Integrated photovoltaic BIPV_UPV.pdf
Spectral efficient network and resource selection model in 5G networks
Reach Out and Touch Someone: Haptics and Empathic Computing
Spectroscopy.pptx food analysis technology
sap open course for s4hana steps from ECC to s4
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
The AUB Centre for AI in Media Proposal.docx
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Mobile App Security Testing_ A Comprehensive Guide.pdf
Review of recent advances in non-invasive hemoglobin estimation
Advanced methodologies resolving dimensionality complications for autism neur...
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Teaching material agriculture food technology
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Empathic Computing: Creating Shared Understanding
Big Data Technologies - Introduction.pptx
20250228 LYD VKU AI Blended-Learning.pptx

Index Tuning

  • 1. Index TuningBy Roi AssaRoi.Assa@888Holdings.com
  • 2. Topics:Fragmentation typesHow to identify?How to analyze it?Resolving fragmentation issuesExamples…
  • 5. External FragmentationOccurs when an index leaf page is not in logical orderKnown as logical fragmentation as wellFor example:On Insert - it is possible that new keys will be inserted in between existing keysThis may cause new index pages to be created to accommodate any existing keys that were moved so that the new keys can be inserted in correct order
  • 6. These new index pages usually will not be physically adjacent to the pages the moved keys were originally stored inExternal FragmentationIndex structure before any additional data inserts:An INSERT statement adds new data to the index (value=5). This insert will cause the index pages to be out of logical order. SELECT * FROM Table WHERE Data BETWEEN 4 AND 10
  • 7. Internal FragmentationInternal fragmentation occurs when the index pages are not being used to their maximum volume. Severe internal fragmentation can lead to increased index size and cause additional reads to be performed to return needed data.
  • 8. These extra reads can lead to degradation in query performance. Internal FragmentationIndex structure before any additional data inserts:An INSERT statement adds new data to the index (value=5). This insert will cause the index page not to use the maximum volume.
  • 10. How to identify?select * from sys.dm_db_index_physical_stats( { database_id | NULL | 0 | DEFAULT } , { object_id | NULL | 0 | DEFAULT } , { index_id | NULL | 0 | -1 | DEFAULT } , { partition_number | NULL | 0 | DEFAULT } , { mode | NULL | DEFAULT })
  • 11. How to identify?Scanning Modes :LIMITED – The fastestIt scans all pages for a heap, but only the parent-level pages for an index, which are the pages above the leaf-levelSAMPLED – Returns statistics based on a 1 percent sample of all the pages in the index or heapDETAILEDScans all pages and returns all statistics.
  • 16. ROW_OVERFLOW_DATA (varchar, nvarchar, varbinary, or sql_variant)
  • 17. index_depth - Number of index levels
  • 18. index_level - Current level of the index (The nonleaf levels of indexes are only processed when mode = DETAILED)
  • 19. Resultsavg_fragmentation_in_percent – Percentage of external fragmentation (out-of-order pages in the index)The lower the number the better > 5% and < = 30%  ALTER INDEX REORGANIZE > 30%  ALTER INDEX REBUILD WITH (ONLINE = ON)fragment_count - The number of fragments in the index (physically consecutive leaf pages)avg_fragment_size_in_pages - Average number of pages in one fragment in an index (page_count/ fragment_count) Should be as high as possiblepage_count - Total number of index or data pages
  • 20. Results (for Sampled and Detailed)avg_page_space_used_in_percent - Average percentage of available data storage space used in all pages (internal) Should be as high as possibleghost_record_count - Number of ghost records ready for removal by the ghost cleanup task (records are in the pages physically but not there logically due to deletion or update)version_ghost_record_count - Counts those records which are logically not in the table but cannot be deleted yet due to an open transaction using row versioning (running on snapshot isolation level)
  • 21. Results (for Sampled and Detailed)forwarded_record_count - Number of records in a heap that have forward pointers to another data location (Occurs during an update, when there is not enough room to store the new row in the original location)SQL Server 2008compressed_page_count - The number of compressed pagesResolving Fragmentation Issues
  • 22. Rebuilding Indexes (BOL)Rebuilding an index drops and re-creates the index
  • 25. reclaims disk space by compacting the pages based on the specified or existing fill factor setting
  • 26. reorders the index rows in contiguous pagesALTER INDEX PK_Employee_EmployeeID ON HumanResources.Employee REBUILDCREATE UNIQUE CLUSTERED INDEX PK_Employee_EmployeeID ON HumanResources.Employee(EmployeeID ) WITH (DROP_EXISTING = ON)
  • 27. Reorganizing Indexes (BOL)Physically reordering the leaf-level pages to match the logical, left to right, order of the leaf nodes
  • 29. Compacts the index pages (based on the existing fill factor value)
  • 30. Uses minimal system resources
  • 31. Two phases: Compaction DefragALTER INDEX PK_Employee_EmployeeID ON HumanResources.Employee REORGANIZE
  • 32. Rebuilding vs. ReorganizingRebuild - Re-create the index internally again and when that has been achieved, it drops the existing index Statistics are re-computed Require free spaceReorganize – Physically re-organizing the leaf nodes of the indexDoes not update statisticsSwaps one page with another and therefore does not require free spaceCan free up some pages (compaction and defrag)Can remove logical fragmentation Not necessarily fix extent fragmentation (in which the previous and the next extents are physically contiguous)