<?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: Duplicate indexes and redundant indexes</title>
	<atom:link href="http://www.mysqlperformanceblog.com/2006/08/17/duplicate-indexes-and-redundant-indexes/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mysqlperformanceblog.com/2006/08/17/duplicate-indexes-and-redundant-indexes/</link>
	<description>Percona&#039;s MySQL &#38; InnoDB performance and scalability blog</description>
	<lastBuildDate>Sat, 11 Feb 2012 16:45:54 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: amit shah</title>
		<link>http://www.mysqlperformanceblog.com/2006/08/17/duplicate-indexes-and-redundant-indexes/comment-page-1/#comment-878281</link>
		<dc:creator>amit shah</dc:creator>
		<pubDate>Fri, 20 Jan 2012 05:55:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/08/17/duplicate-indexes-and-redundant-indexes/#comment-878281</guid>
		<description>Hi, 

Please help me to know how to drop duplicate index with same name. 
=== Error === 
alter table emp drop index fk_deptid;ERROR 1553 (HY000): Cannot drop index &#039;fk_deptid&#039;: needed in a foreign key constraint 
============= 

Below is scenario. 


drop table if exists emp; 
drop table if exists dept; 
create table dept 
( 
deptid integer auto_increment primary key, 
deptname varchar(20) 
); 

create table emp 
( 
empid integer auto_increment primary key, 
empname varchar(20), 
deptid integer, 
key fk_deptid (deptid), 
constraint fk_deptid foreign key(deptid) references dept(deptid) 
); 

* Find below output which shows indexes in the database. (Query for below output is at the end) 

mysql&gt; source list.sql 
+--------------+------------+-----------------+-----------------+-------------+-----------------------+------------------------+ 
&#124; table_schema &#124; table_name &#124; constraint_name &#124; constraint_type &#124; column_list &#124; referenced_table_name &#124; referenced_column_name &#124; 
+--------------+------------+-----------------+-----------------+-------------+-----------------------+------------------------+ 
&#124; test &#124; dept &#124; PRIMARY &#124; PRIMARY KEY &#124; deptid &#124; NULL &#124; NULL &#124; 
&#124; test &#124; emp &#124; fk_deptid &#124; NON UNIQUE &#124; deptid &#124; NULL &#124; NULL &#124; 
&#124; test &#124; emp &#124; fk_deptid &#124; FOREIGN KEY &#124; deptid &#124; dept &#124; deptid &#124; 
&#124; test &#124; emp &#124; PRIMARY &#124; PRIMARY KEY &#124; empid &#124; NULL &#124; NULL &#124; 
+--------------+------------+-----------------+-----------------+-------------+-----------------------+------------------------+ 


alter table emp drop index fk_deptid;ERROR 1553 (HY000): Cannot drop index &#039;fk_deptid&#039;: needed in a foreign key constraint 

+++Query++++ 
SELECT a.table_schema, a.table_name, a.constraint_name, 
a.constraint_type, 
convert(group_concat(DISTINCT b.column_name 
ORDER BY b.ordinal_position SEPARATOR &#039;, &#039;), char) 
as column_list, 
b.referenced_table_name, b.referenced_column_name 
FROM information_schema.table_constraints a 
INNER JOIN information_schema.key_column_usage b 
ON a.constraint_name = b.constraint_name AND 
a.table_schema = b.table_schema AND 
a.table_name = b.table_name 
WHERE a.table_schema=&#039;test&#039; 
GROUP BY a.table_schema, a.table_name, a.constraint_name, 
a.constraint_type, b.referenced_table_name, 
b.referenced_column_name 
UNION 
SELECT table_schema, table_name, index_name as constraint_name, 
if(index_type=&#039;FULLTEXT&#039;, &#039;FULLTEXT&#039;, &#039;NON UNIQUE&#039;) 
as constraint_type, 
convert(group_concat(column_name 
ORDER BY seq_in_index separator &#039;, &#039;), char) as column_list, 
null as referenced_table_name, null as referenced_column_name 
FROM information_schema.statistics 
WHERE non_unique = 1 
AND table_schema=&#039;test&#039; 
GROUP BY table_schema, table_name, constraint_name, constraint_type, 
referenced_table_name, referenced_column_name 
ORDER BY table_schema, table_name, column_list 

Thanks in advance. 

Regards, 
Amit.</description>
		<content:encoded><![CDATA[<p>Hi, </p>
<p>Please help me to know how to drop duplicate index with same name.<br />
=== Error ===<br />
alter table emp drop index fk_deptid;ERROR 1553 (HY000): Cannot drop index &#8216;fk_deptid&#8217;: needed in a foreign key constraint<br />
============= </p>
<p>Below is scenario. </p>
<p>drop table if exists emp;<br />
drop table if exists dept;<br />
create table dept<br />
(<br />
deptid integer auto_increment primary key,<br />
deptname varchar(20)<br />
); </p>
<p>create table emp<br />
(<br />
empid integer auto_increment primary key,<br />
empname varchar(20),<br />
deptid integer,<br />
key fk_deptid (deptid),<br />
constraint fk_deptid foreign key(deptid) references dept(deptid)<br />
); </p>
<p>* Find below output which shows indexes in the database. (Query for below output is at the end) </p>
<p>mysql&gt; source list.sql<br />
+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<br />
| table_schema | table_name | constraint_name | constraint_type | column_list | referenced_table_name | referenced_column_name |<br />
+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<br />
| test | dept | PRIMARY | PRIMARY KEY | deptid | NULL | NULL |<br />
| test | emp | fk_deptid | NON UNIQUE | deptid | NULL | NULL |<br />
| test | emp | fk_deptid | FOREIGN KEY | deptid | dept | deptid |<br />
| test | emp | PRIMARY | PRIMARY KEY | empid | NULL | NULL |<br />
+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+ </p>
<p>alter table emp drop index fk_deptid;ERROR 1553 (HY000): Cannot drop index &#8216;fk_deptid&#8217;: needed in a foreign key constraint </p>
<p>+++Query++++<br />
SELECT a.table_schema, a.table_name, a.constraint_name,<br />
a.constraint_type,<br />
convert(group_concat(DISTINCT b.column_name<br />
ORDER BY b.ordinal_position SEPARATOR &#8216;, &#8216;), char)<br />
as column_list,<br />
b.referenced_table_name, b.referenced_column_name<br />
FROM information_schema.table_constraints a<br />
INNER JOIN information_schema.key_column_usage b<br />
ON a.constraint_name = b.constraint_name AND<br />
a.table_schema = b.table_schema AND<br />
a.table_name = b.table_name<br />
WHERE a.table_schema=&#8217;test&#8217;<br />
GROUP BY a.table_schema, a.table_name, a.constraint_name,<br />
a.constraint_type, b.referenced_table_name,<br />
b.referenced_column_name<br />
UNION<br />
SELECT table_schema, table_name, index_name as constraint_name,<br />
if(index_type=&#8217;FULLTEXT&#8217;, &#8216;FULLTEXT&#8217;, &#8216;NON UNIQUE&#8217;)<br />
as constraint_type,<br />
convert(group_concat(column_name<br />
ORDER BY seq_in_index separator &#8216;, &#8216;), char) as column_list,<br />
null as referenced_table_name, null as referenced_column_name<br />
FROM information_schema.statistics<br />
WHERE non_unique = 1<br />
AND table_schema=&#8217;test&#8217;<br />
GROUP BY table_schema, table_name, constraint_name, constraint_type,<br />
referenced_table_name, referenced_column_name<br />
ORDER BY table_schema, table_name, column_list </p>
<p>Thanks in advance. </p>
<p>Regards,<br />
Amit.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Will</title>
		<link>http://www.mysqlperformanceblog.com/2006/08/17/duplicate-indexes-and-redundant-indexes/comment-page-1/#comment-777126</link>
		<dc:creator>Will</dc:creator>
		<pubDate>Thu, 07 Oct 2010 22:07:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/08/17/duplicate-indexes-and-redundant-indexes/#comment-777126</guid>
		<description>Will this setup allow the query below to properly use both indexes? Does the order of where clauses matter in such a scenario?

index alpha (B,C)
index beta (A)

select A, B from x where A = x and B = x</description>
		<content:encoded><![CDATA[<p>Will this setup allow the query below to properly use both indexes? Does the order of where clauses matter in such a scenario?</p>
<p>index alpha (B,C)<br />
index beta (A)</p>
<p>select A, B from x where A = x and B = x</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aaron Schmidt</title>
		<link>http://www.mysqlperformanceblog.com/2006/08/17/duplicate-indexes-and-redundant-indexes/comment-page-1/#comment-527740</link>
		<dc:creator>Aaron Schmidt</dc:creator>
		<pubDate>Thu, 02 Apr 2009 09:13:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/08/17/duplicate-indexes-and-redundant-indexes/#comment-527740</guid>
		<description>&quot;Order of columns in index is significant, index (A,B) is not duplicate to index (B,A)&quot;

Let&#039;s say my Primary Key is: PRIMARY KEY(A,B)

I also need a standard BTREE index on B: KEY(B)

Now, would it be in my interest to change PRIMARY KEY(A,B) to PRIMARY KEY(B,A) and thus get the covering index on B and have no need for the additional KEY(B) ?

Thanks for your help and all the great information on this site.</description>
		<content:encoded><![CDATA[<p>&#8220;Order of columns in index is significant, index (A,B) is not duplicate to index (B,A)&#8221;</p>
<p>Let&#8217;s say my Primary Key is: PRIMARY KEY(A,B)</p>
<p>I also need a standard BTREE index on B: KEY(B)</p>
<p>Now, would it be in my interest to change PRIMARY KEY(A,B) to PRIMARY KEY(B,A) and thus get the covering index on B and have no need for the additional KEY(B) ?</p>
<p>Thanks for your help and all the great information on this site.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Finding out largest tables on MySQL Server &#171; Purab&#8217;s Blog</title>
		<link>http://www.mysqlperformanceblog.com/2006/08/17/duplicate-indexes-and-redundant-indexes/comment-page-1/#comment-344251</link>
		<dc:creator>Finding out largest tables on MySQL Server &#171; Purab&#8217;s Blog</dc:creator>
		<pubDate>Wed, 13 Aug 2008 07:25:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/08/17/duplicate-indexes-and-redundant-indexes/#comment-344251</guid>
		<description>[...] to data size often indicates there is a lot of indexes (so it is well possible there are some duplicates, redundant or simply unused indexes among them) or may be there is long primary key with Innodb tables. Of [...]</description>
		<content:encoded><![CDATA[<p>[...] to data size often indicates there is a lot of indexes (so it is well possible there are some duplicates, redundant or simply unused indexes among them) or may be there is long primary key with Innodb tables. Of [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: How to find duplicate and redundant indexes in MySQL at Xaprb</title>
		<link>http://www.mysqlperformanceblog.com/2006/08/17/duplicate-indexes-and-redundant-indexes/comment-page-1/#comment-338520</link>
		<dc:creator>How to find duplicate and redundant indexes in MySQL at Xaprb</dc:creator>
		<pubDate>Fri, 01 Aug 2008 12:39:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/08/17/duplicate-indexes-and-redundant-indexes/#comment-338520</guid>
		<description>[...] Zaitsev over at the excellent MySQL Performance Blog recently wrote an article on duplicated and redundant indexes &#8212; any indexes which cover exactly the same columns as another index, or cover a leftmost [...]</description>
		<content:encoded><![CDATA[<p>[...] Zaitsev over at the excellent MySQL Performance Blog recently wrote an article on duplicated and redundant indexes &#8212; any indexes which cover exactly the same columns as another index, or cover a leftmost [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peter</title>
		<link>http://www.mysqlperformanceblog.com/2006/08/17/duplicate-indexes-and-redundant-indexes/comment-page-1/#comment-260643</link>
		<dc:creator>peter</dc:creator>
		<pubDate>Mon, 31 Mar 2008 18:49:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/08/17/duplicate-indexes-and-redundant-indexes/#comment-260643</guid>
		<description>Vaibogam,

This will catch indexes (A,B) and (A,C) as duplicate would not it ? 
It would be simple if indexes would be single column only :)</description>
		<content:encoded><![CDATA[<p>Vaibogam,</p>
<p>This will catch indexes (A,B) and (A,C) as duplicate would not it ?<br />
It would be simple if indexes would be single column only <img src='http://www.mysqlperformanceblog.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vaibogam S</title>
		<link>http://www.mysqlperformanceblog.com/2006/08/17/duplicate-indexes-and-redundant-indexes/comment-page-1/#comment-260480</link>
		<dc:creator>Vaibogam S</dc:creator>
		<pubDate>Mon, 31 Mar 2008 15:40:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/08/17/duplicate-indexes-and-redundant-indexes/#comment-260480</guid>
		<description>A simple way to find out duplicate indexes in 5.0.x

SELECT * FROM information_schema.statistics WHERE table_schema = â€˜?â€™ GROUP BY table_schema, table_name, column_name HAVING count(column_name) &gt; 1;

It would be better to include &#039;index_type&#039; in GROUP BY clause to more accurate answer.

In the above query bind the â€˜database nameâ€™ parameter.

-Bog</description>
		<content:encoded><![CDATA[<p>A simple way to find out duplicate indexes in 5.0.x</p>
<p>SELECT * FROM information_schema.statistics WHERE table_schema = â€˜?â€™ GROUP BY table_schema, table_name, column_name HAVING count(column_name) &gt; 1;</p>
<p>It would be better to include &#8216;index_type&#8217; in GROUP BY clause to more accurate answer.</p>
<p>In the above query bind the â€˜database nameâ€™ parameter.</p>
<p>-Bog</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hitta indexdubletter</title>
		<link>http://www.mysqlperformanceblog.com/2006/08/17/duplicate-indexes-and-redundant-indexes/comment-page-1/#comment-242037</link>
		<dc:creator>Hitta indexdubletter</dc:creator>
		<pubDate>Wed, 13 Feb 2008 07:45:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/08/17/duplicate-indexes-and-redundant-indexes/#comment-242037</guid>
		<description>[...] lÃ¤ste en artikel pÃ¥ mysqlpeformanceblog om redundanta index. Eftersom jag inte vill skriva om den artikeln sÃ¥ hoppar jag direkt till [...]</description>
		<content:encoded><![CDATA[<p>[...] lÃ¤ste en artikel pÃ¥ mysqlpeformanceblog om redundanta index. Eftersom jag inte vill skriva om den artikeln sÃ¥ hoppar jag direkt till [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Finding out largest tables on MySQL Server &#124; MySQL Performance Blog</title>
		<link>http://www.mysqlperformanceblog.com/2006/08/17/duplicate-indexes-and-redundant-indexes/comment-page-1/#comment-238934</link>
		<dc:creator>Finding out largest tables on MySQL Server &#124; MySQL Performance Blog</dc:creator>
		<pubDate>Mon, 04 Feb 2008 14:46:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/08/17/duplicate-indexes-and-redundant-indexes/#comment-238934</guid>
		<description>[...] to data size often indicates there is a lot of indexes (so it is well possible there are some duplicates, redundant or simply unused indexes among them) or may be there is long primary key with Innodb tables. Of [...]</description>
		<content:encoded><![CDATA[<p>[...] to data size often indicates there is a lot of indexes (so it is well possible there are some duplicates, redundant or simply unused indexes among them) or may be there is long primary key with Innodb tables. Of [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: MySQL Performance Blog &#187; Redundant index is not always bad</title>
		<link>http://www.mysqlperformanceblog.com/2006/08/17/duplicate-indexes-and-redundant-indexes/comment-page-1/#comment-160073</link>
		<dc:creator>MySQL Performance Blog &#187; Redundant index is not always bad</dc:creator>
		<pubDate>Tue, 28 Aug 2007 09:54:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/08/17/duplicate-indexes-and-redundant-indexes/#comment-160073</guid>
		<description>[...] year ago Peter wrote about redundant indexes and mentioned sometimes it is good to leave two indexes, even one is first part of another. I&#039;m [...]</description>
		<content:encoded><![CDATA[<p>[...] year ago Peter wrote about redundant indexes and mentioned sometimes it is good to leave two indexes, even one is first part of another. I&#8217;m [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>

