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 Journeyman
SSC Journeyman (98 reputation)SSC Journeyman (98 reputation)SSC Journeyman (98 reputation)SSC Journeyman (98 reputation)SSC Journeyman (98 reputation)SSC Journeyman (98 reputation)SSC Journeyman (98 reputation)SSC Journeyman (98 reputation)

Group: General Forum Members
Points: 98 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
Mr or Mrs. 500
Mr or Mrs. 500 (561 reputation)Mr or Mrs. 500 (561 reputation)Mr or Mrs. 500 (561 reputation)Mr or Mrs. 500 (561 reputation)Mr or Mrs. 500 (561 reputation)Mr or Mrs. 500 (561 reputation)Mr or Mrs. 500 (561 reputation)Mr or Mrs. 500 (561 reputation)

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

Group: General Forum Members
Points: 154 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
Hall of Fame
Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)

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



JRoughgarden
JRoughgarden
Say Hey Kid
Say Hey Kid (665 reputation)Say Hey Kid (665 reputation)Say Hey Kid (665 reputation)Say Hey Kid (665 reputation)Say Hey Kid (665 reputation)Say Hey Kid (665 reputation)Say Hey Kid (665 reputation)Say Hey Kid (665 reputation)

Group: General Forum Members
Points: 665 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-Dedicated
SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)

Group: General Forum Members
Points: 38970 Visits: 886
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-Dedicated
SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)

Group: General Forum Members
Points: 38970 Visits: 886
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-Dedicated
SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)

Group: General Forum Members
Points: 38970 Visits: 886
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