<?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/"
	
	>
<channel>
	<title>
	Comments on: SQL Server: Script to find Redundant and Duplicate Indexes	</title>
	<atom:link href="https://www.dbrnd.com/2016/11/sql-server-script-to-find-redundant-and-duplicate-indexes/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.dbrnd.com/2016/11/sql-server-script-to-find-redundant-and-duplicate-indexes/</link>
	<description>BIGData &#124; NoSQL &#124; MSSQL &#124; MySQL &#124; PostgreSQL</description>
	<lastBuildDate>Wed, 10 Oct 2018 18:44:49 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.6</generator>
	<item>
		<title>
		By: Laura Lefebvre		</title>
		<link>https://www.dbrnd.com/2016/11/sql-server-script-to-find-redundant-and-duplicate-indexes/#comment-6753</link>

		<dc:creator><![CDATA[Laura Lefebvre]]></dc:creator>
		<pubDate>Wed, 10 Oct 2018 18:44:49 +0000</pubDate>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=2586#comment-6753</guid>

					<description><![CDATA[There is an error in your query.  In SQL Server, the &#039;sys.index_columns.key_ordinal&#039; is the column which indicates the order of the columns within the index.  In your query, I am assuming that this clause:

AND ic.index_column_id = 1

was meant to only look at columns which are first in the index.   This should actually be:

AND ic.key_ordinal = 1

So the resulting query is this:

SELECT
	s.Name + &#039;.&#039; + t.Name AS TableName	
	,i.name AS IndexName1	
	,DupliIDX.name AS DuplicateIndexName
	,c.name AS ColumnName
FROM sys.tables AS t 
JOIN sys.indexes AS i
	ON t.object_id = i.object_id -- index belongs to this table
JOIN sys.index_columns ic 
	ON ic.object_id = i.object_id -- columns for this index
		AND ic.index_id = i.index_id -- index to which column belongs
		AND ic.key_ordinal = 1 -- only want the first column in the index
JOIN sys.columns AS c 
	ON c.object_id = ic.object_id 
		AND c.column_id = ic.column_id  -- to get the name of the first indexed column
JOIN sys.schemas AS s 
	ON t.schema_id = s.schema_id
CROSS APPLY
(
	SELECT 
	   ind.index_id
	   ,ind.name
	FROM sys.indexes AS ind 
	JOIN sys.index_columns AS ico 
	   ON ico.object_id = ind.object_id
	   AND ico.index_id = ind.index_id
	   AND ico.key_ordinal = 1
	WHERE ind.object_id = i.object_id 
	   AND ind.index_id &#062; i.index_id -- exclude the clustered index (which is the PK usually)
	   AND ico.column_id = ic.column_id
) DupliIDX    
ORDER BY
    s.name,t.name,i.index_id,c.column_id
GO]]></description>
			<content:encoded><![CDATA[<p>There is an error in your query.  In SQL Server, the &#8216;sys.index_columns.key_ordinal&#8217; is the column which indicates the order of the columns within the index.  In your query, I am assuming that this clause:</p>
<p>AND ic.index_column_id = 1</p>
<p>was meant to only look at columns which are first in the index.   This should actually be:</p>
<p>AND ic.key_ordinal = 1</p>
<p>So the resulting query is this:</p>
<p>SELECT<br />
	s.Name + &#8216;.&#8217; + t.Name AS TableName<br />
	,i.name AS IndexName1<br />
	,DupliIDX.name AS DuplicateIndexName<br />
	,c.name AS ColumnName<br />
FROM sys.tables AS t<br />
JOIN sys.indexes AS i<br />
	ON t.object_id = i.object_id &#8212; index belongs to this table<br />
JOIN sys.index_columns ic<br />
	ON ic.object_id = i.object_id &#8212; columns for this index<br />
		AND ic.index_id = i.index_id &#8212; index to which column belongs<br />
		AND ic.key_ordinal = 1 &#8212; only want the first column in the index<br />
JOIN sys.columns AS c<br />
	ON c.object_id = ic.object_id<br />
		AND c.column_id = ic.column_id  &#8212; to get the name of the first indexed column<br />
JOIN sys.schemas AS s<br />
	ON t.schema_id = s.schema_id<br />
CROSS APPLY<br />
(<br />
	SELECT<br />
	   ind.index_id<br />
	   ,ind.name<br />
	FROM sys.indexes AS ind<br />
	JOIN sys.index_columns AS ico<br />
	   ON ico.object_id = ind.object_id<br />
	   AND ico.index_id = ind.index_id<br />
	   AND ico.key_ordinal = 1<br />
	WHERE ind.object_id = i.object_id<br />
	   AND ind.index_id &gt; i.index_id &#8212; exclude the clustered index (which is the PK usually)<br />
	   AND ico.column_id = ic.column_id<br />
) DupliIDX<br />
ORDER BY<br />
    s.name,t.name,i.index_id,c.column_id<br />
GO</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Anvesh Patel		</title>
		<link>https://www.dbrnd.com/2016/11/sql-server-script-to-find-redundant-and-duplicate-indexes/#comment-6273</link>

		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Mon, 05 Mar 2018 18:00:40 +0000</pubDate>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=2586#comment-6273</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.dbrnd.com/2016/11/sql-server-script-to-find-redundant-and-duplicate-indexes/#comment-6270&quot;&gt;Debiprasad Panda&lt;/a&gt;.

First, we should check the execution plan of the query and then remove the same column from multiple indexes or similar indexes.]]></description>
			<content:encoded><![CDATA[<p>First, we should check the execution plan of the query and then remove the same column from multiple indexes or similar indexes.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Debiprasad Panda		</title>
		<link>https://www.dbrnd.com/2016/11/sql-server-script-to-find-redundant-and-duplicate-indexes/#comment-6270</link>

		<dc:creator><![CDATA[Debiprasad Panda]]></dc:creator>
		<pubDate>Mon, 05 Mar 2018 11:55:54 +0000</pubDate>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=2586#comment-6270</guid>

					<description><![CDATA[HI Anvesh,

Nice article to start with finding out duplicate indexes.
But after reading this article , there were some questions popped up in my mind.

IndexA(Column1,Column2)
IndexB(Column1,Column2,Column3,Column4,Column5)
IndexC(Column2,Column3)
IndexD(Column1,Column3)
IndexE(Column1,Column4)

After completing this article , i am thinking that the duplicate indexe is IndexA.
But in your example , you have mentioned that IndexD ,IndexE along with IndexA are redundant.

Please reply.

Thanks in Advance.]]></description>
			<content:encoded><![CDATA[<p>HI Anvesh,</p>
<p>Nice article to start with finding out duplicate indexes.<br />
But after reading this article , there were some questions popped up in my mind.</p>
<p>IndexA(Column1,Column2)<br />
IndexB(Column1,Column2,Column3,Column4,Column5)<br />
IndexC(Column2,Column3)<br />
IndexD(Column1,Column3)<br />
IndexE(Column1,Column4)</p>
<p>After completing this article , i am thinking that the duplicate indexe is IndexA.<br />
But in your example , you have mentioned that IndexD ,IndexE along with IndexA are redundant.</p>
<p>Please reply.</p>
<p>Thanks in Advance.</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
