From d9484a2f60c488c63e6f9e6cacc06066cf0118be Mon Sep 17 00:00:00 2001 From: Oleksandr Byelkin Date: Tue, 4 Apr 2017 14:47:58 +0200 Subject: [PATCH] MDEV-12395: DROP PARTITION does not work as expected when table has DEFAULT LIST partition Data loss in case of partituon removing is documented => do not try to prevent it --- mysql-test/r/partition_default.result | 48 ++++++++++++++++++++++----- mysql-test/t/partition_default.test | 32 ++++++++++++++---- sql/sql_partition.cc | 3 +- 3 files changed, 67 insertions(+), 16 deletions(-) diff --git a/mysql-test/r/partition_default.result b/mysql-test/r/partition_default.result index 2833d92de323c..bb0a5d4061bd9 100644 --- a/mysql-test/r/partition_default.result +++ b/mysql-test/r/partition_default.result @@ -921,9 +921,6 @@ explain partitions select * from t1 where a=10 and b=10; id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE t1 p0 system NULL NULL NULL NULL 1 alter table t1 drop partition p2; -ERROR HY000: Table has no partition for value 2 -delete from t1 where a=2; -alter table t1 drop partition p2; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( @@ -1069,9 +1066,6 @@ explain partitions select * from t1 where a=10 and b=10; id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE t1 p0 system NULL NULL NULL NULL 1 alter table t1 drop partition p2; -ERROR HY000: Table has no partition for value from column_list -delete from t1 where a=2; -alter table t1 drop partition p2; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( @@ -1125,10 +1119,10 @@ alter table t1 add partition (partition p0 VALUES IN (2,3)); select partition_name, table_rows from INFORMATION_SCHEMA.PARTITIONS where table_name='t1'; partition_name table_rows -p0 2 +p0 0 p1 1 p2 1 -pd 0 +pd 2 drop table t1; create table t1 (a int, b int) PARTITION BY LIST COLUMNS(a,b) @@ -1233,3 +1227,41 @@ select * from t1 where i is null; id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE t1 p0 system NULL NULL NULL NULL 1 drop table t1; +# +# MDEV-12395: DROP PARTITION does not work as expected when +# table has DEFAULT LIST partition +# +CREATE TABLE t1 (i INT) +PARTITION BY LIST (i) +(PARTITION p VALUES IN (1,2,3,4), +PARTITION pdef DEFAULT); +INSERT INTO t1 VALUES (1),(10); +ALTER TABLE t1 DROP PARTITION p; +SELECT * FROM t1; +i +10 +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `i` int(11) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 + PARTITION BY LIST (i) +(PARTITION pdef DEFAULT ENGINE = MyISAM) +DROP TABLE t1; +CREATE TABLE t1 (i INT) +PARTITION BY LIST (i) +(PARTITION p VALUES IN (1,2,3,4), +PARTITION pdef DEFAULT); +INSERT INTO t1 VALUES (1),(10); +ALTER TABLE t1 DROP PARTITION pdef; +SELECT * FROM t1; +i +1 +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `i` int(11) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 + PARTITION BY LIST (i) +(PARTITION p VALUES IN (1,2,3,4) ENGINE = MyISAM) +DROP TABLE t1; diff --git a/mysql-test/t/partition_default.test b/mysql-test/t/partition_default.test index 1110b311c2999..b0424f567e436 100644 --- a/mysql-test/t/partition_default.test +++ b/mysql-test/t/partition_default.test @@ -326,9 +326,6 @@ select partition_name, table_rows from INFORMATION_SCHEMA.PARTITIONS where table explain partitions select * from t1 where a=2 and b=5; explain partitions select * from t1 where a=10 and b=10; ---error ER_NO_PARTITION_FOR_GIVEN_VALUE -alter table t1 drop partition p2; -delete from t1 where a=2; alter table t1 drop partition p2; show create table t1; select * from t1; @@ -395,9 +392,6 @@ select partition_name, table_rows from INFORMATION_SCHEMA.PARTITIONS where table explain partitions select * from t1 where a=2 and b=5; explain partitions select * from t1 where a=10 and b=10; ---error ER_NO_PARTITION_FOR_GIVEN_VALUE -alter table t1 drop partition p2; -delete from t1 where a=2; alter table t1 drop partition p2; show create table t1; select * from t1; @@ -520,3 +514,29 @@ explain partitions select * from t1 where i is null; drop table t1; + + +--echo # +--echo # MDEV-12395: DROP PARTITION does not work as expected when +--echo # table has DEFAULT LIST partition +--echo # + +CREATE TABLE t1 (i INT) + PARTITION BY LIST (i) + (PARTITION p VALUES IN (1,2,3,4), + PARTITION pdef DEFAULT); +INSERT INTO t1 VALUES (1),(10); +ALTER TABLE t1 DROP PARTITION p; +SELECT * FROM t1; +SHOW CREATE TABLE t1; +DROP TABLE t1; + +CREATE TABLE t1 (i INT) + PARTITION BY LIST (i) + (PARTITION p VALUES IN (1,2,3,4), + PARTITION pdef DEFAULT); +INSERT INTO t1 VALUES (1),(10); +ALTER TABLE t1 DROP PARTITION pdef; +SELECT * FROM t1; +SHOW CREATE TABLE t1; +DROP TABLE t1; diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc index 4e71e792a0888..0a146aeb12beb 100644 --- a/sql/sql_partition.cc +++ b/sql/sql_partition.cc @@ -4842,8 +4842,7 @@ uint prep_alter_part_table(THD *thd, TABLE *table, Alter_info *alter_info, my_error(ER_PARTITION_FUNCTION_FAILURE, MYF(0)); goto err; } - if ((flags & (HA_FAST_CHANGE_PARTITION | HA_PARTITION_ONE_PHASE)) != 0 && - !tab_part_info->has_default_partititon()) + if ((flags & (HA_FAST_CHANGE_PARTITION | HA_PARTITION_ONE_PHASE)) != 0) { /* "Fast" change of partitioning is supported in this case.