From b7b8fd256940e6ed9a59eb19e88dfe8e0368736b Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 9 Mar 2006 18:19:34 +0100 Subject: [PATCH 1/2] BUG#17127: Crash if wrong use of VALUES for list partition mysql-test/r/partition.result: Added a number of new test cases where errors in use of VALUES LESS THAN and VALUES IN is happening for ALTER TABLE mysql-test/t/partition.test: Added a number of new test cases where errors in use of VALUES LESS THAN and VALUES IN is happening for ALTER TABLE sql/sql_partition.cc: Check for errors with VALUES * sql/sql_yacc.yy: Add state to part_type when doing ALTER TABLE for partitioning --- mysql-test/r/partition.result | 24 +++++++++++++++++++++++ mysql-test/t/partition.test | 36 +++++++++++++++++++++++++++++++++++ sql/sql_partition.cc | 28 +++++++++++++++++++++++++++ sql/sql_yacc.yy | 6 ++++++ 4 files changed, 94 insertions(+) diff --git a/mysql-test/r/partition.result b/mysql-test/r/partition.result index 59e29046d90..5123b9c3932 100644 --- a/mysql-test/r/partition.result +++ b/mysql-test/r/partition.result @@ -422,4 +422,28 @@ partition_name partition_description table_rows x123 11,12 1 x234 NULL,1 1 drop table t1; +create table t1 (a int) +partition by range (a) +(partition p0 values less than (1)); +alter table t1 add partition (partition p1 values in (2)); +ERROR HY000: Only LIST PARTITIONING can use VALUES IN in partition definition +alter table t1 add partition (partition p1); +ERROR HY000: RANGE PARTITIONING requires definition of VALUES LESS THAN for each partition +drop table t1; +create table t1 (a int) +partition by list (a) +(partition p0 values in (1)); +alter table t1 add partition (partition p1 values less than (2)); +ERROR HY000: Only RANGE PARTITIONING can use VALUES LESS THAN in partition definition +alter table t1 add partition (partition p1); +ERROR HY000: LIST PARTITIONING requires definition of VALUES IN for each partition +drop table t1; +create table t1 (a int) +partition by hash (a) +(partition p0); +alter table t1 add partition (partition p1 values less than (2)); +ERROR HY000: Only RANGE PARTITIONING can use VALUES LESS THAN in partition definition +alter table t1 add partition (partition p1 values in (2)); +ERROR HY000: Only LIST PARTITIONING can use VALUES IN in partition definition +drop table t1; End of 5.1 tests diff --git a/mysql-test/t/partition.test b/mysql-test/t/partition.test index f22edb54756..c8be4a30f6e 100644 --- a/mysql-test/t/partition.test +++ b/mysql-test/t/partition.test @@ -540,4 +540,40 @@ select partition_name, partition_description, table_rows from information_schema.partitions where table_schema ='test'; drop table t1; +# +# Bug 17127 +# +create table t1 (a int) +partition by range (a) +(partition p0 values less than (1)); + +--error ER_PARTITION_WRONG_VALUES_ERROR +alter table t1 add partition (partition p1 values in (2)); +--error ER_PARTITION_REQUIRES_VALUES_ERROR +alter table t1 add partition (partition p1); + +drop table t1; + +create table t1 (a int) +partition by list (a) +(partition p0 values in (1)); + +--error ER_PARTITION_WRONG_VALUES_ERROR +alter table t1 add partition (partition p1 values less than (2)); +--error ER_PARTITION_REQUIRES_VALUES_ERROR +alter table t1 add partition (partition p1); + +drop table t1; + +create table t1 (a int) +partition by hash (a) +(partition p0); + +--error ER_PARTITION_WRONG_VALUES_ERROR +alter table t1 add partition (partition p1 values less than (2)); +--error ER_PARTITION_WRONG_VALUES_ERROR +alter table t1 add partition (partition p1 values in (2)); + +drop table t1; + --echo End of 5.1 tests diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc index 257c1988cbd..7cb3c391e11 100644 --- a/sql/sql_partition.cc +++ b/sql/sql_partition.cc @@ -4132,6 +4132,34 @@ uint prep_alter_part_table(THD *thd, TABLE *table, ALTER_INFO *alter_info, ((flags & (HA_FAST_CHANGE_PARTITION | HA_PARTITION_ONE_PHASE)) != 0); DBUG_PRINT("info", ("*fast_alter_partition: %d flags: 0x%x", *fast_alter_partition, flags)); + if (((alter_info->flags & ALTER_ADD_PARTITION) || + (alter_info->flags & ALTER_REORGANIZE_PARTITION)) && + (thd->lex->part_info->part_type != tab_part_info->part_type)) + { + if (thd->lex->part_info->part_type == RANGE_PARTITION) + { + my_error(ER_PARTITION_WRONG_VALUES_ERROR, MYF(0), + "RANGE", "LESS THAN"); + } + else if (thd->lex->part_info->part_type == LIST_PARTITION) + { + DBUG_ASSERT(thd->lex->part_info->part_type == LIST_PARTITION); + my_error(ER_PARTITION_WRONG_VALUES_ERROR, MYF(0), + "LIST", "IN"); + } + else if (tab_part_info->part_type == RANGE_PARTITION) + { + my_error(ER_PARTITION_REQUIRES_VALUES_ERROR, MYF(0), + "RANGE", "LESS THAN"); + } + else + { + DBUG_ASSERT(tab_part_info->part_type == LIST_PARTITION); + my_error(ER_PARTITION_REQUIRES_VALUES_ERROR, MYF(0), + "LIST", "IN"); + } + DBUG_RETURN(TRUE); + } if (alter_info->flags & ALTER_ADD_PARTITION) { /* diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index a64886d503d..88ed9ff68ca 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -3734,6 +3734,8 @@ opt_part_values: YYABORT; } } + else + lex->part_info->part_type= HASH_PARTITION; } | VALUES LESS_SYM THAN_SYM part_func_max { @@ -3747,6 +3749,8 @@ opt_part_values: YYABORT; } } + else + lex->part_info->part_type= RANGE_PARTITION; } | VALUES IN_SYM '(' part_list_func ')' { @@ -3760,6 +3764,8 @@ opt_part_values: YYABORT; } } + else + lex->part_info->part_type= LIST_PARTITION; } ; From c71dd8c1459fe0f6cd3d90bd034f50ed666175d8 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 14 Mar 2006 01:39:27 -0800 Subject: [PATCH 2/2] Manual merge --- mysql-test/r/partition.result | 2 ++ sql/sql_partition.cc | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/partition.result b/mysql-test/r/partition.result index add9a3474af..e0b344849a7 100644 --- a/mysql-test/r/partition.result +++ b/mysql-test/r/partition.result @@ -445,6 +445,8 @@ alter table t1 add partition (partition p1 values less than (2)); ERROR HY000: Only RANGE PARTITIONING can use VALUES LESS THAN in partition definition alter table t1 add partition (partition p1 values in (2)); ERROR HY000: Only LIST PARTITIONING can use VALUES IN in partition definition +drop table t1; +create table t1 (a int) partition by list (a) (partition p0 values in (1)); alter table t1 rebuild partition; diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc index 254c6c753e2..0d550d6e5ad 100644 --- a/sql/sql_partition.cc +++ b/sql/sql_partition.cc @@ -4135,7 +4135,8 @@ uint prep_alter_part_table(THD *thd, TABLE *table, ALTER_INFO *alter_info, *fast_alter_partition, flags)); if (((alter_info->flags & ALTER_ADD_PARTITION) || (alter_info->flags & ALTER_REORGANIZE_PARTITION)) && - (thd->lex->part_info->part_type != tab_part_info->part_type)) + (thd->lex->part_info->part_type != tab_part_info->part_type) && + (thd->lex->part_info->part_type != NOT_A_PARTITION)) { if (thd->lex->part_info->part_type == RANGE_PARTITION) {