diff --git a/mysql-test/r/partition.result b/mysql-test/r/partition.result index 431c5dda116..40586b8d54b 100644 --- a/mysql-test/r/partition.result +++ b/mysql-test/r/partition.result @@ -2473,3 +2473,17 @@ SELECT * FROM vtmp; 1 DROP VIEW vtmp; DROP TABLE t1; +# +# MDEV-365 "Got assertion when doing alter table on a partition" +# +CREATE TABLE t1 ( i INT ) ENGINE=Aria PARTITION BY HASH(i) PARTITIONS 2; +INSERT INTO t1 VALUES (1),(2),(2),(3),(4); +ALTER TABLE t1 ADD PARTITION PARTITIONS 2; +SELECT * from t1 order by i; +i +1 +2 +2 +3 +4 +DROP TABLE t1; diff --git a/mysql-test/t/partition.test b/mysql-test/t/partition.test index 08c028c8224..ef0d3df6661 100644 --- a/mysql-test/t/partition.test +++ b/mysql-test/t/partition.test @@ -2476,3 +2476,13 @@ SELECT 1 FROM t1 AS t1_0 JOIN t1 ON t1_0.a LIKE (SELECT 1 FROM t1); SELECT * FROM vtmp; DROP VIEW vtmp; DROP TABLE t1; + +--echo # +--echo # MDEV-365 "Got assertion when doing alter table on a partition" +--echo # + +CREATE TABLE t1 ( i INT ) ENGINE=Aria PARTITION BY HASH(i) PARTITIONS 2; +INSERT INTO t1 VALUES (1),(2),(2),(3),(4); +ALTER TABLE t1 ADD PARTITION PARTITIONS 2; +SELECT * from t1 order by i; +DROP TABLE t1; diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc index a9c79589faa..2bec12e4f66 100644 --- a/sql/sql_partition.cc +++ b/sql/sql_partition.cc @@ -5500,10 +5500,12 @@ static bool mysql_change_partitions(ALTER_PARTITION_PARAM_TYPE *lpt) build_table_filename(path, sizeof(path) - 1, lpt->db, lpt->table_name, "", 0); - if(mysql_trans_prepare_alter_copy_data(thd)) + /* First lock the original tables */ + if (file->ha_external_lock(thd, F_WRLCK)) DBUG_RETURN(TRUE); - if (file->ha_external_lock(thd, F_WRLCK)) + /* Disable transactions for all new tables */ + if (mysql_trans_prepare_alter_copy_data(thd)) DBUG_RETURN(TRUE); /* TODO: test if bulk_insert would increase the performance */ diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 2b1b43517b4..0a858b2c345 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -7247,7 +7247,7 @@ err_with_mdl: bool mysql_trans_prepare_alter_copy_data(THD *thd) { - DBUG_ENTER("mysql_prepare_alter_copy_data"); + DBUG_ENTER("mysql_trans_prepare_alter_copy_data"); /* Turn off recovery logging since rollback of an alter table is to delete the new table so there is no need to log the changes to it. @@ -7267,7 +7267,7 @@ bool mysql_trans_prepare_alter_copy_data(THD *thd) bool mysql_trans_commit_alter_copy_data(THD *thd) { bool error= FALSE; - DBUG_ENTER("mysql_commit_alter_copy_data"); + DBUG_ENTER("mysql_trans_commit_alter_copy_data"); if (ha_enable_transaction(thd, TRUE)) DBUG_RETURN(TRUE);