From a4e5902039db10e5661c8475790aff84e67dff09 Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Mon, 28 Sep 2015 19:12:05 +0400 Subject: [PATCH] MDEV-8862 Wrong field type for MAX(COALESCE(datetime_column)) --- mysql-test/r/type_time.result | 9 +++++++++ mysql-test/t/type_time.test | 8 ++++++++ sql/item_func.cc | 4 +++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/type_time.result b/mysql-test/r/type_time.result index 59de00fa416..bdcffc8d824 100644 --- a/mysql-test/r/type_time.result +++ b/mysql-test/r/type_time.result @@ -1206,5 +1206,14 @@ Warning 1292 Incorrect time value: '9000000' for column 'b' at row 4 Warning 1292 Incorrect time value: '9000000' for column 'c' at row 4 DROP TABLE t1; # +# MDEV-8862 Wrong field type for MAX(COALESCE(datetime_column)) +# +CREATE TABLE t1 (a TIME); +INSERT INTO t1 VALUES ('10:10:10'),('10:20:30'); +SELECT MAX(a), MAX(COALESCE(a)) FROM t1; +MAX(a) MAX(COALESCE(a)) +10:20:30 10:20:30 +DROP TABLE t1; +# # End of 10.1 tests # diff --git a/mysql-test/t/type_time.test b/mysql-test/t/type_time.test index b257aa4f455..27679b9ec5a 100644 --- a/mysql-test/t/type_time.test +++ b/mysql-test/t/type_time.test @@ -715,6 +715,14 @@ INSERT INTO t1 VALUES (9000000,9000000,9000000); SELECT a, TIME(a),TIME(b),TIME(c) FROM t1 ORDER BY a; DROP TABLE t1; +--echo # +--echo # MDEV-8862 Wrong field type for MAX(COALESCE(datetime_column)) +--echo # +CREATE TABLE t1 (a TIME); +INSERT INTO t1 VALUES ('10:10:10'),('10:20:30'); +SELECT MAX(a), MAX(COALESCE(a)) FROM t1; +DROP TABLE t1; + --echo # --echo # End of 10.1 tests --echo # diff --git a/sql/item_func.cc b/sql/item_func.cc index 7876929a427..ea1710ecc24 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -1089,7 +1089,9 @@ bool Item_func_hybrid_result_type::get_date(MYSQL_TIME *ltime, case STRING_RESULT: { if (is_temporal_type(field_type())) - return date_op(ltime, fuzzydate); + return date_op(ltime, + fuzzydate | + (field_type() == MYSQL_TYPE_TIME ? TIME_TIME_ONLY : 0)); char buff[40]; String tmp(buff,sizeof(buff), &my_charset_bin),*res; if (!(res= str_op(&tmp)) ||