Skip to content

Commit

Permalink
MDEV-13097 Online alter of a partitioned MyISAM table with auto_incre…
Browse files Browse the repository at this point in the history
…ment

MyISAM only allows online alter if autoincrement didn't change.
MyISAM detects that by comparing new autoinc value from create_info,
with the old one, stored in MYI. But in partitioned tables,
create_info->auto_increment_value is for the whole table, max of
autoinc values of individual MYI partitions. So *some* MYI partitions
will inevitably think that alter table changes auto_increment value
and will deny online alter.

Fix: only compare autoinc values, if the user has used AUTO_INCREMENT
in the ALTER TABLE statement.
  • Loading branch information
vuvova committed Jun 22, 2017
1 parent b6ce68f commit 3f240bf
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
20 changes: 20 additions & 0 deletions mysql-test/r/partition_alter.result
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,23 @@ t1 CREATE TABLE `t1` (
PARTITION p2 VALUES LESS THAN ('2020-10-19') ENGINE = MyISAM) */
insert t1 values (2, '2020-01-03', 20);
drop table t1;
create table t1 (id_1 int auto_increment, id_2 int, id_3 int, d1 date, dt1 datetime default current_timestamp, dt2 datetime default current_timestamp on update current_timestamp, primary key (id_2, id_3), key(id_1)) partition by hash(id_2) partitions 3 (partition p01, partition p02, partition p03);
insert into t1 values(0, 1, 1, NULL, now(), now());
alter online table t1 delay_key_write=1;
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id_1` int(11) NOT NULL AUTO_INCREMENT,
`id_2` int(11) NOT NULL,
`id_3` int(11) NOT NULL,
`d1` date DEFAULT NULL,
`dt1` datetime DEFAULT CURRENT_TIMESTAMP,
`dt2` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id_2`,`id_3`),
KEY `id_1` (`id_1`)
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=latin1 DELAY_KEY_WRITE=1
/*!50100 PARTITION BY HASH (id_2)
(PARTITION p01 ENGINE = MyISAM,
PARTITION p02 ENGINE = MyISAM,
PARTITION p03 ENGINE = MyISAM) */
drop table t1;
9 changes: 9 additions & 0 deletions mysql-test/t/partition_alter.test
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,12 @@ show create table t1;
insert t1 values (2, '2020-01-03', 20);
drop table t1;
--list_files $datadir/test

#
# MDEV-13097 Online alter of a partitioned MyISAM table with auto_increment
#
create table t1 (id_1 int auto_increment, id_2 int, id_3 int, d1 date, dt1 datetime default current_timestamp, dt2 datetime default current_timestamp on update current_timestamp, primary key (id_2, id_3), key(id_1)) partition by hash(id_2) partitions 3 (partition p01, partition p02, partition p03);
insert into t1 values(0, 1, 1, NULL, now(), now());
alter online table t1 delay_key_write=1;
show create table t1;
drop table t1;
3 changes: 2 additions & 1 deletion storage/myisam/ha_myisam.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2266,7 +2266,8 @@ bool ha_myisam::check_if_incompatible_data(HA_CREATE_INFO *create_info,
{
uint options= table->s->db_options_in_use;

if (create_info->auto_increment_value != stats.auto_increment_value ||
if ((create_info->used_fields & HA_CREATE_USED_AUTO &&
create_info->auto_increment_value != stats.auto_increment_value) ||
create_info->data_file_name != data_file_name ||
create_info->index_file_name != index_file_name ||
table_changes == IS_EQUAL_NO ||
Expand Down

0 comments on commit 3f240bf

Please sign in to comment.