Skip to content

Commit

Permalink
MDEV-12395: DROP PARTITION does not work as expected when table has D…
Browse files Browse the repository at this point in the history
…EFAULT LIST partition

Data loss in case of partituon removing is documented => do not try to prevent it
  • Loading branch information
sanja-byelkin committed Apr 7, 2017
1 parent 27f6b11 commit d9484a2
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 16 deletions.
48 changes: 40 additions & 8 deletions mysql-test/r/partition_default.result
Expand Up @@ -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` (
Expand Down Expand Up @@ -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` (
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
32 changes: 26 additions & 6 deletions mysql-test/t/partition_default.test
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
3 changes: 1 addition & 2 deletions sql/sql_partition.cc
Expand Up @@ -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.
Expand Down

0 comments on commit d9484a2

Please sign in to comment.