Skip to content

Commit a0518ed

Browse files
committed
MDEV-23357 Server crashes in Sql_cmd_alter_table_exchange_partition::exchange_partition
1 parent c69520c commit a0518ed

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,10 @@ set @@session.alter_algorithm= @save_alter_algorithm;
2121
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));
2222
ALTER TABLE t1 DROP PARTITION p;
2323
DROP TABLE if exists t1;
24+
CREATE TABLE t1 (i INT);
25+
CREATE VIEW v1 as SELECT * FROM t1;
26+
CREATE TABLE t2 (i INT);
27+
ALTER TABLE v1 EXCHANGE PARTITION p2 WITH TABLE t2 ;
28+
ERROR 42000: Can't open table
29+
DROP VIEW v1;
30+
DROP TABLE t1, t2;

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,14 @@ set @@session.alter_algorithm= @save_alter_algorithm;
2727
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));
2828
ALTER TABLE t1 DROP PARTITION p;
2929
DROP TABLE if exists t1;
30+
31+
#
32+
# MDEV-23357 Server crashes in Sql_cmd_alter_table_exchange_partition::exchange_partition
33+
#
34+
CREATE TABLE t1 (i INT);
35+
CREATE VIEW v1 as SELECT * FROM t1;
36+
CREATE TABLE t2 (i INT);
37+
--error ER_CHECK_NO_SUCH_TABLE
38+
ALTER TABLE v1 EXCHANGE PARTITION p2 WITH TABLE t2 ;
39+
DROP VIEW v1;
40+
DROP TABLE t1, t2;

sql/sql_partition_admin.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -563,12 +563,12 @@ bool Sql_cmd_alter_table_exchange_partition::
563563
part_table= table_list->table;
564564
swap_table= swap_table_list->table;
565565

566-
if (part_table->file->check_if_updates_are_ignored("ALTER"))
567-
DBUG_RETURN(return_with_logging(thd));
568-
569566
if (unlikely(check_exchange_partition(swap_table, part_table)))
570567
DBUG_RETURN(TRUE);
571568

569+
if (part_table->file->check_if_updates_are_ignored("ALTER"))
570+
DBUG_RETURN(return_with_logging(thd));
571+
572572
/* Add IF EXISTS to binlog if shared table */
573573
if (part_table->file->partition_ht()->flags &
574574
HTON_TABLE_MAY_NOT_EXIST_ON_SLAVE)

0 commit comments

Comments
 (0)