SQL Server Performance

  • Home
  • Articles
  • Forums
  • Tips
  • Training
  • FAQ's
  • Blogs
  • Software
  • Books
  • About Us
RSS Feeds
Sign in | Join


Article Topics

All Articles
Performance Tuning
Audit
Business Intelligence
Clustering
Reporting Services
SQL Azure
Developer
General DBA
ASP.NET / ADO.NET
SQL Azure

USEFUL SITES :

ASP.NET Tutorials
Windows and SQL Azure Tutorials
Cloud Hosting Magazine
SharePoint Tutorials
Windows Server Help

Write for Us

Share your SQL Server knowledge with others and raise your profile in the community More...
Latest Articles

A High Level Comparison Between Oracle and SQL Server - Part ...
A High Level Comparison Between Oracle and SQL Server - Part ...
A High Level Comparison Between Oracle and SQL Server - Part ...
A High Level Comparison Between Oracle and SQL Server

More     
 
Latest FAQ's

Add Node to A SQL Server failover Cluster failed with invalid ...
SQL Server Destination remote server error
Setting Up Data And Log Files For SQL Server
Will Check Constraints Improve Database Performance?

More     
   
Latest Software Reviews

dbForge Review
Spotlight on ApexSQL Diff - Server-based database comparison tool ...
Spotlight on ApexSQL Data Diff - Server-based database comparison tool ...
Spotlight on ApexSQL Doc 2008

More     

articles >> performance tuning >> SQL Server Index Fragmentation and Its Resolution ...

SQL Server Index Fragmentation and Its Resolution

By : Randy Dyess
Oct 27, 2004

Page 2 / 3

Syntax (SQL Server 7.0)
DBCC SHOWCONTIG
    [    ( table_id [,index_id ]
        )
    ]

Examples:
Query to show fragmentation information on all indexes in a database
--Show fragmentation information on all indexes in a database
--Clean up the display
SET NOCOUNT ON

--Use the pubs database
USE pubs

DBCC SHOWCONTIG WITH ALL_INDEXES
GO
Query to show fragmentation information on all indexes on a table
--Show fragmentation information on all indexes on a table
--Clean up the display
SET NOCOUNT ON

--Use the pubs database
USE pubs

DBCC SHOWCONTIG (authors) WITH ALL_INDEXES
GO
Query to show fragmentation information on a specific index
--Show fragmentation information on a specific index
--Clean up the display
SET NOCOUNT ON

--Use the pubs database
USE pubs

DBCC SHOWCONTIG (authors,aunmind)
GO

Result Set

DBCC SHOWCONTIG will return the number of pages scanned, the number of extents scanned, the number of times the DBCC statement moved from one extent to another while it traversed the pages of the table or index, the average number of pages per extent, the scan density (best count is the ideal number of extent changes if everything is contiguously linked).

DBCC SHOWCONTIG scanning 'authors' table...
Table: 'authors' (1977058079); index ID: 1, database ID: 5
TABLE level scan performed.
- Pages Scanned................................: 1
- Extents Scanned..............................: 1
- Extent Switches..............................: 0
- Avg. Pages per Extent........................: 1.0
- Scan Density [Best Count: Actual Count]......: 100.00% [1:1]
- Logical Scan Fragmentation ..................: 0.00%
- Extent Scan Fragmentation ...................: 0.00%
- Avg. Bytes Free per Page.....................: 6002.0
- Avg. Page Density (full).....................: 25.85%
DBCC execution completed. If DBCC printed error messages,
contact your system administrator.

What to Look For

Pages Scanned: If you know the approximate row size and the number of rows contained in your table or index, you can estimate the number of pages there should be in that index. Look at the number of pages scanned and if it is significantly higher than the number of pages you estimated, you have internal fragmentation.

Extents Scanned: Take the number of pages scanned and divide that number by 8, rounded to the next highest interval. This figure should match the number of extents scanned returned by DBCC SHOWCONTIG. If the number returned by DBCC SHOWCONTIG is higher, then you have some external fragmentation. The seriousness of the fragmentation depends on just how high the shown value is from the estimated value.

Extent Switches: This number should be equal to (Extents Scanned - 1). Higher numbers indicate external fragmentation.

Avg. Pages per Extent: This number is the Pages Scanned / Extents Scanned and should be 8. Numbers lower than 8 indicate external fragmentation.

Scan Density [Best Count: Actual Count]: One of the most useful of the percentages returned by DBCC SHOWCONTIG. This is the ratio between the Best Count of extents and the Actual Count of extents. This percentage should be as near to 100% as possible. Lower percentages indicate external fragmentation.

Logical Scan Fragmentation: Shows the ratio of pages that are out of order. This percentage should be between 0% and 10% with anything higher indicating external fragmentation.

Extent Scan Fragmentation: Shows any gaps between extents. This percentage should be 0% and higher percentages indicate external fragmentation.

Avg. Bytes Free per Page: Shows the average number of free bytes in a page. Higher numbers show internal fragmentation but you should take the fill factor into account before you let the higher numbers determine if you have internal fragmentation or not.

Avg. Page Density (full): Shown as a percentage that is the inverse of Avg. Bytes Free per Page. Lower percentages indicate internal fragmentation.


<< Prev Page     Next Page>>    








C# Help and Tutorials | PHP MySQL Tutorial | Sharepoint Tutorial | Azure Tutorial | Cloud Hosting Magazine | ASP.NET Tutorials | Windows Server Help | Windows Phone Pro | Silverlight Ace | Visual Studio Tutorials | Home | Peformance Articles | Audit Articles | Business Intelligence Articles | Clustering Articles | Developer Articles | Reporting Services Articles | DBA Articles | ASP.NET / ADO.NET Articles | SQL Server Training Videos | DBA FAQ's | Developer Peformance FAQ's | DBA Peformance FAQ's | Developer FAQ's | Clustering FAQ's | Error Messages | Audit Tool Reviews | Backup Tool Reviews | Coding Tool Reviews | Compare Tool Reviews | Documentation Tool Reviews | Design Tool Reviews | Monitoring Tool Reviews | Log Tool Reviews | Reporting Tool Reviews | Clustering Tool Reviews | Security Tool Reviews | Change Management Tool Reviews | Remote Access Tool Reviews | Book Reviews | Security Tool Reviews | ADO.NET / ASP.NET | Administration | Analysis/OLAP Services | Application Development | Configuration | Components | ETL | Hardware | High Availability | Hints | Index | Misc | Operating Systems | Performance Tuning | Replication | T-SQL | Views


              © 2010 Jude O'Kelly. All rights reserved