From a0518ed998d3e3256d576e6209593c3fd3969ce9 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Fri, 31 Jul 2020 17:11:17 +0200 Subject: [PATCH] MDEV-23357 Server crashes in Sql_cmd_alter_table_exchange_partition::exchange_partition --- mysql-test/suite/parts/r/alter_table.result | 7 +++++++ mysql-test/suite/parts/t/alter_table.test | 11 +++++++++++ sql/sql_partition_admin.cc | 6 +++--- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/mysql-test/suite/parts/r/alter_table.result b/mysql-test/suite/parts/r/alter_table.result index fc508663204..94100b83118 100644 --- a/mysql-test/suite/parts/r/alter_table.result +++ b/mysql-test/suite/parts/r/alter_table.result @@ -21,3 +21,10 @@ set @@session.alter_algorithm= @save_alter_algorithm; CREATE TABLE t1 (a INT) PARTITION BY RANGE(a) SUBPARTITION BY HASH(a) (PARTITION p VALUES LESS THAN (5) (SUBPARTITION sp, SUBPARTITION sp1), PARTITION p1 VALUES LESS THAN MAXVALUE (SUBPARTITION sp2, SUBPARTITION sp3)); ALTER TABLE t1 DROP PARTITION p; DROP TABLE if exists t1; +CREATE TABLE t1 (i INT); +CREATE VIEW v1 as SELECT * FROM t1; +CREATE TABLE t2 (i INT); +ALTER TABLE v1 EXCHANGE PARTITION p2 WITH TABLE t2 ; +ERROR 42000: Can't open table +DROP VIEW v1; +DROP TABLE t1, t2; diff --git a/mysql-test/suite/parts/t/alter_table.test b/mysql-test/suite/parts/t/alter_table.test index 6c4d83f9eed..53b61806acb 100644 --- a/mysql-test/suite/parts/t/alter_table.test +++ b/mysql-test/suite/parts/t/alter_table.test @@ -27,3 +27,14 @@ set @@session.alter_algorithm= @save_alter_algorithm; CREATE TABLE t1 (a INT) PARTITION BY RANGE(a) SUBPARTITION BY HASH(a) (PARTITION p VALUES LESS THAN (5) (SUBPARTITION sp, SUBPARTITION sp1), PARTITION p1 VALUES LESS THAN MAXVALUE (SUBPARTITION sp2, SUBPARTITION sp3)); ALTER TABLE t1 DROP PARTITION p; DROP TABLE if exists t1; + +# +# MDEV-23357 Server crashes in Sql_cmd_alter_table_exchange_partition::exchange_partition +# +CREATE TABLE t1 (i INT); +CREATE VIEW v1 as SELECT * FROM t1; +CREATE TABLE t2 (i INT); +--error ER_CHECK_NO_SUCH_TABLE +ALTER TABLE v1 EXCHANGE PARTITION p2 WITH TABLE t2 ; +DROP VIEW v1; +DROP TABLE t1, t2; diff --git a/sql/sql_partition_admin.cc b/sql/sql_partition_admin.cc index 7822cab5ff0..55abee72a52 100644 --- a/sql/sql_partition_admin.cc +++ b/sql/sql_partition_admin.cc @@ -563,12 +563,12 @@ bool Sql_cmd_alter_table_exchange_partition:: part_table= table_list->table; swap_table= swap_table_list->table; - if (part_table->file->check_if_updates_are_ignored("ALTER")) - DBUG_RETURN(return_with_logging(thd)); - if (unlikely(check_exchange_partition(swap_table, part_table))) DBUG_RETURN(TRUE); + if (part_table->file->check_if_updates_are_ignored("ALTER")) + DBUG_RETURN(return_with_logging(thd)); + /* Add IF EXISTS to binlog if shared table */ if (part_table->file->partition_ht()->flags & HTON_TABLE_MAY_NOT_EXIST_ON_SLAVE)