SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


DMV sys.dm_db_index_physical_stats: Detailed vs. Limited


DMV sys.dm_db_index_physical_stats: Detailed vs. Limited

Author
Message
DBAless
DBAless
SSC Eights!
SSC Eights! (820 reputation)SSC Eights! (820 reputation)SSC Eights! (820 reputation)SSC Eights! (820 reputation)SSC Eights! (820 reputation)SSC Eights! (820 reputation)SSC Eights! (820 reputation)SSC Eights! (820 reputation)

Group: General Forum Members
Points: 820 Visits: 92

When I run the following two queries. I get drastically different results. I don't understand why.

select o.name, p.object_id, i.name, p.index_id, p.index_type_desc, p.avg_fragmentation_in_percent, p.fragment_count, p.avg_fragment_size_in_pages, p.page_count
from sys.dm_db_index_physical_stats (7, NULL, NULL, NULL, 'DETAILED') p
JOIN sys.objects AS o ON p.[object_id] = o.[object_id]
JOIN sys.indexes AS i ON o.[object_id] = i.[object_id] AND p.index_id = i.index_id
where avg_fragmentation_in_percent > 0
order by avg_fragmentation_in_percent desc

VS.

select o.name, p.object_id, i.name, p.index_id, p.index_type_desc, p.avg_fragmentation_in_percent, p.fragment_count, p.avg_fragment_size_in_pages, p.page_count
from sys.dm_db_index_physical_stats (7, NULL, NULL, NULL, 'LIMITED') p
JOIN sys.objects AS o ON p.[object_id] = o.[object_id]
JOIN sys.indexes AS i ON o.[object_id] = i.[object_id] AND p.index_id = i.index_id
where avg_fragmentation_in_percent > 0
order by avg_fragmentation_in_percent desc


TheSQLGuru
TheSQLGuru
SSC Guru
SSC Guru (132K reputation)SSC Guru (132K reputation)SSC Guru (132K reputation)SSC Guru (132K reputation)SSC Guru (132K reputation)SSC Guru (132K reputation)SSC Guru (132K reputation)SSC Guru (132K reputation)

Group: General Forum Members
Points: 132585 Visits: 8996
Did you Binoogle that DMV? Did you read Books Online about it??

Best,
Kevin G. Boles
SQL Server Consultant
SQL MVP 2007-2012
TheSQLGuru on googles mail service
Grant Fritchey
Grant Fritchey
SSC Guru
SSC Guru (391K reputation)SSC Guru (391K reputation)SSC Guru (391K reputation)SSC Guru (391K reputation)SSC Guru (391K reputation)SSC Guru (391K reputation)SSC Guru (391K reputation)SSC Guru (391K reputation)

Group: General Forum Members
Points: 391200 Visits: 34705
One scans everything. The other only looks at the root page. Of course the results will be different. Read the documentation for more details.

----------------------------------------------------
The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood...
Theodore Roosevelt

The Scary DBA
Author of: SQL Server 2017 Query Performance Tuning, 5th Edition and SQL Server Execution Plans, 3rd Edition
Product Evangelist for Red Gate Software
DBAless
DBAless
SSC Eights!
SSC Eights! (820 reputation)SSC Eights! (820 reputation)SSC Eights! (820 reputation)SSC Eights! (820 reputation)SSC Eights! (820 reputation)SSC Eights! (820 reputation)SSC Eights! (820 reputation)SSC Eights! (820 reputation)

Group: General Forum Members
Points: 820 Visits: 92
I have read the documentation. But I don't understand it. I am a "involuntary DBA". And I have a hard time following most Microsoft documentation. I tend to look for forum or blog postings that translate it into a "For Dummies" version.

In my research, looking for an explanation I can follow, I came across this from Paul S. Randal, who has some legit credentials for his expertise.

https://www.sqlskills.com/blogs/paul/inside-sys-dm_db_index_physical_stats/

In here he says,
"
The DETAILED mode does two things:
  • Calculate fragmentation by doing a LIMITED mode scan
  • Calculate all other statistics by reading all pages at every level of the index

"
So, then why would the fragmentation calculations be different between LIMITED and DETAILED? If you look at the fields I'm pulling, fragmentation is all I'm looking at.


DBAless
DBAless
SSC Eights!
SSC Eights! (820 reputation)SSC Eights! (820 reputation)SSC Eights! (820 reputation)SSC Eights! (820 reputation)SSC Eights! (820 reputation)SSC Eights! (820 reputation)SSC Eights! (820 reputation)SSC Eights! (820 reputation)

Group: General Forum Members
Points: 820 Visits: 92

Barring an explanation I can follow...

Which should I use for deciding what indexes need reorg/rebuild?

Some sites suggest that Detailed is more accurate, but other sites just say it is different / not necessarily better.


Grant Fritchey
Grant Fritchey
SSC Guru
SSC Guru (391K reputation)SSC Guru (391K reputation)SSC Guru (391K reputation)SSC Guru (391K reputation)SSC Guru (391K reputation)SSC Guru (391K reputation)SSC Guru (391K reputation)SSC Guru (391K reputation)

Group: General Forum Members
Points: 391200 Visits: 34705
Paul is one of the greatest. You'll probably never go wrong reading his stuff and following his advice.

The difference is in the amount of data being accessed. The full scan of all pages gives you a more complete picture, while putting a much higher cost on the server. The limited scan gives you a less complete picture at a much lower cost. More often than not, LIMITED is adequate, if imperfect.

On a side-note, fragmentation is seldom a major issue for people. Usually spending time ensuring more accurate statistics works out better than attempting to eliminate fragmentation.

----------------------------------------------------
The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood...
Theodore Roosevelt

The Scary DBA
Author of: SQL Server 2017 Query Performance Tuning, 5th Edition and SQL Server Execution Plans, 3rd Edition
Product Evangelist for Red Gate Software
DBAless
DBAless
SSC Eights!
SSC Eights! (820 reputation)SSC Eights! (820 reputation)SSC Eights! (820 reputation)SSC Eights! (820 reputation)SSC Eights! (820 reputation)SSC Eights! (820 reputation)SSC Eights! (820 reputation)SSC Eights! (820 reputation)

Group: General Forum Members
Points: 820 Visits: 92

Okay. Thanks for pointing me in that direction. Stats mgmt was right after fragmentation on my "to-learn" list.


Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum









































































































































































SQLServerCentral


Search