From 5122e43a935a75a232b08b39e14b01e892bebb7e Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Fri, 18 Mar 2011 19:23:32 +0100 Subject: [PATCH] lp:737450 Second Assertion `item->null_value' failed in 5.1-micro implement Item_func_min_max::get_date() --- mysql-test/r/func_time.result | 6 ++++++ mysql-test/t/func_time.test | 8 ++++++++ sql/item_func.cc | 14 ++++++-------- sql/item_func.h | 2 +- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/mysql-test/r/func_time.result b/mysql-test/r/func_time.result index 1ada270b326..039640a5036 100644 --- a/mysql-test/r/func_time.result +++ b/mysql-test/r/func_time.result @@ -1527,3 +1527,9 @@ NULL Warnings: Warning 1292 Incorrect datetime value: '0000-00-00' drop table t1; +create table t1 (f2 time not null, f3 datetime, f4 int not null, f5 timestamp); +insert ignore t1 values ('04:38:11','0000-00-00 00:00:00',0,'0000-00-00 00:00:00'); +select least(greatest(f3, f2, f4), f5) from t1; +least(greatest(f3, f2, f4), f5) +0000-00-00 00:00:00 +drop table t1; diff --git a/mysql-test/t/func_time.test b/mysql-test/t/func_time.test index 078f910a704..7d143ed9c16 100644 --- a/mysql-test/t/func_time.test +++ b/mysql-test/t/func_time.test @@ -960,3 +960,11 @@ select timestampadd(week, 1, f1) from t1; select timestampadd(week, 1, date("0000-00-00")); drop table t1; +# +# lp:737450 Second Assertion `item->null_value' failed in 5.1-micro +# +create table t1 (f2 time not null, f3 datetime, f4 int not null, f5 timestamp); +insert ignore t1 values ('04:38:11','0000-00-00 00:00:00',0,'0000-00-00 00:00:00'); +select least(greatest(f3, f2, f4), f5) from t1; +drop table t1; + diff --git a/sql/item_func.cc b/sql/item_func.cc index 821341aa82d..3e539585dde 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -2259,9 +2259,6 @@ void Item_func_min_max::fix_length_and_dec() /* Compare item arguments in the DATETIME context. - SYNOPSIS - cmp_datetimes() - DESCRIPTION Compare item arguments as DATETIME values and return the index of the least/greatest argument in the arguments array. @@ -2273,9 +2270,10 @@ void Item_func_min_max::fix_length_and_dec() 0 Otherwise */ -bool Item_func_min_max::cmp_datetimes(MYSQL_TIME *ltime) +bool Item_func_min_max::get_date(MYSQL_TIME *ltime, uint fuzzy_date) { longlong UNINIT_VAR(min_max); + DBUG_ASSERT(fixed == 1); for (uint i=0; i < arg_count ; i++) { @@ -2309,7 +2307,7 @@ String *Item_func_min_max::val_str(String *str) if (compare_as_dates) { MYSQL_TIME ltime; - if (cmp_datetimes(<ime)) + if (get_date(<ime, TIME_FUZZY_DATE)) return 0; char buf[MAX_DATE_STRING_REP_LENGTH]; @@ -2383,7 +2381,7 @@ double Item_func_min_max::val_real() if (compare_as_dates) { MYSQL_TIME ltime; - if (cmp_datetimes(<ime)) + if (get_date(<ime, TIME_FUZZY_DATE)) return 0; return TIME_to_double(<ime); @@ -2412,7 +2410,7 @@ longlong Item_func_min_max::val_int() if (compare_as_dates) { MYSQL_TIME ltime; - if (cmp_datetimes(<ime)) + if (get_date(<ime, TIME_FUZZY_DATE)) return 0; return TIME_to_ulonglong(<ime); @@ -2442,7 +2440,7 @@ my_decimal *Item_func_min_max::val_decimal(my_decimal *dec) if (compare_as_dates) { MYSQL_TIME ltime; - if (cmp_datetimes(<ime)) + if (get_date(<ime, TIME_FUZZY_DATE)) return 0; return date2my_decimal(<ime, dec); diff --git a/sql/item_func.h b/sql/item_func.h index d0f5d8d8d8f..cd2829fb5a7 100644 --- a/sql/item_func.h +++ b/sql/item_func.h @@ -769,9 +769,9 @@ public: longlong val_int(); String *val_str(String *); my_decimal *val_decimal(my_decimal *); + bool get_date(MYSQL_TIME *res, uint fuzzy_date); void fix_length_and_dec(); enum Item_result result_type () const { return cmp_type; } - bool cmp_datetimes(MYSQL_TIME *ltime); enum_field_types field_type() const { return cached_field_type; } };