<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://sqlblog.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Search results matching tags 'Internals', 'fragmentation', and 'DMVs'</title><link>http://sqlblog.com/search/SearchResults.aspx?o=DateDescending&amp;tag=Internals,fragmentation,DMVs&amp;orTags=0</link><description>Search results matching tags 'Internals', 'fragmentation', and 'DMVs'</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>Geek City: Fragmentation on the System Tables</title><link>http://sqlblog.com/blogs/kalen_delaney/archive/2008/01/17/fragmentation-on-the-system-tables.aspx</link><pubDate>Fri, 18 Jan 2008 01:05:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:4576</guid><dc:creator>Kalen Delaney</dc:creator><description>&lt;P&gt;It's my first post of the new year. I hope it's starting out well for all of you! New year, but sometimes the same old questions. I got another email asking about defragging the system tables. It seems to be in the Hit Parade of FAQs. &lt;/P&gt;
&lt;P&gt;First of all, WHY do you think you would need to defrag a system table? Fragmentation is only a problem when you are performing an in-order scan on a table of more than 100 pages or so, and how often do you do that to a system table that is that big? Rarely, I would assume, but let me know if you have seen an actual need for defragging a system table.&lt;/P&gt;
&lt;P&gt;In SQL Server 2000, you can actually use a system table as a parameter to DBCC SHOWCONTIG to see the fragmentation values. One of my readers reported that he tried running a DBCC INDEXDEFRAG on SQL 2000 system tables and while sometimes it worked, sometimes it corrupted the table! It doesn't sound worth it to me. &lt;/P&gt;
&lt;P&gt;And now, with SQL Server 2005 there is no way to see the fragmentation on the system tables. What about using the new Dynamic Management Object sys.dm_db_index_physical_stats? It requires an object_id as a parameter, and if you select from the metadata view sys.all_objects you can see the object_id for the real system tables, even if you're not using the DAC. Try this:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT face="Courier New" color=#004080&gt;select * from sys.all_objects&lt;BR&gt;where type = 'S'&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You should see all the system tables in your current database, and their object IDs. So you could try passing the id to the management view. Here I'll try it for &lt;EM&gt;syshobts&lt;/EM&gt;, which has an ID of 15:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT color=#000080&gt;&lt;FONT face="Courier New"&gt;select * from &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;FONT face="Courier New"&gt;sys.dm_db_index_physical_stats(1, 15, null, null, 'detailed')&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;No results are returned. If I replace the 15 with null, to indicate I want all objects, I do not see any objects with IDs less than 100, which means there are no system objects reported.&lt;/P&gt;
&lt;P&gt;I did notice one interesting behavior while playing around with this concept. If I use the old DBCC SHOWCONTIG and try to get a report for a system table, this command gives me an error:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT face="courier new" color=#004080&gt;dbcc showcontig ('syshobts')&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new" color=#ff0000&gt;Msg 2501, Level 16, State 45, Line 1&lt;BR&gt;Cannot find a table or object with the name "syshobts". Check the system catalog.&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;However, if I qualify the table name with the schema name, something different happens.&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT face="courier new" color=#004080&gt;dbcc showcontig ('sys.syshobts')&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This time, I don't get an error. I don't get a fragmentation report, but I don't get an error. I just get the message that DBCC execution completed. So it's obvious that there is a difference here. If I then intentionally misspell the object name&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT face="courier new" color=#004080&gt;dbcc showcontig ('sys.syshobbits')&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;now I get the error that SQL Server cannot find the object. So it seems that in SQL Server 2005, DBCC SHOWCONTIG is deliberately filtering out the real system tables, and it was by design to not return fragmentation information. So even if you could run defrag on your system tables, you could never know what impact you had!&lt;/P&gt;
&lt;P&gt;I think there's better ways to spend our time.&lt;/P&gt;
&lt;P&gt;Have fun!&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#ff00ff&gt;~Kalen&lt;/FONT&gt;&lt;/P&gt;</description></item></channel></rss>