<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: SQL SERVER &#8211; Query to Find Duplicate Indexes &#8211; Script to Find Redundant Indexes</title>
	<atom:link href="http://blog.sqlauthority.com/2011/07/13/sql-server-query-to-find-duplicate-indexes-script-to-find-redundant-indexes/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sqlauthority.com/2011/07/13/sql-server-query-to-find-duplicate-indexes-script-to-find-redundant-indexes/</link>
	<description>Personal Notes of Pinal Dave</description>
	<lastBuildDate>Fri, 17 May 2013 15:26:57 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Girijesh Pandey</title>
		<link>http://blog.sqlauthority.com/2011/07/13/sql-server-query-to-find-duplicate-indexes-script-to-find-redundant-indexes/#comment-355210</link>
		<dc:creator><![CDATA[Girijesh Pandey]]></dc:creator>
		<pubDate>Tue, 02 Oct 2012 18:28:55 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=13564#comment-355210</guid>
		<description><![CDATA[Hi Pinal,

Nice explanation!

We Can also get the exact duplicate index using below query.

with indexcols as
(
select object_id as id, index_id as indid, name,
(select case keyno when 0 then NULL else colid end as [data()]
from sys.sysindexkeys as k
where k.id = i.object_id
and k.indid = i.index_id
order by keyno, colid
for xml path(&#039;&#039;)) as cols,
(select case keyno when 0 then colid else NULL end as [data()]
from sys.sysindexkeys as k
where k.id = i.object_id
and k.indid = i.index_id
order by colid
for xml path(&#039;&#039;)) as inc
from sys.indexes as i
)
select
object_schema_name(c1.id) + &#039;.&#039; + object_name(c1.id) as &#039;table&#039;,
c1.name as &#039;index&#039;,
c2.name as &#039;exactduplicate&#039;
from indexcols as c1
join indexcols as c2
on c1.id = c2.id
and c1.indid &lt; c2.indid
and c1.cols = c2.cols
and c1.inc = c2.inc;

-- Script to get Overlapping Indexes
with indexcols as
(
select object_id as id, index_id as indid, name,
(select case keyno when 0 then NULL else colid end as [data()]
from sys.sysindexkeys as k
where k.id = i.object_id
and k.indid = i.index_id
order by keyno, colid
for xml path(&#039;&#039;)) as cols
from sys.indexes as i
)
select
object_schema_name(c1.id) + &#039;.&#039; + object_name(c1.id) as &#039;table&#039;,
c1.name as &#039;index&#039;,
c2.name as &#039;partialduplicate&#039;
from indexcols as c1
join indexcols as c2
on c1.id = c2.id
and c1.indid &lt; c2.indid
and (c1.cols like c2.cols + &#039;%&#039; 
or c2.cols like c1.cols + &#039;%&#039;) ;


Hope, it would be really help you to get exact/Overlapping duplicate indexes in any Database.
Note:- Please double check these scripts on Development server before executing it on Production server.

Feel free to redirect me in case of any query/questions.

Regards,
Girijesh]]></description>
		<content:encoded><![CDATA[<p>Hi Pinal,</p>
<p>Nice explanation!</p>
<p>We Can also get the exact duplicate index using below query.</p>
<p>with indexcols as<br />
(<br />
select object_id as id, index_id as indid, name,<br />
(select case keyno when 0 then NULL else colid end as [data()]<br />
from sys.sysindexkeys as k<br />
where k.id = i.object_id<br />
and k.indid = i.index_id<br />
order by keyno, colid<br />
for xml path(&#8221;)) as cols,<br />
(select case keyno when 0 then colid else NULL end as [data()]<br />
from sys.sysindexkeys as k<br />
where k.id = i.object_id<br />
and k.indid = i.index_id<br />
order by colid<br />
for xml path(&#8221;)) as inc<br />
from sys.indexes as i<br />
)<br />
select<br />
object_schema_name(c1.id) + &#8216;.&#8217; + object_name(c1.id) as &#8216;table&#8217;,<br />
c1.name as &#8216;index&#8217;,<br />
c2.name as &#8216;exactduplicate&#8217;<br />
from indexcols as c1<br />
join indexcols as c2<br />
on c1.id = c2.id<br />
and c1.indid &lt; c2.indid<br />
and c1.cols = c2.cols<br />
and c1.inc = c2.inc;</p>
<p>&#8211; Script to get Overlapping Indexes<br />
with indexcols as<br />
(<br />
select object_id as id, index_id as indid, name,<br />
(select case keyno when 0 then NULL else colid end as [data()]<br />
from sys.sysindexkeys as k<br />
where k.id = i.object_id<br />
and k.indid = i.index_id<br />
order by keyno, colid<br />
for xml path(&#039;&#039;)) as cols<br />
from sys.indexes as i<br />
)<br />
select<br />
object_schema_name(c1.id) + &#039;.&#039; + object_name(c1.id) as &#039;table&#039;,<br />
c1.name as &#039;index&#039;,<br />
c2.name as &#039;partialduplicate&#039;<br />
from indexcols as c1<br />
join indexcols as c2<br />
on c1.id = c2.id<br />
and c1.indid &lt; c2.indid<br />
and (c1.cols like c2.cols + &#039;%&#039;<br />
or c2.cols like c1.cols + &#039;%&#039;) ;</p>
<p>Hope, it would be really help you to get exact/Overlapping duplicate indexes in any Database.<br />
Note:- Please double check these scripts on Development server before executing it on Production server.</p>
<p>Feel free to redirect me in case of any query/questions.</p>
<p>Regards,<br />
Girijesh</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jason</title>
		<link>http://blog.sqlauthority.com/2011/07/13/sql-server-query-to-find-duplicate-indexes-script-to-find-redundant-indexes/#comment-162518</link>
		<dc:creator><![CDATA[Jason]]></dc:creator>
		<pubDate>Sat, 27 Aug 2011 05:49:27 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=13564#comment-162518</guid>
		<description><![CDATA[Thanks for posting. I hadn&#039;t really thought to check for duplicate/overlapping indexes before. Was interesting to look into on our dbs.

Jason]]></description>
		<content:encoded><![CDATA[<p>Thanks for posting. I hadn&#8217;t really thought to check for duplicate/overlapping indexes before. Was interesting to look into on our dbs.</p>
<p>Jason</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Ames</title>
		<link>http://blog.sqlauthority.com/2011/07/13/sql-server-query-to-find-duplicate-indexes-script-to-find-redundant-indexes/#comment-149224</link>
		<dc:creator><![CDATA[David Ames]]></dc:creator>
		<pubDate>Tue, 19 Jul 2011 00:41:57 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=13564#comment-149224</guid>
		<description><![CDATA[Pinal,

Kim Tripp has expended on index duplicate searching &amp; given her own script at:  http://sqlskills.com/BLOGS/KIMBERLY/post/UnderstandingDuplicateIndexes.aspx and http://sqlskills.com/BLOGS/KIMBERLY/post/RemovingDuplicateIndexes.aspx

Dave]]></description>
		<content:encoded><![CDATA[<p>Pinal,</p>
<p>Kim Tripp has expended on index duplicate searching &amp; given her own script at:  <a href="http://sqlskills.com/BLOGS/KIMBERLY/post/UnderstandingDuplicateIndexes.aspx" rel="nofollow">http://sqlskills.com/BLOGS/KIMBERLY/post/UnderstandingDuplicateIndexes.aspx</a> and <a href="http://sqlskills.com/BLOGS/KIMBERLY/post/RemovingDuplicateIndexes.aspx" rel="nofollow">http://sqlskills.com/BLOGS/KIMBERLY/post/RemovingDuplicateIndexes.aspx</a></p>
<p>Dave</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ukc</title>
		<link>http://blog.sqlauthority.com/2011/07/13/sql-server-query-to-find-duplicate-indexes-script-to-find-redundant-indexes/#comment-149112</link>
		<dc:creator><![CDATA[ukc]]></dc:creator>
		<pubDate>Mon, 18 Jul 2011 10:12:33 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=13564#comment-149112</guid>
		<description><![CDATA[Hi Pinal,

Nice article. I tried to run this on my DEV instance and found this interesting thing. I am having same named table with same named primary key column in different Schema. This script display indexes on these columns as duplicates. I believe its not correct.

Please share you thoughts

Results:
SchemaName	&#124; TableName	&#124; IndexName	&#124; OverLappingIndex	&#124; Col1
=========================================================
E2S			&#124; queue		&#124; PK_queue	&#124; PK_email		&#124; Id
Email		&#124; Queue		&#124; PK_email	&#124; PK_queue		&#124; Id]]></description>
		<content:encoded><![CDATA[<p>Hi Pinal,</p>
<p>Nice article. I tried to run this on my DEV instance and found this interesting thing. I am having same named table with same named primary key column in different Schema. This script display indexes on these columns as duplicates. I believe its not correct.</p>
<p>Please share you thoughts</p>
<p>Results:<br />
SchemaName	| TableName	| IndexName	| OverLappingIndex	| Col1<br />
=========================================================<br />
E2S			| queue		| PK_queue	| PK_email		| Id<br />
Email		| Queue		| PK_email	| PK_queue		| Id</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul Randal</title>
		<link>http://blog.sqlauthority.com/2011/07/13/sql-server-query-to-find-duplicate-indexes-script-to-find-redundant-indexes/#comment-148842</link>
		<dc:creator><![CDATA[Paul Randal]]></dc:creator>
		<pubDate>Sun, 17 Jul 2011 02:28:25 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=13564#comment-148842</guid>
		<description><![CDATA[@Dave Most likely, if colC is not very wide.]]></description>
		<content:encoded><![CDATA[<p>@Dave Most likely, if colC is not very wide.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Ames</title>
		<link>http://blog.sqlauthority.com/2011/07/13/sql-server-query-to-find-duplicate-indexes-script-to-find-redundant-indexes/#comment-148045</link>
		<dc:creator><![CDATA[David Ames]]></dc:creator>
		<pubDate>Wed, 13 Jul 2011 17:29:46 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=13564#comment-148045</guid>
		<description><![CDATA[Paul,

I&#039;m interested in more information on this comment: &quot;Left-based subsets the same doesn’t mean you can drop the wider one &quot;. Using the example of two indexes (colA,colB,colC) and (colA,colB), assuming that everything else in the index is equal (includes, filters, etc) and that ColC is not very wide.

Can we say the index 2 is redundant because index 1 includes the same cols as index 2?

I&#039;d like to know your &#039;rule-of-thumb&#039; approach to this scenario as it&#039;s fairly common.

Thanks,
Dave]]></description>
		<content:encoded><![CDATA[<p>Paul,</p>
<p>I&#8217;m interested in more information on this comment: &#8220;Left-based subsets the same doesn’t mean you can drop the wider one &#8220;. Using the example of two indexes (colA,colB,colC) and (colA,colB), assuming that everything else in the index is equal (includes, filters, etc) and that ColC is not very wide.</p>
<p>Can we say the index 2 is redundant because index 1 includes the same cols as index 2?</p>
<p>I&#8217;d like to know your &#8216;rule-of-thumb&#8217; approach to this scenario as it&#8217;s fairly common.</p>
<p>Thanks,<br />
Dave</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Darth Sonic</title>
		<link>http://blog.sqlauthority.com/2011/07/13/sql-server-query-to-find-duplicate-indexes-script-to-find-redundant-indexes/#comment-147923</link>
		<dc:creator><![CDATA[Darth Sonic]]></dc:creator>
		<pubDate>Wed, 13 Jul 2011 07:24:24 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=13564#comment-147923</guid>
		<description><![CDATA[Clustered and Non-Clustered indexes are not seperated by this script, also PrimaryKeys and other unique indexes could have same overlapping columns. And included columns are not considered as well.]]></description>
		<content:encoded><![CDATA[<p>Clustered and Non-Clustered indexes are not seperated by this script, also PrimaryKeys and other unique indexes could have same overlapping columns. And included columns are not considered as well.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pinaldave</title>
		<link>http://blog.sqlauthority.com/2011/07/13/sql-server-query-to-find-duplicate-indexes-script-to-find-redundant-indexes/#comment-147858</link>
		<dc:creator><![CDATA[pinaldave]]></dc:creator>
		<pubDate>Wed, 13 Jul 2011 03:33:49 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=13564#comment-147858</guid>
		<description><![CDATA[Yes Sir,

I totally agree. Collecting input to modify this query to reflect the all the suggestions. Your suggestion is very valid and based your your suggestion I will further update the same.]]></description>
		<content:encoded><![CDATA[<p>Yes Sir,</p>
<p>I totally agree. Collecting input to modify this query to reflect the all the suggestions. Your suggestion is very valid and based your your suggestion I will further update the same.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul Randal</title>
		<link>http://blog.sqlauthority.com/2011/07/13/sql-server-query-to-find-duplicate-indexes-script-to-find-redundant-indexes/#comment-147850</link>
		<dc:creator><![CDATA[Paul Randal]]></dc:creator>
		<pubDate>Wed, 13 Jul 2011 02:30:28 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=13564#comment-147850</guid>
		<description><![CDATA[Hey Pinal - You don&#039;t consider INCLUDEd columns, ASC/DESC, or nonclustered indexes that have the same keys as clustereds but are far narrower. Dangerous query to have people run. Left-based subsets the same doesn&#039;t mean you can drop the wider one - they may satisfy vastly different queries and dropping the narrow one could seriously affect performance.]]></description>
		<content:encoded><![CDATA[<p>Hey Pinal &#8211; You don&#8217;t consider INCLUDEd columns, ASC/DESC, or nonclustered indexes that have the same keys as clustereds but are far narrower. Dangerous query to have people run. Left-based subsets the same doesn&#8217;t mean you can drop the wider one &#8211; they may satisfy vastly different queries and dropping the narrow one could seriously affect performance.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
