summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeny Potemkin <epotemkin@mysql.com>2011-01-12 20:32:38 +0300
committerEvgeny Potemkin <epotemkin@mysql.com>2011-01-12 20:32:38 +0300
commitd23c21737ec2216f0ac6c3bc11d8a48b000c82c2 (patch)
tree84d7ab889331eb023f36f22537fc4baa43059a7b
parent4ca124581c45de6b2d65c7b5ffd10d1c03977773 (diff)
parent7d2c7748bf948577f978258d8e014fe53eb7b776 (diff)
downloadmariadb-git-clone-5.5.9-build.tar.gz
Auto-merged.clone-5.5.9-build
-rw-r--r--mysql-test/r/type_timestamp.result29
-rw-r--r--mysql-test/t/type_timestamp.test18
-rw-r--r--sql/item.cc3
3 files changed, 48 insertions, 2 deletions
diff --git a/mysql-test/r/type_timestamp.result b/mysql-test/r/type_timestamp.result
index 10a2b47ba02..d5769bfd59a 100644
--- a/mysql-test/r/type_timestamp.result
+++ b/mysql-test/r/type_timestamp.result
@@ -540,3 +540,32 @@ a
2010-03-05 11:08:02
DROP TABLE t1;
End of Bug#50888
+#
+# Bug59330: Incorrect result when comparing an aggregate
+# function with TIMESTAMP
+#
+CREATE TABLE t1 (dt DATETIME, ts TIMESTAMP);
+INSERT INTO t1 VALUES('2011-01-06 12:34:30', '2011-01-06 12:34:30');
+SELECT MAX(dt), MAX(ts) FROM t1;
+MAX(dt) MAX(ts)
+2011-01-06 12:34:30 2011-01-06 12:34:30
+SELECT MAX(ts) < '2010-01-01 00:00:00' FROM t1;
+MAX(ts) < '2010-01-01 00:00:00'
+0
+SELECT MAX(dt) < '2010-01-01 00:00:00' FROM t1;
+MAX(dt) < '2010-01-01 00:00:00'
+0
+SELECT MAX(ts) > '2010-01-01 00:00:00' FROM t1;
+MAX(ts) > '2010-01-01 00:00:00'
+1
+SELECT MAX(dt) > '2010-01-01 00:00:00' FROM t1;
+MAX(dt) > '2010-01-01 00:00:00'
+1
+SELECT MAX(ts) = '2011-01-06 12:34:30' FROM t1;
+MAX(ts) = '2011-01-06 12:34:30'
+1
+SELECT MAX(dt) = '2011-01-06 12:34:30' FROM t1;
+MAX(dt) = '2011-01-06 12:34:30'
+1
+DROP TABLE t1;
+End of 5.5 tests
diff --git a/mysql-test/t/type_timestamp.test b/mysql-test/t/type_timestamp.test
index dfac6f93b7d..76423b11b99 100644
--- a/mysql-test/t/type_timestamp.test
+++ b/mysql-test/t/type_timestamp.test
@@ -377,3 +377,21 @@ SELECT a FROM t1;
DROP TABLE t1;
--echo End of Bug#50888
+
+--echo #
+--echo # Bug59330: Incorrect result when comparing an aggregate
+--echo # function with TIMESTAMP
+--echo #
+CREATE TABLE t1 (dt DATETIME, ts TIMESTAMP);
+INSERT INTO t1 VALUES('2011-01-06 12:34:30', '2011-01-06 12:34:30');
+SELECT MAX(dt), MAX(ts) FROM t1;
+SELECT MAX(ts) < '2010-01-01 00:00:00' FROM t1;
+SELECT MAX(dt) < '2010-01-01 00:00:00' FROM t1;
+SELECT MAX(ts) > '2010-01-01 00:00:00' FROM t1;
+SELECT MAX(dt) > '2010-01-01 00:00:00' FROM t1;
+SELECT MAX(ts) = '2011-01-06 12:34:30' FROM t1;
+SELECT MAX(dt) = '2011-01-06 12:34:30' FROM t1;
+DROP TABLE t1;
+
+--echo End of 5.5 tests
+
diff --git a/sql/item.cc b/sql/item.cc
index 18a88d64470..c7787d65c22 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -7370,8 +7370,7 @@ Item_cache* Item_cache::get_cache(const Item *item, const Item_result type)
return new Item_cache_decimal();
case STRING_RESULT:
/* Not all functions that return DATE/TIME are actually DATE/TIME funcs. */
- if ((item->field_type() == MYSQL_TYPE_DATE ||
- item->field_type() == MYSQL_TYPE_DATETIME ||
+ if ((item->is_datetime() ||
item->field_type() == MYSQL_TYPE_TIME) &&
(const_cast<Item*>(item))->result_as_longlong())
return new Item_cache_datetime(item->field_type());