Commit 1e130ba6 authored by sunny's avatar sunny

branches/5.1: Fix Bug# 34920. We need to use/inherit the passed in autoinc

counter for ALTER TABLE statements too.
parent 30ee677a
......@@ -5109,8 +5109,15 @@ ha_innobase::create(
DBUG_ASSERT(innobase_table != 0);
if ((create_info->used_fields & HA_CREATE_USED_AUTO) &&
(create_info->auto_increment_value != 0)) {
/* Note: We can't call update_thd() as prebuilt will not be
setup at this stage and so we use thd. */
/* We need to copy the AUTOINC value from the old table if
this is an ALTER TABLE. */
if (((create_info->used_fields & HA_CREATE_USED_AUTO)
|| thd_sql_command(thd) == SQLCOM_ALTER_TABLE)
&& create_info->auto_increment_value != 0) {
/* Query was ALTER TABLE...AUTO_INCREMENT = x; or
CREATE TABLE ...AUTO_INCREMENT = x; Find out a table
......
......@@ -3231,3 +3231,22 @@ a
2
DROP TABLE t1;
DROP TABLE t2;
CREATE TABLE t1 (
c1 INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
c2 VARCHAR(128) NOT NULL,
PRIMARY KEY(c1)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=100;
CREATE TABLE t2 (
c1 INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
c2 INT(10) UNSIGNED DEFAULT NULL,
PRIMARY KEY(c1)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=200;
SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE table_name = 't2';
AUTO_INCREMENT
200
ALTER TABLE t2 ADD CONSTRAINT t1_t2_1 FOREIGN KEY(c1) REFERENCES t1(c1);
SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE table_name = 't2';
AUTO_INCREMENT
200
DROP TABLE t2;
DROP TABLE t1;
......@@ -2415,6 +2415,29 @@ DROP TABLE t2;
DISCONNECT c1;
DISCONNECT c2;
#
# Bug 34920 test
#
CONNECTION default;
CREATE TABLE t1 (
c1 INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
c2 VARCHAR(128) NOT NULL,
PRIMARY KEY(c1)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=100;
CREATE TABLE t2 (
c1 INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
c2 INT(10) UNSIGNED DEFAULT NULL,
PRIMARY KEY(c1)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=200;
SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE table_name = 't2';
ALTER TABLE t2 ADD CONSTRAINT t1_t2_1 FOREIGN KEY(c1) REFERENCES t1(c1);
SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE table_name = 't2';
DROP TABLE t2;
DROP TABLE t1;
# End 34920 test
#######################################################################
# #
# Please, DO NOT TOUCH this file as well as the innodb.result file. #
......
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