#At file:///export/home/x/mysql-5.5-bug11815600/ based on revid:marc.alff@stripped
3378 Jon Olav Hauglid 2011-03-09
Bug#11815600 [ERROR] INNODB COULD NOT FIND INDEX PRIMARY
KEY NO 0 FOR TABLE IN ERROR LOG
With the changes made by the patches for Bug#11751388 and
Bug#11784056, concurrent reads are allowed while secondary
indexes are created in InnoDB. This means that the metadata
lock on the affected table is not upgraded to exclusive
until the .FRM is updated at the end of ALTER TABLE processing.
The problem was that if this lock upgrade failed for some
reason (e.g. timeout), the index information in the server
and inside InnoDB would be out of sync. This would happen
since the add index operation already was committed inside
InnoDB but the table metadata inside the server had not been
updated yet.
This patch fixes the problem by dropping any recently added
indexes if lock upgrade fails.
Test case added to innodb_mysql_lock.test.
modified:
mysql-test/r/innodb_mysql_lock.result
mysql-test/t/innodb_mysql_lock.test
sql/sql_table.cc
=== modified file 'mysql-test/r/innodb_mysql_lock.result'
--- a/mysql-test/r/innodb_mysql_lock.result 2010-06-26 20:23:28 +0000
+++ b/mysql-test/r/innodb_mysql_lock.result 2011-03-09 10:38:39 +0000
@@ -148,3 +148,25 @@ COMMIT;
# Connection default
DROP TABLE t1, t2;
DROP VIEW v1;
+#
+# Bug#11815600 [ERROR] INNODB COULD NOT FIND INDEX PRIMARY
+# KEY NO 0 FOR TABLE IN ERROR LOG
+#
+DROP TABLE IF EXISTS t1;
+# Connection default
+CREATE TABLE t1 (id INT PRIMARY KEY, value INT) ENGINE = InnoDB;
+INSERT INTO t1 VALUES (1, 12345);
+START TRANSACTION;
+SELECT * FROM t1;
+id value
+1 12345
+# Connection con1
+SET lock_wait_timeout=1;
+ALTER TABLE t1 ADD INDEX idx(value);
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+# Connection default
+SELECT * FROM t1;
+id value
+1 12345
+COMMIT;
+DROP TABLE t1;
=== modified file 'mysql-test/t/innodb_mysql_lock.test'
--- a/mysql-test/t/innodb_mysql_lock.test 2010-08-06 11:29:37 +0000
+++ b/mysql-test/t/innodb_mysql_lock.test 2011-03-09 10:38:39 +0000
@@ -279,6 +279,38 @@ disconnect con2;
disconnect con3;
+--echo #
+--echo # Bug#11815600 [ERROR] INNODB COULD NOT FIND INDEX PRIMARY
+--echo # KEY NO 0 FOR TABLE IN ERROR LOG
+--echo #
+
+--disable_warnings
+DROP TABLE IF EXISTS t1;
+--enable_warnings
+
+--connect (con1,localhost,root)
+
+--echo # Connection default
+connection default;
+CREATE TABLE t1 (id INT PRIMARY KEY, value INT) ENGINE = InnoDB;
+INSERT INTO t1 VALUES (1, 12345);
+START TRANSACTION;
+SELECT * FROM t1;
+
+--echo # Connection con1
+--connection con1
+SET lock_wait_timeout=1;
+--error ER_LOCK_WAIT_TIMEOUT
+ALTER TABLE t1 ADD INDEX idx(value);
+
+--echo # Connection default
+--connection default
+SELECT * FROM t1;
+COMMIT;
+DROP TABLE t1;
+disconnect con1;
+
+
# Check that all connections opened by test cases in this file are really
# gone so execution of other tests won't be affected by their presence.
--source include/wait_until_count_sessions.inc
=== modified file 'sql/sql_table.cc'
--- a/sql/sql_table.cc 2011-03-07 09:08:10 +0000
+++ b/sql/sql_table.cc 2011-03-09 10:38:39 +0000
@@ -6596,7 +6596,28 @@ bool mysql_alter_table(THD *thd,char *ne
my_casedn_str(files_charset_info, old_name);
if (wait_while_table_is_used(thd, table, HA_EXTRA_PREPARE_FOR_RENAME))
+ {
+ // If lock upgrade fails, we must drop any indexes recently added.
+ if (index_add_count)
+ {
+ /*
+ Temporarily set table-key_info to include information about the
+ indexes added above that we now need to drop.
+ */
+ KEY *save_key_info= table->key_info;
+ table->key_info= key_info_buffer;
+ if ((error= table->file->prepare_drop_index(table, index_add_buffer,
+ index_add_count)))
+ table->file->print_error(error, MYF(0));
+ else if ((error= table->file->final_drop_index(table)))
+ table->file->print_error(error, MYF(0));
+ table->key_info= save_key_info;
+ // Reopen the table to rebuild the index translation table.
+ table->file->close();
+ table->file->ha_open(table, table->s->normalized_path.str, table->db_stat, 0);
+ }
goto err_new_table_cleanup;
+ }
close_all_tables_for_name(thd, table->s,
Attachment: [text/bzr-bundle] bzr/jon.hauglid@oracle.com-20110309103839-zrfhox2pwv5gx0ej.bundle
| Thread |
|---|
| • bzr commit into mysql-5.5 branch (jon.hauglid:3378) Bug#11815600 | Jon Olav Hauglid | 9 Mar |