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


All INDEX details query - gives duplicate entires


All INDEX details query - gives duplicate entires

Author
Message
sqlwars
sqlwars
Valued Member
Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)

Group: General Forum Members
Points: 50 Visits: 67
HI,

I mixed and matched many queries tto give all details of index needed for analysis. Howeever, the query returns duplicate values. how do i remove the duplicate entries. PLEASE HELP. Here is the query:

-- ALL Indexes Details

SELECT
[Total Cost] = ROUND(avg_total_user_cost * avg_user_impact * (s.user_seeks + s.user_scans),0)
,avg_user_impact , TableName = statement ,[name] ,i.type_desc
,[index_size_in_MB] = (sum(a.total_pages) * 8) / 1024.00 -- Pages are 8 Bytes in size
,[records_in_index]= sum(CASE WHEN a.type = 1 THEN p.rows ELSE 0 END) -- Only count the rows once
,u.user_seeks,u.user_scans,u.user_lookups,u.user_updates
,[EqualityUsage] = equality_columns, [InequalityUsage] = inequality_columns
,[Include Cloumns] = included_columns

FROM sys.dm_db_missing_index_groups g
INNER JOIN sys.dm_db_missing_index_group_stats s ON s.group_handle = g.index_group_handle
INNER JOIN sys.dm_db_missing_index_details d ON d.index_handle = g.index_handle
INNER JOIN sys.indexes i ON d.[object_id] = i.[object_id]
INNER JOIN sys.dm_db_index_usage_stats u ON d.[object_id] = u.[object_id]
INNER JOIN sys.partitions p ON i.[object_id] = p.[object_id]
INNER JOIN sys.allocation_units a ON p.partition_id = a.container_id

GROUP BY
g.index_group_handle, g.index_handle
,s.avg_total_user_cost,s.avg_user_impact,s.user_seeks,s.user_scans
,u.user_lookups,u.user_updates,u.user_seeks,u.user_scans
,i.type_desc,i.name,d.statement,d.equality_columns,d.inequality_columns,d.included_columns;

-- ALL Indexes Details
Dave Ballantyne
Dave Ballantyne
SSCertifiable
SSCertifiable (7.1K reputation)SSCertifiable (7.1K reputation)SSCertifiable (7.1K reputation)SSCertifiable (7.1K reputation)SSCertifiable (7.1K reputation)SSCertifiable (7.1K reputation)SSCertifiable (7.1K reputation)SSCertifiable (7.1K reputation)

Group: General Forum Members
Points: 7132 Visits: 8370
Possibly the simplest way is to use DISTINCT.



Clear Sky SQL
My Blog
sqlwars
sqlwars
Valued Member
Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)

Group: General Forum Members
Points: 50 Visits: 67
distinct didnt work, same number of results. Each Index is being repeated 6 times.

The only columns where the value changes are:
--sys.partitions (partition id,hobt_id)
--sys.allocation_units (allocation_unit_id,container_id,total_pages,used_pages,data_pages)
--computed column - index size (which uses the above columes to compute data)

Any help please to avoid the duplicates?
Bhuvnesh
Bhuvnesh
SSChampion
SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)

Group: General Forum Members
Points: 13200 Visits: 4077
Are you sure that u are getting duplicate data ? in my system i am getting same records with or without DISTINCT

-------Bhuvnesh----------
I work only to learn Sql Server...though my company pays me for getting their stuff done;-)
jeffem
jeffem
Mr or Mrs. 500
Mr or Mrs. 500 (524 reputation)Mr or Mrs. 500 (524 reputation)Mr or Mrs. 500 (524 reputation)Mr or Mrs. 500 (524 reputation)Mr or Mrs. 500 (524 reputation)Mr or Mrs. 500 (524 reputation)Mr or Mrs. 500 (524 reputation)Mr or Mrs. 500 (524 reputation)

Group: General Forum Members
Points: 524 Visits: 346
There are columns with different data, in my results:

user_seeks, user_scans, user_lookups, and user_updates

If you don't want the values you listed to repeat, you need to either exclude the above columns or group by the columns you don't want to repeat and use an aggregate function (MAX(), MIN(), etc.) of the others.
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