diff --git a/mysql-test/suite/vcol/r/innodb_autoinc_vcol.result b/mysql-test/suite/vcol/r/innodb_autoinc_vcol.result new file mode 100644 index 00000000000..f2d6b4105ff --- /dev/null +++ b/mysql-test/suite/vcol/r/innodb_autoinc_vcol.result @@ -0,0 +1,16 @@ +create table t1 (c2 int as (-c1), c1 int primary key auto_increment) engine=innodb; +insert into t1(c1) values (null),(null),(null); +select * from t1; +c2 c1 +-1 1 +-2 2 +-3 3 +alter table t1 auto_increment = 3; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c2` int(11) AS (-c1) VIRTUAL, + `c1` int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (`c1`) +) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1 +drop table t1; diff --git a/mysql-test/suite/vcol/t/innodb_autoinc_vcol.test b/mysql-test/suite/vcol/t/innodb_autoinc_vcol.test new file mode 100644 index 00000000000..2f2ac3d08e1 --- /dev/null +++ b/mysql-test/suite/vcol/t/innodb_autoinc_vcol.test @@ -0,0 +1,9 @@ +--source include/have_innodb.inc + +create table t1 (c2 int as (-c1), c1 int primary key auto_increment) engine=innodb; +insert into t1(c1) values (null),(null),(null); +select * from t1; +alter table t1 auto_increment = 3; +show create table t1; +drop table t1; + diff --git a/storage/innobase/handler/handler0alter.cc b/storage/innobase/handler/handler0alter.cc index f8efc38afff..49a9c424287 100644 --- a/storage/innobase/handler/handler0alter.cc +++ b/storage/innobase/handler/handler0alter.cc @@ -4736,9 +4736,11 @@ commit_get_autoinc( Field* autoinc_field = old_table->found_next_number_field; + KEY* autoinc_key = + old_table->key_info + old_table->s->next_number_index; - dict_index_t* index = dict_table_get_index_on_first_col( - ctx->old_table, autoinc_field->field_index); + dict_index_t* index = dict_table_get_index_on_name( + ctx->old_table, autoinc_key->name); max_autoinc = ha_alter_info->create_info->auto_increment_value; diff --git a/storage/xtradb/handler/handler0alter.cc b/storage/xtradb/handler/handler0alter.cc index 8f29332d05b..5235b8f5443 100644 --- a/storage/xtradb/handler/handler0alter.cc +++ b/storage/xtradb/handler/handler0alter.cc @@ -4743,9 +4743,11 @@ commit_get_autoinc( Field* autoinc_field = old_table->found_next_number_field; + KEY* autoinc_key = + old_table->key_info + old_table->s->next_number_index; - dict_index_t* index = dict_table_get_index_on_first_col( - ctx->old_table, autoinc_field->field_index); + dict_index_t* index = dict_table_get_index_on_name( + ctx->old_table, autoinc_key->name); max_autoinc = ha_alter_info->create_info->auto_increment_value;