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


Index Seeks, Scans, and Lookups


Index Seeks, Scans, and Lookups

Author
Message
Peter Samson
Peter Samson
SSC Rookie
SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)

Group: General Forum Members
Points: 42 Visits: 46
Comments posted to this topic are about the item Index Seeks, Scans, and Lookups

Peter

http://seattleworks.com including my blog The SQL Janitor
Edward Boyle-478467
Edward Boyle-478467
SSC Veteran
SSC Veteran (238 reputation)SSC Veteran (238 reputation)SSC Veteran (238 reputation)SSC Veteran (238 reputation)SSC Veteran (238 reputation)SSC Veteran (238 reputation)SSC Veteran (238 reputation)SSC Veteran (238 reputation)

Group: General Forum Members
Points: 238 Visits: 1165
I think you may need u.database_id = db_id() in the Where Clause
Rob Maurer
Rob Maurer
SSC-Enthusiastic
SSC-Enthusiastic (112 reputation)SSC-Enthusiastic (112 reputation)SSC-Enthusiastic (112 reputation)SSC-Enthusiastic (112 reputation)SSC-Enthusiastic (112 reputation)SSC-Enthusiastic (112 reputation)SSC-Enthusiastic (112 reputation)SSC-Enthusiastic (112 reputation)

Group: General Forum Members
Points: 112 Visits: 359
Running MSSQL 2000, I get

Server: Msg 208, Level 16, State 1, Line 2
Invalid object name 'sys.dm_db_index_usage_stats'.
Server: Msg 208, Level 16, State 1, Line 2
Invalid object name 'sys.sysobjects'.
Server: Msg 208, Level 16, State 1, Line 2
Invalid object name 'sys.sysindexes'.

henrik staun poulsen
henrik staun poulsen
SSCrazy
SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)

Group: General Forum Members
Points: 2641 Visits: 1226
I think that sp_indexinfo is much better than this query.



JRoughgarden
JRoughgarden
SSC Veteran
SSC Veteran (289 reputation)SSC Veteran (289 reputation)SSC Veteran (289 reputation)SSC Veteran (289 reputation)SSC Veteran (289 reputation)SSC Veteran (289 reputation)SSC Veteran (289 reputation)SSC Veteran (289 reputation)

Group: General Forum Members
Points: 289 Visits: 195
I like this better:

declare @bntTotalRowsScanned bigint
select @bntTotalRowsScanned = sum(i.rowcnt * u.user_scans)
from sys.dm_db_index_usage_stats as u
inner join sys.sysobjects as o on u.object_id = o.id and o.xtype = 'U'
inner join sys.sysindexes as i on u.index_id = i.indid and o.id = i.id
where u.database_id = db_id()
select top 10 o.name as 'Table'
, isnull(i.name, '(Heap, No Indexes)') as 'Index'
, i.rowcnt as 'Est Rows'
, u.user_seeks as 'Seeks'
, u.user_scans as 'Scans'
, u.user_lookups as 'Lookups'
, i.rowcnt * u.user_scans as 'Rows Scanned'
, cast(cast(i.rowcnt * u.user_scans * 100 as float) /cast(@bntTotalRowsScanned as float) as decimal(5,2)) as PctTotal
from sys.dm_db_index_usage_stats as u
inner join sys.sysobjects as o on u.object_id = o.id and o.xtype = 'U'
inner join sys.sysindexes as i on u.index_id = i.indid and o.id = i.id
where u.database_id = db_id()
order by 7 desc



Iwas Bornready
Iwas Bornready
SSC-Insane
SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)

Group: General Forum Members
Points: 22772 Visits: 885
Edward Boyle-478467 (3/1/2010)
I think you may need u.database_id = db_id() in the Where Clause
I tried it both ways and the results were the same, for me anyway.
Iwas Bornready
Iwas Bornready
SSC-Insane
SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)

Group: General Forum Members
Points: 22772 Visits: 885
henrik staun poulsen (11/2/2010)
I think that sp_indexinfo is much better than this query.
I thought the query was good but I'll try your suggestion.
Iwas Bornready
Iwas Bornready
SSC-Insane
SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)

Group: General Forum Members
Points: 22772 Visits: 885
Thanks for the script. It was very helpful.
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