Commit 7e8ddb6b authored by Georgi Kodinov's avatar Georgi Kodinov

Backport of the 5.1 fix for bug #55826 to 5.0

parent 5df7f9bc
...@@ -1315,4 +1315,16 @@ id select_type table type possible_keys key key_len ref rows Extra ...@@ -1315,4 +1315,16 @@ id select_type table type possible_keys key key_len ref rows Extra
2 DEPENDENT SUBQUERY t1 system NULL NULL NULL NULL 0 const row not found 2 DEPENDENT SUBQUERY t1 system NULL NULL NULL NULL 0 const row not found
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 1 2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 1
DROP TABLE t1,t2; DROP TABLE t1,t2;
#
# Bug#55826: create table .. select crashes with when KILL_BAD_DATA
# is returned
#
CREATE TABLE t1(a INT) ENGINE=innodb;
INSERT INTO t1 VALUES (0);
SET SQL_MODE='STRICT_ALL_TABLES';
CREATE TABLE t2
SELECT LEAST((SELECT '' FROM t1),NOW()) FROM `t1`;
ERROR 22007: Truncated incorrect datetime value: ''
DROP TABLE t1;
SET SQL_MODE=DEFAULT;
End of 5.0 tests End of 5.0 tests
...@@ -1073,4 +1073,19 @@ explain ...@@ -1073,4 +1073,19 @@ explain
select b from t1 where a not in (select b from t1,t2 group by a) group by a; select b from t1 where a not in (select b from t1,t2 group by a) group by a;
DROP TABLE t1,t2; DROP TABLE t1,t2;
--echo #
--echo # Bug#55826: create table .. select crashes with when KILL_BAD_DATA
--echo # is returned
--echo #
CREATE TABLE t1(a INT) ENGINE=innodb;
INSERT INTO t1 VALUES (0);
SET SQL_MODE='STRICT_ALL_TABLES';
--error ER_TRUNCATED_WRONG_VALUE
CREATE TABLE t2
SELECT LEAST((SELECT '' FROM t1),NOW()) FROM `t1`;
DROP TABLE t1;
SET SQL_MODE=DEFAULT;
--echo End of 5.0 tests --echo End of 5.0 tests
...@@ -2270,7 +2270,7 @@ void Item_func_min_max::fix_length_and_dec() ...@@ -2270,7 +2270,7 @@ void Item_func_min_max::fix_length_and_dec()
stored to the value pointer, if latter is provided. stored to the value pointer, if latter is provided.
RETURN RETURN
0 If one of arguments is NULL 0 If one of arguments is NULL or there was a execution error
# index of the least/greatest argument # index of the least/greatest argument
*/ */
...@@ -2284,6 +2284,14 @@ uint Item_func_min_max::cmp_datetimes(ulonglong *value) ...@@ -2284,6 +2284,14 @@ uint Item_func_min_max::cmp_datetimes(ulonglong *value)
Item **arg= args + i; Item **arg= args + i;
bool is_null; bool is_null;
longlong res= get_datetime_value(thd, &arg, 0, datetime_item, &is_null); longlong res= get_datetime_value(thd, &arg, 0, datetime_item, &is_null);
/* Check if we need to stop (because of error or KILL) and stop the loop */
if (thd->net.report_error)
{
null_value= 1;
return 0;
}
if ((null_value= args[i]->null_value)) if ((null_value= args[i]->null_value))
return 0; return 0;
if (i == 0 || (res < min_max ? cmp_sign : -cmp_sign) > 0) if (i == 0 || (res < min_max ? cmp_sign : -cmp_sign) > 0)
...@@ -2312,6 +2320,12 @@ String *Item_func_min_max::val_str(String *str) ...@@ -2312,6 +2320,12 @@ String *Item_func_min_max::val_str(String *str)
if (null_value) if (null_value)
return 0; return 0;
str_res= args[min_max_idx]->val_str(str); str_res= args[min_max_idx]->val_str(str);
if (args[min_max_idx]->null_value)
{
// check if the call to val_str() above returns a NULL value
null_value= 1;
return NULL;
}
str_res->set_charset(collation.collation); str_res->set_charset(collation.collation);
return str_res; return str_res;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment