Commit 992a74f4 authored by sunny's avatar sunny

branches/5.1: When the InnoDB and MySQL data dictionaries go out of sync, before

the bug fix we would assert on missing autoinc columns. With this fix we allow
MySQL to open the table but set the next autoinc value for the column to the
MAX value. This effectively disables the next value generation. INSERTs will
fail with a generic AUTOINC failure. However, the user should be able to
read/dump the table, set the column values explicitly, use ALTER TABLE to
set the next autoinc value and/or sync the two data dictionaries to resume
normal operations.

Fix Bug#44030 Error: (1500) Couldn't read the MAX(ID) autoinc value from the
index (PRIMARY)

rb://118
parent 1a9e35d4
...@@ -2414,12 +2414,27 @@ ha_innobase::innobase_initialize_autoinc() ...@@ -2414,12 +2414,27 @@ ha_innobase::innobase_initialize_autoinc()
dict_table_autoinc_initialize(innodb_table, auto_inc); dict_table_autoinc_initialize(innodb_table, auto_inc);
} else { } else if (error == DB_RECORD_NOT_FOUND) {
ut_print_timestamp(stderr); ut_print_timestamp(stderr);
fprintf(stderr, " InnoDB: Error: (%lu) Couldn't read " fprintf(stderr, " InnoDB: Error: MySQL and InnoDB data "
"the MAX(%s) autoinc value from the " "dictionaries are out of sync.\n"
"index (%s).\n", error, col_name, index->name); "InnoDB: Unable to find the AUTOINC column %s in the "
} "InnoDB table %s.\n"
"InnoDB: We set the next AUTOINC column value to the "
"maximum possible value,\n"
"InnoDB: in effect disabling the AUTOINC next value "
"generation.\n"
"InnoDB: You can either set the next AUTOINC value "
"explicitly using ALTER TABLE\n"
"InnoDB: or fix the data dictionary.\n",
col_name, index->table->name);
auto_inc = 0xFFFFFFFFFFFFFFFFULL;
dict_table_autoinc_initialize(innodb_table, auto_inc);
error = DB_SUCCESS;
} /* else other errors are still fatal */
return(ulong(error)); return(ulong(error));
} }
...@@ -2630,7 +2645,6 @@ ha_innobase::open( ...@@ -2630,7 +2645,6 @@ ha_innobase::open(
if (dict_table_autoinc_read(prebuilt->table) == 0) { if (dict_table_autoinc_read(prebuilt->table) == 0) {
error = innobase_initialize_autoinc(); error = innobase_initialize_autoinc();
/* Should always succeed! */
ut_a(error == DB_SUCCESS); ut_a(error == DB_SUCCESS);
} }
......
...@@ -867,3 +867,11 @@ INSERT INTO t2 SELECT NULL FROM t1; ...@@ -867,3 +867,11 @@ INSERT INTO t2 SELECT NULL FROM t1;
Got one of the listed errors Got one of the listed errors
DROP TABLE t1; DROP TABLE t1;
DROP TABLE t2; DROP TABLE t2;
c1 TINYINT(3) UNSIGNED NOT NULL AUTO_INCREMENT
PRIMARY KEY) ENGINE=InnoDB;
INSERT INTO t2 SELECT c1 FROM t1;
Got one of the listed errors
INSERT INTO t2 SELECT NULL FROM t1;
Got one of the listed errors
DROP TABLE t1;
DROP TABLE t2;
...@@ -478,3 +478,23 @@ INSERT INTO t2 SELECT c1 FROM t1; ...@@ -478,3 +478,23 @@ INSERT INTO t2 SELECT c1 FROM t1;
INSERT INTO t2 SELECT NULL FROM t1; INSERT INTO t2 SELECT NULL FROM t1;
DROP TABLE t1; DROP TABLE t1;
DROP TABLE t2; DROP TABLE t2;
#
# 44030: Error: (1500) Couldn't read the MAX(ID) autoinc value from
# the index (PRIMARY)
# This test requires a restart of the server
CREATE TABLE t1 (c1 INT PRIMARY KEY AUTO_INCREMENT) ENGINE=InnoDB;
INSERT INTO t1 VALUES (null);
INSERT INTO t1 VALUES (null);
ALTER TABLE t1 CHANGE c1 d1 INT NOT NULL AUTO_INCREMENT;
SELECT * FROM t1;
# Restart the server
-- source include/restart_mysqld.inc
# The MySQL and InnoDB data dictionaries should now be out of sync.
# The select should print message to the error log
SELECT * FROM t1;
-- error ER_AUTOINC_READ_FAILED,1467
INSERT INTO t1 VALUES(null);
ALTER TABLE t1 AUTO_INCREMENT = 3;
INSERT INTO t1 VALUES(null);
SELECT * FROM t1;
DROP TABLE t1;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment