Hi Tor,
There are three test cases in this bug report:
TESTCASE 1
create table g3(`a` time)engine=myisam;
insert into g3 values ('00:00:00'),('00:01:00');
select 1 from g3 where 1 < some (select cast(`a` as datetime) from g3);
TESTCASE 2
create table g4(`a` date,`b` int,unique(`b`),unique(`a`),key(`b`))engine=innodb;
insert into g4 values ('2011-05-13',0);
select 1 from g4 where `b`<(select cast(`a` as date) from g4 group by `a`);
TESTCASE 3
select min(timestampadd(month,1>'',from_days('%Z')));
Test case 2 still crashes :-(
On 02/09/2011 04:44 PM, Tor Didriksen wrote:
> #At file:///export/home/didrik/repo/5.5-bug59686-timestamp/ based on
> revid:joerg@stripped
>
> 3326 Tor Didriksen 2011-02-09
> Bug #59686 crash in String::copy() with time data type
>
> The problem was that Item_sum_hybrid::val_xxx() did not propagate null values
> up the expression tree.
> @ mysql-test/r/func_time.result
> New test case.
> @ mysql-test/t/func_time.test
> New test case.
> @ sql/item_sum.cc
> Check for null_value when evaluating sub-items in sub-trees in
> Item_sum_hybrid::val_xxx()
>
> modified:
> mysql-test/r/func_time.result
> mysql-test/t/func_time.test
> sql/item_sum.cc
> === modified file 'mysql-test/r/func_time.result'
> --- a/mysql-test/r/func_time.result 2011-02-02 18:16:06 +0000
> +++ b/mysql-test/r/func_time.result 2011-02-09 15:44:57 +0000
> @@ -1368,3 +1368,15 @@ SELECT SUBDATE(STR_TO_DATE(NULL,0), INTE
> SUBDATE(STR_TO_DATE(NULL,0), INTERVAL 1 HOUR)
> NULL
> #
> +# Bug #59686 crash in String::copy() with time data type
> +#
> +SELECT min(timestampadd(month, 1>'', from_days('%Z')));
> +min(timestampadd(month, 1>'', from_days('%Z')))
> +NULL
> +Warnings:
> +Warning 1292 Truncated incorrect INTEGER value: '%Z'
> +create table t1(a time);
> +insert into t1 values ('00:00:00'),('00:01:00');
> +select 1 from t1 where 1< some (select cast(a as datetime) from t1);
> +1
> +drop table t1;
>
> === modified file 'mysql-test/t/func_time.test'
> --- a/mysql-test/t/func_time.test 2011-02-02 18:16:06 +0000
> +++ b/mysql-test/t/func_time.test 2011-02-09 15:44:57 +0000
> @@ -881,4 +881,12 @@ SELECT WEEK(STR_TO_DATE(NULL,0));
> SELECT SUBDATE(STR_TO_DATE(NULL,0), INTERVAL 1 HOUR);
>
> --echo #
> +--echo # Bug #59686 crash in String::copy() with time data type
> +--echo #
> +
> +SELECT min(timestampadd(month, 1>'', from_days('%Z')));
>
> +create table t1(a time);
> +insert into t1 values ('00:00:00'),('00:01:00');
> +select 1 from t1 where 1< some (select cast(a as datetime) from t1);
> +drop table t1;
>
> === modified file 'sql/item_sum.cc'
> --- a/sql/item_sum.cc 2011-02-02 09:18:44 +0000
> +++ b/sql/item_sum.cc 2011-02-09 15:44:57 +0000
> @@ -1903,7 +1903,10 @@ double Item_sum_hybrid::val_real()
> DBUG_ASSERT(fixed == 1);
> if (null_value)
> return 0.0;
> - return value->val_real();
> + double retval= value->val_real();
> + if ((null_value= value->null_value))
> + DBUG_ASSERT(retval == 0.0);
> + return retval;
> }
>
> longlong Item_sum_hybrid::val_int()
> @@ -1911,7 +1914,10 @@ longlong Item_sum_hybrid::val_int()
> DBUG_ASSERT(fixed == 1);
> if (null_value)
> return 0;
> - return value->val_int();
> + longlong retval= value->val_int();
> + if ((null_value= value->null_value))
> + DBUG_ASSERT(retval == 0);
> + return retval;
> }
>
>
> @@ -1920,7 +1926,10 @@ my_decimal *Item_sum_hybrid::val_decimal
> DBUG_ASSERT(fixed == 1);
> if (null_value)
> return 0;
> - return value->val_decimal(val);
> + my_decimal *retval= value->val_decimal(val);
> + if ((null_value= value->null_value))
> + DBUG_ASSERT(retval == NULL);
> + return retval;
> }
>
>
> @@ -1930,7 +1939,10 @@ Item_sum_hybrid::val_str(String *str)
> DBUG_ASSERT(fixed == 1);
> if (null_value)
> return 0;
> - return value->val_str(str);
> + String *retval= value->val_str(str);
> + if ((null_value= value->null_value))
> + DBUG_ASSERT(retval == NULL);
> + return retval;
> }
>
>
>
>
>
>
>
--
Jørgen Løland | Senior Software Engineer | +47 73842138
Oracle MySQL
Trondheim, Norway