Skip to content

Commit 1fc6e29

Browse files
committed
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.
1 parent 2c79f57 commit 1fc6e29

File tree

4 files changed

+33
-4
lines changed

4 files changed

+33
-4
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
create table t1 (c2 int as (-c1), c1 int primary key auto_increment) engine=innodb;
2+
insert into t1(c1) values (null),(null),(null);
3+
select * from t1;
4+
c2 c1
5+
-1 1
6+
-2 2
7+
-3 3
8+
alter table t1 auto_increment = 3;
9+
show create table t1;
10+
Table Create Table
11+
t1 CREATE TABLE `t1` (
12+
`c2` int(11) AS (-c1) VIRTUAL,
13+
`c1` int(11) NOT NULL AUTO_INCREMENT,
14+
PRIMARY KEY (`c1`)
15+
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1
16+
drop table t1;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
--source include/have_innodb.inc
2+
3+
create table t1 (c2 int as (-c1), c1 int primary key auto_increment) engine=innodb;
4+
insert into t1(c1) values (null),(null),(null);
5+
select * from t1;
6+
alter table t1 auto_increment = 3;
7+
show create table t1;
8+
drop table t1;
9+

storage/innobase/handler/handler0alter.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4736,9 +4736,11 @@ commit_get_autoinc(
47364736

47374737
Field* autoinc_field =
47384738
old_table->found_next_number_field;
4739+
KEY* autoinc_key =
4740+
old_table->key_info + old_table->s->next_number_index;
47394741

4740-
dict_index_t* index = dict_table_get_index_on_first_col(
4741-
ctx->old_table, autoinc_field->field_index);
4742+
dict_index_t* index = dict_table_get_index_on_name(
4743+
ctx->old_table, autoinc_key->name);
47424744

47434745
max_autoinc = ha_alter_info->create_info->auto_increment_value;
47444746

storage/xtradb/handler/handler0alter.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4743,9 +4743,11 @@ commit_get_autoinc(
47434743

47444744
Field* autoinc_field =
47454745
old_table->found_next_number_field;
4746+
KEY* autoinc_key =
4747+
old_table->key_info + old_table->s->next_number_index;
47464748

4747-
dict_index_t* index = dict_table_get_index_on_first_col(
4748-
ctx->old_table, autoinc_field->field_index);
4749+
dict_index_t* index = dict_table_get_index_on_name(
4750+
ctx->old_table, autoinc_key->name);
47494751

47504752
max_autoinc = ha_alter_info->create_info->auto_increment_value;
47514753

0 commit comments

Comments
 (0)