From d72f05fc5b330c3507b44538d5e5559a2c70288a Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Thu, 17 Mar 2011 15:57:04 +0100 Subject: [PATCH] lp:736791 Crash in make_truncated_value_warningwith LEAST()/GREATEST/COALESCE and a test case for lp:736370 Datetime functions in subquery context cause wrong result --- mysql-test/r/func_time.result | 18 ++++++++++++++++++ mysql-test/t/func_time.test | 16 ++++++++++++++++ sql/item_func.cc | 3 +-- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/func_time.result b/mysql-test/r/func_time.result index b5c35d40a0f..5ee050e5cba 100644 --- a/mysql-test/r/func_time.result +++ b/mysql-test/r/func_time.result @@ -1476,3 +1476,21 @@ Warning 1292 Truncated incorrect time value: '-596523:14:07' select convert_tz(timediff('0000-00-00 00:00:00', cast('2008-03-26 07:09:06' as datetime)), 'UTC', 'Europe/Moscow'); convert_tz(timediff('0000-00-00 00:00:00', cast('2008-03-26 07:09:06' as datetime)), 'UTC', 'Europe/Moscow') NULL +create table t1 (f1 integer, f2 date); +insert into t1 values (1,'2011-05-05'),(2,'2011-05-05'),(3,'2011-05-05'),(4,'2011-05-05'),(5,'2011-05-05'); +select * from t1 where (f1, f2) in (select f1, makedate(2011 , 125) from t1); +f1 f2 +1 2011-05-05 +2 2011-05-05 +3 2011-05-05 +4 2011-05-05 +5 2011-05-05 +drop table t1; +create table t1 (f1 timestamp); +insert into t1 values ('0000-00-00 00:00:00'); +select least(1, f1) from t1; +least(1, f1) +0000-00-00 00:00:00 +Warnings: +Warning 1292 Incorrect datetime value: '1' for column 'f1' at row 1 +drop table t1; diff --git a/mysql-test/t/func_time.test b/mysql-test/t/func_time.test index db06a462183..646b55ad25a 100644 --- a/mysql-test/t/func_time.test +++ b/mysql-test/t/func_time.test @@ -916,3 +916,19 @@ drop table t1; # select timediff('0000-00-00 00:00:00', cast('2008-03-26 07:09:06' as datetime)); select convert_tz(timediff('0000-00-00 00:00:00', cast('2008-03-26 07:09:06' as datetime)), 'UTC', 'Europe/Moscow'); + +# +# lp:736370 Datetime functions in subquery context cause wrong result and bogus warnings in mysql-5.1-micr +# +create table t1 (f1 integer, f2 date); +insert into t1 values (1,'2011-05-05'),(2,'2011-05-05'),(3,'2011-05-05'),(4,'2011-05-05'),(5,'2011-05-05'); +select * from t1 where (f1, f2) in (select f1, makedate(2011 , 125) from t1); +drop table t1; + +# +# lp:736791 Crash in make_truncated_value_warningwith LEAST()/GREATEST/COALESCE +# +create table t1 (f1 timestamp); +insert into t1 values ('0000-00-00 00:00:00'); +select least(1, f1) from t1; +drop table t1; diff --git a/sql/item_func.cc b/sql/item_func.cc index b37156efa02..821341aa82d 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -2221,6 +2221,7 @@ void Item_func_min_max::fix_length_and_dec() decimals=0; max_length=0; maybe_null=0; + thd= current_thd; cmp_type=args[0]->result_type(); for (uint i=0 ; i < arg_count ; i++) @@ -2240,8 +2241,6 @@ void Item_func_min_max::fix_length_and_dec() if (cmp_type == STRING_RESULT) { agg_arg_charsets(collation, args, arg_count, MY_COLL_CMP_CONV, 1); - if (compare_as_dates) - thd= current_thd; } else if ((cmp_type == DECIMAL_RESULT) || (cmp_type == INT_RESULT)) max_length= my_decimal_precision_to_length_no_truncation(max_int_part +