mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
branches/5.1: Copy the maximum AUTOINC value from the old table to the new
table when MySQL does a CREATE INDEX ON T. This is required because MySQL does a table copy, rename and drops the old table. Fix Bug#47125: auto_increment start value is ignored if an index is created and engine=innodb rb://168
This commit is contained in:
@ -5510,18 +5510,22 @@ ha_innobase::create(
|
||||
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. */
|
||||
this is an ALTER TABLE or CREATE INDEX because CREATE INDEX
|
||||
does a table copy too. */
|
||||
|
||||
if (((create_info->used_fields & HA_CREATE_USED_AUTO)
|
||||
|| thd_sql_command(thd) == SQLCOM_ALTER_TABLE)
|
||||
&& create_info->auto_increment_value != 0) {
|
||||
|| thd_sql_command(thd) == SQLCOM_ALTER_TABLE
|
||||
|| thd_sql_command(thd) == SQLCOM_CREATE_INDEX)
|
||||
&& create_info->auto_increment_value > 0) {
|
||||
|
||||
/* Query was ALTER TABLE...AUTO_INCREMENT = x; or
|
||||
CREATE TABLE ...AUTO_INCREMENT = x; Find out a table
|
||||
definition from the dictionary and get the current value
|
||||
of the auto increment field. Set a new value to the
|
||||
auto increment field if the value is greater than the
|
||||
maximum value in the column. */
|
||||
/* Query was one of :
|
||||
CREATE TABLE ...AUTO_INCREMENT = x; or
|
||||
ALTER TABLE...AUTO_INCREMENT = x; or
|
||||
CREATE INDEX x on t(...);
|
||||
Find out a table definition from the dictionary and get
|
||||
the current value of the auto increment field. Set a new
|
||||
value to the auto increment field if the value is greater
|
||||
than the maximum value in the column. */
|
||||
|
||||
auto_inc_value = create_info->auto_increment_value;
|
||||
|
||||
|
@ -1111,3 +1111,18 @@ c1 c2
|
||||
3 innodb
|
||||
4 NULL
|
||||
DROP TABLE t1;
|
||||
CREATE TABLE T1 (c1 INT AUTO_INCREMENT, c2 INT, PRIMARY KEY(c1)) AUTO_INCREMENT=10 ENGINE=InnoDB;
|
||||
CREATE INDEX i1 on T1(c2);
|
||||
SHOW CREATE TABLE T1;
|
||||
Table Create Table
|
||||
T1 CREATE TABLE `T1` (
|
||||
`c1` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`c2` int(11) DEFAULT NULL,
|
||||
PRIMARY KEY (`c1`),
|
||||
KEY `i1` (`c2`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=latin1
|
||||
INSERT INTO T1 (c2) values (0);
|
||||
SELECT * FROM T1;
|
||||
c1 c2
|
||||
10 0
|
||||
DROP TABLE T1;
|
||||
|
@ -607,5 +607,16 @@ INSERT INTO t1 VALUES (NULL, NULL);
|
||||
SHOW CREATE TABLE t1;
|
||||
SELECT * FROM t1;
|
||||
DROP TABLE t1;
|
||||
|
||||
#
|
||||
# End negative number check
|
||||
|
||||
##
|
||||
# 47125: auto_increment start value is ignored if an index is created
|
||||
# and engine=innodb
|
||||
#
|
||||
CREATE TABLE T1 (c1 INT AUTO_INCREMENT, c2 INT, PRIMARY KEY(c1)) AUTO_INCREMENT=10 ENGINE=InnoDB;
|
||||
CREATE INDEX i1 on T1(c2);
|
||||
SHOW CREATE TABLE T1;
|
||||
INSERT INTO T1 (c2) values (0);
|
||||
SELECT * FROM T1;
|
||||
DROP TABLE T1;
|
||||
|
Reference in New Issue
Block a user