From 1a963822c80ada2ea82a8a07c09870070fb6a820 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Thu, 17 Mar 2011 22:38:34 +0100 Subject: [PATCH] lp:737104 Crash in DTCollation::set in 5.1-micro and a different fix for lp:736370 cache temporal expression in Item_cache_int, not in Item_string. invoke get_datetime_value() to create a correct Item_cache_int. Implement Item_cache_int::clone, as it's a proper constant --- mysql-test/r/func_time.result | 4 ++++ mysql-test/t/func_time.test | 8 +++++++- sql/item.cc | 9 ++++++++- sql/item.h | 6 ++++++ 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/func_time.result b/mysql-test/r/func_time.result index 94bca821504..67d14ee1c07 100644 --- a/mysql-test/r/func_time.result +++ b/mysql-test/r/func_time.result @@ -1497,3 +1497,7 @@ drop table t1; select now() > coalesce(time('21:43:24'), date('2010-05-03')); now() > coalesce(time('21:43:24'), date('2010-05-03')) 1 +create table t1 (f1 timestamp); +select * from t1 where f1 > f1 and f1 <=> timestampadd(hour, 9 , '2010-01-01 16:55:35'); +f1 +drop table t1; diff --git a/mysql-test/t/func_time.test b/mysql-test/t/func_time.test index d21462ff09b..7c4c24f937d 100644 --- a/mysql-test/t/func_time.test +++ b/mysql-test/t/func_time.test @@ -926,7 +926,7 @@ select * from t1 where 1 and concat(f2)=MAKEDATE(2011, 125); drop table t1; # -# lp:736791 Crash in make_truncated_value_warningwith LEAST()/GREATEST/COALESCE +# lp:736791 Crash in make_truncated_value_warning with LEAST()/GREATEST/COALESCE # create table t1 (f1 timestamp); insert into t1 values ('0000-00-00 00:00:00'); @@ -938,3 +938,9 @@ drop table t1; # select now() > coalesce(time('21:43:24'), date('2010-05-03')); +# +# lp:737104 Crash in DTCollation::set in 5.1-micro +# +create table t1 (f1 timestamp); +select * from t1 where f1 > f1 and f1 <=> timestampadd(hour, 9 , '2010-01-01 16:55:35'); +drop table t1; diff --git a/sql/item.cc b/sql/item.cc index 92df6bb0953..40e23f524db 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -6884,8 +6884,15 @@ void resolve_const_item(THD *thd, Item **ref, Item *comp_item) char *name=item->name; // Alloced by sql_alloc switch (res_type) { - case TIME_RESULT: // will be handled by get_datetime_value() + case TIME_RESULT: + { + bool is_null; + Item **ref_copy= ref; + get_datetime_value(thd, &ref_copy, &new_item, comp_item, &is_null); + if (is_null) + new_item= new Item_null(name); break; + } case STRING_RESULT: { char buff[MAX_FIELD_WIDTH]; diff --git a/sql/item.h b/sql/item.h index af0f3d1c024..d45df4ebe53 100644 --- a/sql/item.h +++ b/sql/item.h @@ -3035,6 +3035,12 @@ public: my_decimal *val_decimal(my_decimal *); enum Item_result result_type() const { return INT_RESULT; } bool cache_value(); + Item *clone_item() + { + Item_cache_int *item= new Item_cache_int(cached_field_type); + item->store(this, value); + return item; + } };