Commit 1fc6e297 authored by Sergei Golubchik's avatar Sergei Golubchik

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.
parent 2c79f575
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;
--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;
...@@ -4736,9 +4736,11 @@ commit_get_autoinc( ...@@ -4736,9 +4736,11 @@ commit_get_autoinc(
Field* autoinc_field = Field* autoinc_field =
old_table->found_next_number_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( dict_index_t* index = dict_table_get_index_on_name(
ctx->old_table, autoinc_field->field_index); ctx->old_table, autoinc_key->name);
max_autoinc = ha_alter_info->create_info->auto_increment_value; max_autoinc = ha_alter_info->create_info->auto_increment_value;
......
...@@ -4743,9 +4743,11 @@ commit_get_autoinc( ...@@ -4743,9 +4743,11 @@ commit_get_autoinc(
Field* autoinc_field = Field* autoinc_field =
old_table->found_next_number_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( dict_index_t* index = dict_table_get_index_on_name(
ctx->old_table, autoinc_field->field_index); ctx->old_table, autoinc_key->name);
max_autoinc = ha_alter_info->create_info->auto_increment_value; max_autoinc = ha_alter_info->create_info->auto_increment_value;
......
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