原文链接:http://www.mysqlperformanceblog.com/2011/11/29/innodb-vs-mysql-index-counts/
I had a customer recently who a few strange errors in their mysqld.err log:
最近在一个客户的错误日志里面发现一些奇怪的错误
[ERROR] Table database_name/table_name contains 8 indexes inside InnoDB, which is different from the number of indexes 7 defined in the MySQL
This customer was running Percona Server 5.1 and they got this error on two tables during a maintenance window when they were adding indexes to the same tables. We had a suspicion that it had something to do with Fast index creation in Innodb, and that it had been corrected when the ALTER TABLE completed because the errors had not recurred.
Reproducing the error on a test system is simple:
From my testing, I saw that the error only happened when the table was opened and not on every table access. So, it was a possibility that the indexes were out of sync and we weren’t seeing new errors in the log simply because the table hadn’t been re-opened.
But, before getting too crazy, how can we verify the problem still exists? We need a way to compare the output of SHOW CREATE TABLE to what Innodb thinks. What Innodb thinks is in the Innodb Data dictionary.
ALTER TABLE table_name ENGINE=Innodb;
This, of course, rebuilds the whole table based on the .frm table definition and removes the existing index in Innodb, which might not be desirable, but at least you can re-add it later. However, it’s not the greatest thing to do on a live production database master if you can help it.
Another solution might be to figure out what index was missing via the Innodb data dictionary (more on that in a minute), create a separate table identical to the existing .frm, add that index to it, and copy the new .frm back over the original. Kind of scary.
My advice is to ensure the error still exists before trying to fix it.