Skip to content

Commit 607d8f9

Browse files
committed
MDEV-14081 ALTER TABLE CHANGE COLUMN Corrupts Index Leading to Crashes in 10.2
remove remnants of 10.0 bugfix, incorrectly merged into 10.2 Using col_names[i] was obviously, wrong, must've been col_names[ifield->col_no]. incorrect column name resulted in innodb having index unique_id2(id1), while the server thought it's unique_id2(id4). But col_names[ifield->col_no] is wrong too, because `table` has non-renamed columns, so the correct column name is always dict_table_get_col_name(table, ifield->col_no)
1 parent e6df603 commit 607d8f9

File tree

7 files changed

+29
-33
lines changed

7 files changed

+29
-33
lines changed

mysql-test/suite/innodb/r/alter_table.result

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,14 @@ t1 CREATE TABLE `t1` (
1111
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC
1212
drop table t1;
1313
set @@sql_mode=default;
14+
create table t1 (
15+
id1 int(11) not null auto_increment,
16+
id2 varchar(30) not null,
17+
id3 datetime not null default current_timestamp,
18+
primary key (id1),
19+
unique key unique_id2 (id2)
20+
) engine=innodb;
21+
alter table t1 change column id2 id4 varchar(100) not null;
22+
select * from t1 where id4 like 'a';
23+
id1 id4 id3
24+
drop table t1;

mysql-test/suite/innodb/r/innodb-alter.result

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -640,10 +640,8 @@ CHANGE foo_id FTS_DOC_ID BIGINT UNSIGNED NOT NULL;
640640
ALTER TABLE t1o DROP INDEX ct, DROP INDEX FTS_DOC_ID_INDEX,
641641
CHANGE FTS_DOC_ID foo_id BIGINT UNSIGNED NOT NULL;
642642
ALTER TABLE t1o ADD UNIQUE INDEX FTS_DOC_ID_INDEX(foo_id);
643-
call mtr.add_suppression("InnoDB: No matching column for `FTS_DOC_ID` in index `ct` of table `test`\\.`t1o`");
644643
ALTER TABLE t1o CHANGE foo_id FTS_DOC_ID BIGINT UNSIGNED NOT NULL,
645644
ADD FULLTEXT INDEX(ct);
646-
ERROR HY000: Index for table 't1o' is corrupt; try to repair it
647645
DROP TABLE sys_indexes;
648646
CREATE TABLE sys_indexes SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_INDEXES i
649647
INNER JOIN sys_tables st ON i.TABLE_ID=st.TABLE_ID;

mysql-test/suite/innodb/t/alter_table.test

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,17 @@ create index idx1 on t1(a(3073));
88
show create table t1;
99
drop table t1;
1010
set @@sql_mode=default;
11+
12+
#
13+
# MDEV-14081 ALTER TABLE CHANGE COLUMN Corrupts Index Leading to Crashes in 10.2
14+
#
15+
create table t1 (
16+
id1 int(11) not null auto_increment,
17+
id2 varchar(30) not null,
18+
id3 datetime not null default current_timestamp,
19+
primary key (id1),
20+
unique key unique_id2 (id2)
21+
) engine=innodb;
22+
alter table t1 change column id2 id4 varchar(100) not null;
23+
select * from t1 where id4 like 'a';
24+
drop table t1;

mysql-test/suite/innodb/t/innodb-alter.test

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -370,16 +370,8 @@ CHANGE FTS_DOC_ID foo_id BIGINT UNSIGNED NOT NULL;
370370

371371
ALTER TABLE t1o ADD UNIQUE INDEX FTS_DOC_ID_INDEX(foo_id);
372372

373-
# FIXME: MDEV-9469 'Incorrect key file' on ALTER TABLE
374-
call mtr.add_suppression("InnoDB: No matching column for `FTS_DOC_ID` in index `ct` of table `test`\\.`t1o`");
375-
--error ER_NOT_KEYFILE
376373
ALTER TABLE t1o CHANGE foo_id FTS_DOC_ID BIGINT UNSIGNED NOT NULL,
377374
ADD FULLTEXT INDEX(ct);
378-
# FIXME: MDEV-9469 (enable this)
379-
#--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
380-
#ALTER TABLE t1o CHANGE FTS_DOC_ID foo_id BIGINT UNSIGNED NOT NULL,
381-
#ALGORITHM=INPLACE;
382-
#end of MDEV-9469 FIXME
383375

384376
DROP TABLE sys_indexes;
385377
CREATE TABLE sys_indexes SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_INDEXES i

storage/innobase/handler/handler0alter.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4850,7 +4850,7 @@ prepare_inplace_alter_table_dict(
48504850

48514851
ctx->add_index[a] = row_merge_create_index(
48524852
ctx->trx, ctx->new_table,
4853-
&index_defs[a], add_v, ctx->col_names);
4853+
&index_defs[a], add_v);
48544854

48554855
add_key_nums[a] = index_defs[a].key_number;
48564856

storage/innobase/include/row0merge.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,16 +265,13 @@ row_merge_rename_index_to_drop(
265265
@param[in] index_def the index definition
266266
@param[in] add_v new virtual columns added along with add
267267
index call
268-
@param[in] col_names column names if columns are renamed
269-
or NULL
270268
@return index, or NULL on error */
271269
dict_index_t*
272270
row_merge_create_index(
273271
trx_t* trx,
274272
dict_table_t* table,
275273
const index_def_t* index_def,
276-
const dict_add_v_col_t* add_v,
277-
const char** col_names)
274+
const dict_add_v_col_t* add_v)
278275
MY_ATTRIBUTE((warn_unused_result));
279276

280277
/*********************************************************************//**

storage/innobase/row/row0merge.cc

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4362,16 +4362,13 @@ row_merge_create_index_graph(
43624362
@param[in] index_def the index definition
43634363
@param[in] add_v new virtual columns added along with add
43644364
index call
4365-
@param[in] col_names column names if columns are renamed
4366-
or NULL
43674365
@return index, or NULL on error */
43684366
dict_index_t*
43694367
row_merge_create_index(
43704368
trx_t* trx,
43714369
dict_table_t* table,
43724370
const index_def_t* index_def,
4373-
const dict_add_v_col_t* add_v,
4374-
const char** col_names)
4371+
const dict_add_v_col_t* add_v)
43754372
{
43764373
dict_index_t* index;
43774374
dberr_t err;
@@ -4411,20 +4408,7 @@ row_merge_create_index(
44114408
table, ifield->col_no);
44124409
}
44134410
} else {
4414-
/*
4415-
Alter table renaming a column and then adding a index
4416-
to this new name e.g ALTER TABLE t
4417-
CHANGE COLUMN b c INT NOT NULL, ADD UNIQUE INDEX (c);
4418-
requires additional check as column names are not yet
4419-
changed when new index definitions are created. Table's
4420-
new column names are on a array of column name pointers
4421-
if any of the column names are changed. */
4422-
4423-
if (col_names && col_names[i]) {
4424-
name = col_names[i];
4425-
} else {
4426-
name = dict_table_get_col_name(table, ifield->col_no);
4427-
}
4411+
name = dict_table_get_col_name(table, ifield->col_no);
44284412
}
44294413

44304414
dict_mem_index_add_field(index, name, ifield->prefix_len);

0 commit comments

Comments
 (0)