SlideShare a Scribd company logo
1 of 9
Download to read offline
Defragging Indexes For Beginners,[object Object]
Why we need to defrag indexes,[object Object],Fragmented indexes are ineffective,[object Object],Ineffective indexes are slooooooow,[object Object]
Over to the code….,[object Object],We are going to: ,[object Object],Create a database,[object Object],Create a table ,[object Object],Load some data,[object Object],Add an index,[object Object],Fragment the index,[object Object],Fix the index,[object Object]
Demo...,[object Object]
Which option is best?,[object Object],> 5% and < = 30% fragmentation,[object Object],ALTER INDEX REORGANIZE,[object Object],> 30% fragmentation,[object Object],ALTER INDEX REBUILD WITH (ONLINE = ON),[object Object]
Keep your indexes sweet,[object Object],Perform regular maintenance on your database, include index checks/defrags as part of the maintenance task.,[object Object],A tool such as Idera’s SQL Defrag Manager could be useful, but it is pricey.,[object Object],Write a script and set up a scheduled task to automate your index maintenance.,[object Object]
Conclusion,[object Object],Reorganize Index,[object Object],Peformed online,[object Object],Does not lock for long periods,[object Object],Does not block updates or other queries,[object Object],Best option for fragmentation between 5% and 30%.,[object Object],Rebuild Index,[object Object],Drops and recreates the index,[object Object],Will give the best defragmentation results,[object Object],Can be performed online or offline,[object Object],Best option for fragmentation greater than 30%,[object Object],Maintenance,[object Object],Monitor your index fragmentation,[object Object],Fix fragmented indexes before they become a problem,[object Object]
Resources,[object Object],Click on the Word icon to the right to access the SQL code and notes used in the practical element of this session. ,[object Object],Download AdventureWorks2008 DBs for free here: http://tinyurl.com/c6y6a3,[object Object],More info on fill factors over at the MSDN site: http://msdn.microsoft.com/en-us/library/aa933139(SQL.80).aspx,[object Object],Detailed information on Reorganize and Rebuild: http://msdn.microsoft.com/en-us/library/ms189858(SQL.90).aspx,[object Object],Great information on Indexes from Brad McGehee,[object Object],http://tinyurl.com/mfx8h7,[object Object],Maintenance Options:,[object Object],http://www.idera.com/Products/SQL-Server/SQL-defrag-manager/,[object Object],http://msdn.microsoft.com/en-us/library/aa258803(SQL.80).aspx,[object Object]
Website:,[object Object],www.aucklandsql.com,[object Object],Mailing list:,[object Object],announce@aucklandsql.com,[object Object],Blog:,[object Object],http://nzgirlgeek.blogspot.com,[object Object],Email: ,[object Object],amanda@aucklandsql.com,[object Object]

More Related Content

Featured

AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 

Featured (20)

AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 

Defragging Indexes

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.

Editor's Notes

  1. Whenever you insert, update or delete data on a table with an associated index, that index will fragment slightly. Over time, this fragmentation gets worse and worse and eventually you have a counterproductive index on your table. If the indexes are fragmented then not only will the query response be very slow, but the data storage will also require more disk space. DBAs should be monitoring the performance of indexes on the servers they maintain, and defrag them when necessary to optimise database performance. This monitoring task can also be automated but that’s a talk for another time.
  2. We’ll be following these steps in the code, I’ll go through each item one at a time and I’ll make all of this available on my blog and the aucklandsql website, details at the end. What we’re going to do is create a new database and table that we can play around with, load some data into the table from AdventureWorks2008 and then we’ll add an index. We will then fragment the index and will try two options to fix that index, Reorganize and Rebuild Index. By the end of the presentation we will be able to see which option of defragging is more effective.
  3. Rebuild Index will defragment better than Reorganize, however it is not always practical to rebuild indexes. MSDN has these guidelines in it’s page about defragging indexes.Reorganize an index when the index is not heavily fragmented. If the index is heavily fragmented, you will achieve better results by rebuilding the index.Rebuilding an index can be executed online or offline. Reorganizing an index is always executed online. To achieve availability similar to the reorganize option, you should rebuild indexes online.
  4. SQL Defrag Manager $1000+ per license.Useful script on BOL that checks all indexes on a database and defrags if above a declared threshold – easily adaptable to use ALTER INDEX REORGANIZE or REBUILD instead of DBCC INDEXDEFRAG . Link to script available at the end – though you may want to write your own from scratch if you have an aversion to cursors.Another thing to mention is that dropping/recreating indexes can be used to move existing tables from one filegroup to another without needing to rebuild scheme / move data.
  5. When creating a database, assign the largest value possible to your data files.If using automatic growth on your data files, specify a maximum growth size.If you have a lot of files in the same filegroup or disk partition, do not let them grow automatically, or consider splitting them across several partitions.Set up an index maintenance schedule so that the indexes are regularly evaluated (this can be automated)