From 1fc6e297f26756038c173eb7a1ea722d3a828c42 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 13 Jan 2016 21:06:29 +0100 Subject: [PATCH] XtraDB/InnoDB crash with autoinc, vcol and online alter Fix the doubly questional fix for MySQL Bug#17250787: * it detected autoinc index by looking for the first index that starts from autoinc column. never mind one column can be part of many indexes. * it used autoinc_field->field_index to look up into internal innodb dictionary. But field_index accounts for virtual columns too, while innodb dictionary ignores them. Find the index by its name, like elsewhere in ha_innobase. --- .../suite/vcol/r/innodb_autoinc_vcol.result | 16 ++++++++++++++++ mysql-test/suite/vcol/t/innodb_autoinc_vcol.test | 9 +++++++++ storage/innobase/handler/handler0alter.cc | 6 ++++-- storage/xtradb/handler/handler0alter.cc | 6 ++++-- 4 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 mysql-test/suite/vcol/r/innodb_autoinc_vcol.result create mode 100644 mysql-test/suite/vcol/t/innodb_autoinc_vcol.test 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;