Skip to content

Commit 3f240bf

Browse files
committed
MDEV-13097 Online alter of a partitioned MyISAM table with auto_increment
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.
1 parent b6ce68f commit 3f240bf

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

mysql-test/r/partition_alter.result

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,23 @@ t1 CREATE TABLE `t1` (
9292
PARTITION p2 VALUES LESS THAN ('2020-10-19') ENGINE = MyISAM) */
9393
insert t1 values (2, '2020-01-03', 20);
9494
drop table t1;
95+
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);
96+
insert into t1 values(0, 1, 1, NULL, now(), now());
97+
alter online table t1 delay_key_write=1;
98+
show create table t1;
99+
Table Create Table
100+
t1 CREATE TABLE `t1` (
101+
`id_1` int(11) NOT NULL AUTO_INCREMENT,
102+
`id_2` int(11) NOT NULL,
103+
`id_3` int(11) NOT NULL,
104+
`d1` date DEFAULT NULL,
105+
`dt1` datetime DEFAULT CURRENT_TIMESTAMP,
106+
`dt2` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
107+
PRIMARY KEY (`id_2`,`id_3`),
108+
KEY `id_1` (`id_1`)
109+
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=latin1 DELAY_KEY_WRITE=1
110+
/*!50100 PARTITION BY HASH (id_2)
111+
(PARTITION p01 ENGINE = MyISAM,
112+
PARTITION p02 ENGINE = MyISAM,
113+
PARTITION p03 ENGINE = MyISAM) */
114+
drop table t1;

mysql-test/t/partition_alter.test

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,12 @@ show create table t1;
103103
insert t1 values (2, '2020-01-03', 20);
104104
drop table t1;
105105
--list_files $datadir/test
106+
107+
#
108+
# MDEV-13097 Online alter of a partitioned MyISAM table with auto_increment
109+
#
110+
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);
111+
insert into t1 values(0, 1, 1, NULL, now(), now());
112+
alter online table t1 delay_key_write=1;
113+
show create table t1;
114+
drop table t1;

storage/myisam/ha_myisam.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2266,7 +2266,8 @@ bool ha_myisam::check_if_incompatible_data(HA_CREATE_INFO *create_info,
22662266
{
22672267
uint options= table->s->db_options_in_use;
22682268

2269-
if (create_info->auto_increment_value != stats.auto_increment_value ||
2269+
if ((create_info->used_fields & HA_CREATE_USED_AUTO &&
2270+
create_info->auto_increment_value != stats.auto_increment_value) ||
22702271
create_info->data_file_name != data_file_name ||
22712272
create_info->index_file_name != index_file_name ||
22722273
table_changes == IS_EQUAL_NO ||

0 commit comments

Comments
 (0)