Skip to content

Commit 9b53e54

Browse files
author
Alexander Barkov
committed
MDEV-13788 Server crash when issuing bad SQL partition syntax
1 parent c44ece7 commit 9b53e54

11 files changed

+165
-20
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--echo #
2+
--echo # MDEV-13788 Server crash when issuing bad SQL partition syntax
3+
--echo #
4+
5+
--eval CREATE TABLE t1 (id int, d date) ENGINE=$engine PARTITION BY RANGE COLUMNS(d) (PARTITION p1 VALUES LESS THAN (MAXVALUE))
6+
SHOW CREATE TABLE t1;
7+
--error ER_PARTITION_REQUIRES_VALUES_ERROR
8+
ALTER TABLE t1 REORGANIZE PARTITION p1 INTO
9+
(
10+
PARTITION p2, /* Notice no values */
11+
PARTITION p3 VALUES LESS THAN (MAXVALUE)
12+
);
13+
DROP TABLE t1;
14+
15+
16+
--eval CREATE TABLE t1 (id int, d date) ENGINE=$engine PARTITION BY LIST (id) (PARTITION p1 VALUES IN (1,2,3))
17+
SHOW CREATE TABLE t1;
18+
--error ER_PARTITION_REQUIRES_VALUES_ERROR
19+
ALTER TABLE t1 REORGANIZE PARTITION p1 INTO
20+
(
21+
PARTITION p2, /* Notice no values */
22+
PARTITION p3 VALUES IN (4,5,6)
23+
);
24+
DROP TABLE t1;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#
2+
# MDEV-13788 Server crash when issuing bad SQL partition syntax
3+
#
4+
CREATE TABLE t1 (id int, d date) ENGINE=InnoDB PARTITION BY RANGE COLUMNS(d) (PARTITION p1 VALUES LESS THAN (MAXVALUE));
5+
SHOW CREATE TABLE t1;
6+
Table Create Table
7+
t1 CREATE TABLE `t1` (
8+
`id` int(11) DEFAULT NULL,
9+
`d` date DEFAULT NULL
10+
) ENGINE=InnoDB DEFAULT CHARSET=latin1
11+
/*!50500 PARTITION BY RANGE COLUMNS(d)
12+
(PARTITION p1 VALUES LESS THAN (MAXVALUE) ENGINE = InnoDB) */
13+
ALTER TABLE t1 REORGANIZE PARTITION p1 INTO
14+
(
15+
PARTITION p2, /* Notice no values */
16+
PARTITION p3 VALUES LESS THAN (MAXVALUE)
17+
);
18+
ERROR HY000: Syntax error: RANGE PARTITIONING requires definition of VALUES LESS THAN for each partition
19+
DROP TABLE t1;
20+
CREATE TABLE t1 (id int, d date) ENGINE=InnoDB PARTITION BY LIST (id) (PARTITION p1 VALUES IN (1,2,3));
21+
SHOW CREATE TABLE t1;
22+
Table Create Table
23+
t1 CREATE TABLE `t1` (
24+
`id` int(11) DEFAULT NULL,
25+
`d` date DEFAULT NULL
26+
) ENGINE=InnoDB DEFAULT CHARSET=latin1
27+
/*!50100 PARTITION BY LIST (id)
28+
(PARTITION p1 VALUES IN (1,2,3) ENGINE = InnoDB) */
29+
ALTER TABLE t1 REORGANIZE PARTITION p1 INTO
30+
(
31+
PARTITION p2, /* Notice no values */
32+
PARTITION p3 VALUES IN (4,5,6)
33+
);
34+
ERROR HY000: Syntax error: LIST PARTITIONING requires definition of VALUES IN for each partition
35+
DROP TABLE t1;

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,38 @@ select * from t1;
1616
pk dt
1717
1 2017-09-28 15:12:00
1818
drop table t1;
19+
#
20+
# MDEV-13788 Server crash when issuing bad SQL partition syntax
21+
#
22+
CREATE TABLE t1 (id int, d date) ENGINE=Aria PARTITION BY RANGE COLUMNS(d) (PARTITION p1 VALUES LESS THAN (MAXVALUE));
23+
SHOW CREATE TABLE t1;
24+
Table Create Table
25+
t1 CREATE TABLE `t1` (
26+
`id` int(11) DEFAULT NULL,
27+
`d` date DEFAULT NULL
28+
) ENGINE=Aria DEFAULT CHARSET=latin1
29+
/*!50500 PARTITION BY RANGE COLUMNS(d)
30+
(PARTITION p1 VALUES LESS THAN (MAXVALUE) ENGINE = Aria) */
31+
ALTER TABLE t1 REORGANIZE PARTITION p1 INTO
32+
(
33+
PARTITION p2, /* Notice no values */
34+
PARTITION p3 VALUES LESS THAN (MAXVALUE)
35+
);
36+
ERROR HY000: Syntax error: RANGE PARTITIONING requires definition of VALUES LESS THAN for each partition
37+
DROP TABLE t1;
38+
CREATE TABLE t1 (id int, d date) ENGINE=Aria PARTITION BY LIST (id) (PARTITION p1 VALUES IN (1,2,3));
39+
SHOW CREATE TABLE t1;
40+
Table Create Table
41+
t1 CREATE TABLE `t1` (
42+
`id` int(11) DEFAULT NULL,
43+
`d` date DEFAULT NULL
44+
) ENGINE=Aria DEFAULT CHARSET=latin1
45+
/*!50100 PARTITION BY LIST (id)
46+
(PARTITION p1 VALUES IN (1,2,3) ENGINE = Aria) */
47+
ALTER TABLE t1 REORGANIZE PARTITION p1 INTO
48+
(
49+
PARTITION p2, /* Notice no values */
50+
PARTITION p3 VALUES IN (4,5,6)
51+
);
52+
ERROR HY000: Syntax error: LIST PARTITIONING requires definition of VALUES IN for each partition
53+
DROP TABLE t1;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#
2+
# MDEV-13788 Server crash when issuing bad SQL partition syntax
3+
#
4+
CREATE TABLE t1 (id int, d date) ENGINE=MyISAM PARTITION BY RANGE COLUMNS(d) (PARTITION p1 VALUES LESS THAN (MAXVALUE));
5+
SHOW CREATE TABLE t1;
6+
Table Create Table
7+
t1 CREATE TABLE `t1` (
8+
`id` int(11) DEFAULT NULL,
9+
`d` date DEFAULT NULL
10+
) ENGINE=MyISAM DEFAULT CHARSET=latin1
11+
/*!50500 PARTITION BY RANGE COLUMNS(d)
12+
(PARTITION p1 VALUES LESS THAN (MAXVALUE) ENGINE = MyISAM) */
13+
ALTER TABLE t1 REORGANIZE PARTITION p1 INTO
14+
(
15+
PARTITION p2, /* Notice no values */
16+
PARTITION p3 VALUES LESS THAN (MAXVALUE)
17+
);
18+
ERROR HY000: Syntax error: RANGE PARTITIONING requires definition of VALUES LESS THAN for each partition
19+
DROP TABLE t1;
20+
CREATE TABLE t1 (id int, d date) ENGINE=MyISAM PARTITION BY LIST (id) (PARTITION p1 VALUES IN (1,2,3));
21+
SHOW CREATE TABLE t1;
22+
Table Create Table
23+
t1 CREATE TABLE `t1` (
24+
`id` int(11) DEFAULT NULL,
25+
`d` date DEFAULT NULL
26+
) ENGINE=MyISAM DEFAULT CHARSET=latin1
27+
/*!50100 PARTITION BY LIST (id)
28+
(PARTITION p1 VALUES IN (1,2,3) ENGINE = MyISAM) */
29+
ALTER TABLE t1 REORGANIZE PARTITION p1 INTO
30+
(
31+
PARTITION p2, /* Notice no values */
32+
PARTITION p3 VALUES IN (4,5,6)
33+
);
34+
ERROR HY000: Syntax error: LIST PARTITIONING requires definition of VALUES IN for each partition
35+
DROP TABLE t1;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
--source include/have_innodb.inc
2+
--source include/have_partition.inc
3+
--let $engine=InnoDB
4+
--source inc/part_alter_values.inc

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@ select * from t1;
1616
alter table t1 drop partition p20181231;
1717
select * from t1;
1818
drop table t1;
19+
20+
--let $engine=Aria
21+
--source inc/part_alter_values.inc
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
--source include/have_partition.inc
2+
--let $engine=MyISAM
3+
--source inc/part_alter_values.inc

sql/partition_info.cc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2132,6 +2132,24 @@ bool partition_info::fix_column_value_functions(THD *thd,
21322132
DBUG_RETURN(result);
21332133
}
21342134

2135+
2136+
bool partition_info::error_if_requires_values() const
2137+
{
2138+
switch (part_type) {
2139+
case NOT_A_PARTITION:
2140+
case HASH_PARTITION:
2141+
break;
2142+
case RANGE_PARTITION:
2143+
my_error(ER_PARTITION_REQUIRES_VALUES_ERROR, MYF(0), "RANGE", "LESS THAN");
2144+
return true;
2145+
case LIST_PARTITION:
2146+
my_error(ER_PARTITION_REQUIRES_VALUES_ERROR, MYF(0), "LIST", "IN");
2147+
return true;
2148+
}
2149+
return false;
2150+
}
2151+
2152+
21352153
/*
21362154
The parser generates generic data structures, we need to set them up
21372155
as the rest of the code expects to find them. This is in reality part
@@ -2221,6 +2239,8 @@ int partition_info::fix_parser_data(THD *thd)
22212239
part_elem= it++;
22222240
List_iterator<part_elem_value> list_val_it(part_elem->list_val_list);
22232241
num_elements= part_elem->list_val_list.elements;
2242+
if (!num_elements && error_if_requires_values())
2243+
DBUG_RETURN(true);
22242244
DBUG_ASSERT(part_type == RANGE_PARTITION ?
22252245
num_elements == 1U : TRUE);
22262246
for (j= 0; j < num_elements; j++)

sql/partition_info.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ class partition_info : public Sql_alloc
313313
void set_show_version_string(String *packet);
314314
void report_part_expr_error(bool use_subpart_expr);
315315
bool has_same_partitioning(partition_info *new_part_info);
316+
bool error_if_requires_values() const;
316317
private:
317318
static int list_part_cmp(const void* a, const void* b);
318319
bool set_up_default_partitions(handler *file, HA_CREATE_INFO *info,

sql/sql_partition.cc

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4770,16 +4770,11 @@ uint prep_alter_part_table(THD *thd, TABLE *table, Alter_info *alter_info,
47704770
my_error(ER_PARTITION_WRONG_VALUES_ERROR, MYF(0),
47714771
"LIST", "IN");
47724772
}
4773-
else if (tab_part_info->part_type == RANGE_PARTITION)
4774-
{
4775-
my_error(ER_PARTITION_REQUIRES_VALUES_ERROR, MYF(0),
4776-
"RANGE", "LESS THAN");
4777-
}
47784773
else
47794774
{
4780-
DBUG_ASSERT(tab_part_info->part_type == LIST_PARTITION);
4781-
my_error(ER_PARTITION_REQUIRES_VALUES_ERROR, MYF(0),
4782-
"LIST", "IN");
4775+
DBUG_ASSERT(tab_part_info->part_type == RANGE_PARTITION ||
4776+
tab_part_info->part_type == LIST_PARTITION);
4777+
(void) tab_part_info->error_if_requires_values();
47834778
}
47844779
goto err;
47854780
}

0 commit comments

Comments
 (0)