From fa5e50943d782f27d85ca3aad8a6c841b14e78ff Mon Sep 17 00:00:00 2001 From: "mikael@c-4908e253.1238-1-64736c10.cust.bredbandsbolaget.se" <> Date: Tue, 11 Apr 2006 23:35:48 -0400 Subject: [PATCH 1/2] BUG#18962: DROP PARTITION fails when partitions dropped for subpartitions with default naming procedure Fixed naming procedures for default partitioning and default subpartitioning --- mysql-test/r/partition_pruning.result | 10 +++--- mysql-test/r/partition_range.result | 24 ++++++++++++++ mysql-test/t/partition_range.test | 28 ++++++++++++++++ sql/partition_info.cc | 48 ++++++++++++++++++++------- sql/partition_info.h | 2 +- 5 files changed, 94 insertions(+), 18 deletions(-) diff --git a/mysql-test/r/partition_pruning.result b/mysql-test/r/partition_pruning.result index 8b959cb6a3e..30a7f857a66 100644 --- a/mysql-test/r/partition_pruning.result +++ b/mysql-test/r/partition_pruning.result @@ -596,7 +596,7 @@ f_int1 NULL explain partitions select * from t1 where f_int1 is null; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 part4_p2sp0 system NULL NULL NULL NULL 1 +1 SIMPLE t1 part4_part4sp0 system NULL NULL NULL NULL 1 drop table t1; create table t1 (a int not null, b int not null) partition by list(a) @@ -625,16 +625,16 @@ insert into t1 values (1,1),(1,2),(1,3),(1,4), (2,1),(2,2),(2,3),(2,4), (NULL,1); explain partitions select * from t1 where a IS NULL AND (b=1 OR b=2); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 pn_p3sp0,pn_p3sp1 system NULL NULL NULL NULL 1 +1 SIMPLE t1 pn_pnsp0,pn_pnsp1 system NULL NULL NULL NULL 1 explain partitions select * from t1 where (a IS NULL or a < 1) AND (b=1 OR b=2); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 pn_p3sp0,pn_p3sp1 system NULL NULL NULL NULL 1 +1 SIMPLE t1 pn_pnsp0,pn_pnsp1 system NULL NULL NULL NULL 1 explain partitions select * from t1 where (a IS NULL or a < 2) AND (b=1 OR b=2); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p0_p0sp0,p0_p0sp1,pn_p3sp0,pn_p3sp1 ALL NULL NULL NULL NULL 5 Using where +1 SIMPLE t1 p0_p0sp0,p0_p0sp1,pn_pnsp0,pn_pnsp1 ALL NULL NULL NULL NULL 5 Using where explain partitions select * from t1 where (a IS NULL or a <= 1) AND (b=1 OR b=2); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p0_p0sp0,p0_p0sp1,pn_p3sp0,pn_p3sp1 ALL NULL NULL NULL NULL 5 Using where +1 SIMPLE t1 p0_p0sp0,p0_p0sp1,pn_pnsp0,pn_pnsp1 ALL NULL NULL NULL NULL 5 Using where drop table t1; create table t1 ( a int) partition by list (MOD(a, 10)) ( partition p0 values in (0), partition p1 values in (1), diff --git a/mysql-test/r/partition_range.result b/mysql-test/r/partition_range.result index fc9350f5902..c7257db4910 100644 --- a/mysql-test/r/partition_range.result +++ b/mysql-test/r/partition_range.result @@ -363,3 +363,27 @@ SELECT COUNT(*) FROM t1 WHERE c3 < '2000-12-31'; COUNT(*) 10 DROP TABLE t1; +create table t1 (a int) +partition by range (MOD(a,3)) +subpartition by hash(a) +subpartitions 2 +(partition p0 values less than (1), +partition p1 values less than (2), +partition p2 values less than (3), +partition p3 values less than (4)); +ALTER TABLE t1 DROP PARTITION p3; +ALTER TABLE t1 DROP PARTITION p1; +ALTER TABLE t1 DROP PARTITION p2; +drop table t1; +create table t1 (a int) +partition by range (MOD(a,3)) +subpartition by hash(a) +subpartitions 2 +(partition p0 values less than (1), +partition p1 values less than (2), +partition p2 values less than (3), +partition p3 values less than (4)); +ALTER TABLE t1 DROP PARTITION p0; +ALTER TABLE t1 DROP PARTITION p1; +ALTER TABLE t1 DROP PARTITION p2; +drop table t1; diff --git a/mysql-test/t/partition_range.test b/mysql-test/t/partition_range.test index a4d8c3740b7..ef539e2001f 100644 --- a/mysql-test/t/partition_range.test +++ b/mysql-test/t/partition_range.test @@ -388,3 +388,31 @@ SELECT COUNT(*) FROM t1 WHERE c3 BETWEEN '1996-12-31' AND '2000-12-31'; SELECT COUNT(*) FROM t1 WHERE c3 < '2000-12-31'; DROP TABLE t1; +# +# BUG 18962 Errors in DROP PARTITION +# +create table t1 (a int) +partition by range (MOD(a,3)) +subpartition by hash(a) +subpartitions 2 +(partition p0 values less than (1), + partition p1 values less than (2), + partition p2 values less than (3), + partition p3 values less than (4)); +ALTER TABLE t1 DROP PARTITION p3; +ALTER TABLE t1 DROP PARTITION p1; +ALTER TABLE t1 DROP PARTITION p2; +drop table t1; + +create table t1 (a int) +partition by range (MOD(a,3)) +subpartition by hash(a) +subpartitions 2 +(partition p0 values less than (1), + partition p1 values less than (2), + partition p2 values less than (3), + partition p3 values less than (4)); +ALTER TABLE t1 DROP PARTITION p0; +ALTER TABLE t1 DROP PARTITION p1; +ALTER TABLE t1 DROP PARTITION p2; +drop table t1; diff --git a/sql/partition_info.cc b/sql/partition_info.cc index ad0aa053ae2..8e0c50b9ffe 100644 --- a/sql/partition_info.cc +++ b/sql/partition_info.cc @@ -91,7 +91,7 @@ partition_info *partition_info::get_clone() #define MAX_PART_NAME_SIZE 16 char *partition_info::create_default_partition_names(uint part_no, uint no_parts, - uint start_no, bool is_subpart) + uint start_no) { char *ptr= sql_calloc(no_parts*MAX_PART_NAME_SIZE); char *move_ptr= ptr; @@ -102,10 +102,7 @@ char *partition_info::create_default_partition_names(uint part_no, uint no_parts { do { - if (is_subpart) - my_sprintf(move_ptr, (move_ptr,"p%usp%u", part_no, (start_no + i))); - else - my_sprintf(move_ptr, (move_ptr,"p%u", (start_no + i))); + my_sprintf(move_ptr, (move_ptr,"p%u", (start_no + i))); move_ptr+=MAX_PART_NAME_SIZE; } while (++i < no_parts); } @@ -117,6 +114,35 @@ char *partition_info::create_default_partition_names(uint part_no, uint no_parts } +/* + Create a unique name for the subpartition as part_name'sp''subpart_no' + SYNOPSIS + create_subpartition_name() + subpart_no Number of subpartition + part_name Name of partition + RETURN VALUES + >0 A reference to the created name string + 0 Memory allocation error +*/ + +char *create_subpartition_name(uint subpart_no, const char *part_name) +{ + uint size_alloc= strlen(part_name) + MAX_PART_NAME_SIZE; + char *ptr= sql_calloc(size_alloc); + DBUG_ENTER("create_subpartition_name"); + + if (likely(ptr != NULL)) + { + my_sprintf(ptr, (ptr, "%ssp%u", part_name, subpart_no)); + } + else + { + mem_alloc_error(size_alloc); + } + DBUG_RETURN(ptr); +} + + /* Set up all the default partitions not set-up by the user in the SQL statement. Also perform a number of checks that the user hasn't tried @@ -167,8 +193,7 @@ bool partition_info::set_up_default_partitions(handler *file, ulonglong max_rows goto end; } if (unlikely((!(default_name= create_default_partition_names(0, no_parts, - start_no, - FALSE))))) + start_no))))) goto end; i= 0; do @@ -238,18 +263,17 @@ bool partition_info::set_up_default_subpartitions(handler *file, { part_elem= part_it++; j= 0; - name_ptr= create_default_partition_names(i, no_subparts, (uint)0, TRUE); - if (unlikely(!name_ptr)) - goto end; do { partition_element *subpart_elem= new partition_element(); if (likely(subpart_elem != 0 && (!part_elem->subpartitions.push_back(subpart_elem)))) { + char *ptr= create_subpartition_name(j, part_elem->partition_name); + if (!ptr) + goto end; subpart_elem->engine_type= default_engine_type; - subpart_elem->partition_name= name_ptr; - name_ptr+= MAX_PART_NAME_SIZE; + subpart_elem->partition_name= ptr; } else { diff --git a/sql/partition_info.h b/sql/partition_info.h index 664c8834b0b..ecba048c486 100644 --- a/sql/partition_info.h +++ b/sql/partition_info.h @@ -256,7 +256,7 @@ private: uint start_no); bool set_up_default_subpartitions(handler *file, ulonglong max_rows); char *create_default_partition_names(uint part_no, uint no_parts, - uint start_no, bool is_subpart); + uint start_no); bool has_unique_name(partition_element *element); }; From fe46ee911180b796e71faccb8f9470d374a665a6 Mon Sep 17 00:00:00 2001 From: "mikael@c-870ae253.1238-1-64736c10.cust.bredbandsbolaget.se" <> Date: Fri, 21 Apr 2006 08:37:09 -0400 Subject: [PATCH 2/2] BUG#18962: Crash of ALTER TABLE .. DROP PARTITION ... Review fixes --- sql/partition_info.cc | 5 +++-- sql/partition_info.h | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/sql/partition_info.cc b/sql/partition_info.cc index bb1e9eeb905..dfc5dd2989b 100644 --- a/sql/partition_info.cc +++ b/sql/partition_info.cc @@ -88,7 +88,7 @@ partition_info *partition_info::get_clone() The external routine needing this code is check_partition_info */ -#define MAX_PART_NAME_SIZE 16 +#define MAX_PART_NAME_SIZE 8 char *partition_info::create_default_partition_names(uint part_no, uint no_parts, uint start_no) @@ -125,7 +125,8 @@ char *partition_info::create_default_partition_names(uint part_no, uint no_parts 0 Memory allocation error */ -char *create_subpartition_name(uint subpart_no, const char *part_name) +char *partition_info::create_subpartition_name(uint subpart_no, + const char *part_name) { uint size_alloc= strlen(part_name) + MAX_PART_NAME_SIZE; char *ptr= sql_calloc(size_alloc); diff --git a/sql/partition_info.h b/sql/partition_info.h index ecba048c486..ae95b4a339f 100644 --- a/sql/partition_info.h +++ b/sql/partition_info.h @@ -257,6 +257,7 @@ private: bool set_up_default_subpartitions(handler *file, ulonglong max_rows); char *create_default_partition_names(uint part_no, uint no_parts, uint start_no); + char *create_subpartition_name(uint subpart_no, const char *part_name); bool has_unique_name(partition_element *element); };