From de26416468c3915ec1363d6e95e6a4302846641c Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 20 Mar 2006 17:41:45 +0400 Subject: [PATCH 1/2] Bug#14367 Partitions: crash if utf8 column use part_info->item_free_list instead of thd->free_list during partition function parsing mysql-test/r/partition.result: Bug#14367 Partitions: crash if utf8 column test case mysql-test/t/partition.test: Bug#14367 Partitions: crash if utf8 column test case sql/item.cc: Bug#14367 Partitions: crash if utf8 column create copy of string in current mem_root to avoid memory leak --- mysql-test/r/partition.result | 5 +++++ mysql-test/t/partition.test | 9 +++++++++ sql/item.cc | 5 ++++- sql/sql_partition.cc | 3 +++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/partition.result b/mysql-test/r/partition.result index f31692bea0a..2532975e3cb 100644 --- a/mysql-test/r/partition.result +++ b/mysql-test/r/partition.result @@ -557,4 +557,9 @@ t2 CREATE TABLE `t2` ( PRIMARY KEY (`a`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='no comment' PARTITION BY KEY (a) drop table t2; +create table t1 (s1 char(2) character set utf8) +partition by list (case when s1 > 'cz' then 1 else 2 end) +(partition p1 values in (1), +partition p2 values in (2)); +drop table t1; End of 5.1 tests diff --git a/mysql-test/t/partition.test b/mysql-test/t/partition.test index 73949733426..254a64c7c9e 100644 --- a/mysql-test/t/partition.test +++ b/mysql-test/t/partition.test @@ -714,4 +714,13 @@ show create table t2; drop table t2; +# +# Bug#14367: Partitions: crash if utf8 column +# +create table t1 (s1 char(2) character set utf8) +partition by list (case when s1 > 'cz' then 1 else 2 end) +(partition p1 values in (1), + partition p2 values in (2)); +drop table t1; + --echo End of 5.1 tests diff --git a/sql/item.cc b/sql/item.cc index cf59c0bad9e..a734984a496 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -647,6 +647,7 @@ Item *Item_string::safe_charset_converter(CHARSET_INFO *tocs) { Item_string *conv; uint conv_errors; + char *ptr; String tmp, cstr, *ostr= val_str(&tmp); cstr.copy(ostr->ptr(), ostr->length(), ostr->charset(), tocs, &conv_errors); if (conv_errors || !(conv= new Item_string(cstr.ptr(), cstr.length(), @@ -661,7 +662,9 @@ Item *Item_string::safe_charset_converter(CHARSET_INFO *tocs) */ return NULL; } - conv->str_value.copy(); + if (!(ptr= current_thd->memdup(cstr.ptr(), cstr.length() + 1 ))) + return NULL; + conv->str_value.set(ptr, cstr.length(), cstr.charset()); /* Ensure that no one is going to change the result string */ conv->str_value.mark_as_const(); return conv; diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc index 03fa046094a..bb2db2c5da4 100644 --- a/sql/sql_partition.cc +++ b/sql/sql_partition.cc @@ -1710,6 +1710,7 @@ bool fix_partition_func(THD *thd, const char* name, TABLE *table, char* db_name; partition_info *part_info= table->part_info; ulong save_set_query_id= thd->set_query_id; + Item *thd_free_list= thd->free_list; DBUG_ENTER("fix_partition_func"); if (part_info->fixed) @@ -1744,6 +1745,7 @@ bool fix_partition_func(THD *thd, const char* name, TABLE *table, DBUG_RETURN(TRUE); } } + thd->free_list= part_info->item_free_list; if (part_info->is_sub_partitioned()) { DBUG_ASSERT(part_info->subpart_type == HASH_PARTITION); @@ -1853,6 +1855,7 @@ bool fix_partition_func(THD *thd, const char* name, TABLE *table, set_up_range_analysis_info(part_info); result= FALSE; end: + thd->free_list= thd_free_list; thd->set_query_id= save_set_query_id; DBUG_PRINT("info", ("thd->set_query_id: %d", thd->set_query_id)); DBUG_RETURN(result); From 91eac0bdc3b212967f73e221463e8173686863ca Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 20 Mar 2006 18:58:21 +0400 Subject: [PATCH 2/2] Fix for bug#15336 Partitions: crash if create table as select added HA_EXTRA_WRITE_CACHE case to ha_partition::extra() mysql-test/r/partition.result: Fix for bug#15336 Partitions: crash if create table as select test case mysql-test/t/partition.test: Fix for bug#15336 Partitions: crash if create table as select test case --- mysql-test/r/partition.result | 2 ++ mysql-test/t/partition.test | 6 ++++++ sql/ha_partition.cc | 1 + 3 files changed, 9 insertions(+) diff --git a/mysql-test/r/partition.result b/mysql-test/r/partition.result index 2532975e3cb..b5b6235c799 100644 --- a/mysql-test/r/partition.result +++ b/mysql-test/r/partition.result @@ -562,4 +562,6 @@ partition by list (case when s1 > 'cz' then 1 else 2 end) (partition p1 values in (1), partition p2 values in (2)); drop table t1; +create table t1 (f1 int) partition by hash (f1) as select 1; +drop table t1; End of 5.1 tests diff --git a/mysql-test/t/partition.test b/mysql-test/t/partition.test index 254a64c7c9e..20b55531177 100644 --- a/mysql-test/t/partition.test +++ b/mysql-test/t/partition.test @@ -723,4 +723,10 @@ partition by list (case when s1 > 'cz' then 1 else 2 end) partition p2 values in (2)); drop table t1; +# +# Bug#15336 Partitions: crash if create table as select +# +create table t1 (f1 int) partition by hash (f1) as select 1; +drop table t1; + --echo End of 5.1 tests diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index b5b33668ba0..b6dceb8f690 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -4703,6 +4703,7 @@ int ha_partition::extra(enum ha_extra_function operation) break; } case HA_EXTRA_NO_CACHE: + case HA_EXTRA_WRITE_CACHE: { m_extra_cache= FALSE; m_extra_cache_size= 0;