From 31a79ee3d0fd8cde70bad857807c5053f06a938b Mon Sep 17 00:00:00 2001 From: "jimw@mysql.com" <> Date: Mon, 17 Oct 2005 17:00:42 -0700 Subject: [PATCH] Fix Item_func_abs::fix_length_and_dec() to set maybe_null properly. (Bug #14009) --- mysql-test/r/func_math.result | 6 ++++++ mysql-test/t/func_math.test | 10 ++++++++++ sql/item_func.cc | 1 + 3 files changed, 17 insertions(+) diff --git a/mysql-test/r/func_math.result b/mysql-test/r/func_math.result index b36902d7872..11a3d14fb65 100644 --- a/mysql-test/r/func_math.result +++ b/mysql-test/r/func_math.result @@ -145,3 +145,9 @@ insert into t1 values (1); select rand(i) from t1; ERROR HY000: Incorrect arguments to RAND drop table t1; +create table t1 (a varchar(90), ts datetime not null, index (a)) engine=innodb default charset=utf8; +insert into t1 values ('http://www.foo.com/', now()); +select a from t1 where a='http://www.foo.com/' order by abs(timediff(ts, 0)); +a +http://www.foo.com/ +drop table t1; diff --git a/mysql-test/t/func_math.test b/mysql-test/t/func_math.test index c75454a96d4..a8f62e38e86 100644 --- a/mysql-test/t/func_math.test +++ b/mysql-test/t/func_math.test @@ -86,4 +86,14 @@ insert into t1 values (1); select rand(i) from t1; drop table t1; +# +# Bug #14009: use of abs() on null value causes problems with filesort +# +# InnoDB is required to reproduce the fault, but it is okay if we default to +# MyISAM when testing. +create table t1 (a varchar(90), ts datetime not null, index (a)) engine=innodb default charset=utf8; +insert into t1 values ('http://www.foo.com/', now()); +select a from t1 where a='http://www.foo.com/' order by abs(timediff(ts, 0)); +drop table t1; + # End of 4.1 tests diff --git a/sql/item_func.cc b/sql/item_func.cc index 288859443ff..5a70e6ba89b 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -766,6 +766,7 @@ void Item_func_abs::fix_length_and_dec() hybrid_type= REAL_RESULT; if (args[0]->result_type() == INT_RESULT) hybrid_type= INT_RESULT; + maybe_null= 1; }