Skip to content

Commit d9484a2

Browse files
committed
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
1 parent 27f6b11 commit d9484a2

File tree

3 files changed

+67
-16
lines changed

3 files changed

+67
-16
lines changed

mysql-test/r/partition_default.result

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -921,9 +921,6 @@ explain partitions select * from t1 where a=10 and b=10;
921921
id select_type table partitions type possible_keys key key_len ref rows Extra
922922
1 SIMPLE t1 p0 system NULL NULL NULL NULL 1
923923
alter table t1 drop partition p2;
924-
ERROR HY000: Table has no partition for value 2
925-
delete from t1 where a=2;
926-
alter table t1 drop partition p2;
927924
show create table t1;
928925
Table Create Table
929926
t1 CREATE TABLE `t1` (
@@ -1069,9 +1066,6 @@ explain partitions select * from t1 where a=10 and b=10;
10691066
id select_type table partitions type possible_keys key key_len ref rows Extra
10701067
1 SIMPLE t1 p0 system NULL NULL NULL NULL 1
10711068
alter table t1 drop partition p2;
1072-
ERROR HY000: Table has no partition for value from column_list
1073-
delete from t1 where a=2;
1074-
alter table t1 drop partition p2;
10751069
show create table t1;
10761070
Table Create Table
10771071
t1 CREATE TABLE `t1` (
@@ -1125,10 +1119,10 @@ alter table t1 add partition
11251119
(partition p0 VALUES IN (2,3));
11261120
select partition_name, table_rows from INFORMATION_SCHEMA.PARTITIONS where table_name='t1';
11271121
partition_name table_rows
1128-
p0 2
1122+
p0 0
11291123
p1 1
11301124
p2 1
1131-
pd 0
1125+
pd 2
11321126
drop table t1;
11331127
create table t1 (a int, b int)
11341128
PARTITION BY LIST COLUMNS(a,b)
@@ -1233,3 +1227,41 @@ select * from t1 where i is null;
12331227
id select_type table partitions type possible_keys key key_len ref rows Extra
12341228
1 SIMPLE t1 p0 system NULL NULL NULL NULL 1
12351229
drop table t1;
1230+
#
1231+
# MDEV-12395: DROP PARTITION does not work as expected when
1232+
# table has DEFAULT LIST partition
1233+
#
1234+
CREATE TABLE t1 (i INT)
1235+
PARTITION BY LIST (i)
1236+
(PARTITION p VALUES IN (1,2,3,4),
1237+
PARTITION pdef DEFAULT);
1238+
INSERT INTO t1 VALUES (1),(10);
1239+
ALTER TABLE t1 DROP PARTITION p;
1240+
SELECT * FROM t1;
1241+
i
1242+
10
1243+
SHOW CREATE TABLE t1;
1244+
Table Create Table
1245+
t1 CREATE TABLE `t1` (
1246+
`i` int(11) DEFAULT NULL
1247+
) ENGINE=MyISAM DEFAULT CHARSET=latin1
1248+
PARTITION BY LIST (i)
1249+
(PARTITION pdef DEFAULT ENGINE = MyISAM)
1250+
DROP TABLE t1;
1251+
CREATE TABLE t1 (i INT)
1252+
PARTITION BY LIST (i)
1253+
(PARTITION p VALUES IN (1,2,3,4),
1254+
PARTITION pdef DEFAULT);
1255+
INSERT INTO t1 VALUES (1),(10);
1256+
ALTER TABLE t1 DROP PARTITION pdef;
1257+
SELECT * FROM t1;
1258+
i
1259+
1
1260+
SHOW CREATE TABLE t1;
1261+
Table Create Table
1262+
t1 CREATE TABLE `t1` (
1263+
`i` int(11) DEFAULT NULL
1264+
) ENGINE=MyISAM DEFAULT CHARSET=latin1
1265+
PARTITION BY LIST (i)
1266+
(PARTITION p VALUES IN (1,2,3,4) ENGINE = MyISAM)
1267+
DROP TABLE t1;

mysql-test/t/partition_default.test

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -326,9 +326,6 @@ select partition_name, table_rows from INFORMATION_SCHEMA.PARTITIONS where table
326326
explain partitions select * from t1 where a=2 and b=5;
327327
explain partitions select * from t1 where a=10 and b=10;
328328

329-
--error ER_NO_PARTITION_FOR_GIVEN_VALUE
330-
alter table t1 drop partition p2;
331-
delete from t1 where a=2;
332329
alter table t1 drop partition p2;
333330
show create table t1;
334331
select * from t1;
@@ -395,9 +392,6 @@ select partition_name, table_rows from INFORMATION_SCHEMA.PARTITIONS where table
395392
explain partitions select * from t1 where a=2 and b=5;
396393
explain partitions select * from t1 where a=10 and b=10;
397394

398-
--error ER_NO_PARTITION_FOR_GIVEN_VALUE
399-
alter table t1 drop partition p2;
400-
delete from t1 where a=2;
401395
alter table t1 drop partition p2;
402396
show create table t1;
403397
select * from t1;
@@ -520,3 +514,29 @@ explain partitions
520514
select * from t1 where i is null;
521515

522516
drop table t1;
517+
518+
519+
--echo #
520+
--echo # MDEV-12395: DROP PARTITION does not work as expected when
521+
--echo # table has DEFAULT LIST partition
522+
--echo #
523+
524+
CREATE TABLE t1 (i INT)
525+
PARTITION BY LIST (i)
526+
(PARTITION p VALUES IN (1,2,3,4),
527+
PARTITION pdef DEFAULT);
528+
INSERT INTO t1 VALUES (1),(10);
529+
ALTER TABLE t1 DROP PARTITION p;
530+
SELECT * FROM t1;
531+
SHOW CREATE TABLE t1;
532+
DROP TABLE t1;
533+
534+
CREATE TABLE t1 (i INT)
535+
PARTITION BY LIST (i)
536+
(PARTITION p VALUES IN (1,2,3,4),
537+
PARTITION pdef DEFAULT);
538+
INSERT INTO t1 VALUES (1),(10);
539+
ALTER TABLE t1 DROP PARTITION pdef;
540+
SELECT * FROM t1;
541+
SHOW CREATE TABLE t1;
542+
DROP TABLE t1;

sql/sql_partition.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4842,8 +4842,7 @@ uint prep_alter_part_table(THD *thd, TABLE *table, Alter_info *alter_info,
48424842
my_error(ER_PARTITION_FUNCTION_FAILURE, MYF(0));
48434843
goto err;
48444844
}
4845-
if ((flags & (HA_FAST_CHANGE_PARTITION | HA_PARTITION_ONE_PHASE)) != 0 &&
4846-
!tab_part_info->has_default_partititon())
4845+
if ((flags & (HA_FAST_CHANGE_PARTITION | HA_PARTITION_ONE_PHASE)) != 0)
48474846
{
48484847
/*
48494848
"Fast" change of partitioning is supported in this case.

0 commit comments

Comments
 (0)