List:Commits« Previous MessageNext Message »
From:Evgeny Potemkin Date:October 1 2010 11:38am
Subject:bzr commit into mysql-5.5-bugteam branch (epotemkin:3213) Bug#57095
View as plain text  
#At file:///work/bzrroot/57095-bug-5.5-bugfixing/ based on revid:jon.hauglid@stripped

 3213 Evgeny Potemkin	2010-10-01
      Bug#57095: Wrongly chosen expression cache type led to a wrong result.
      The coalesce function returned DATETIME type due to a DATETIME argument, but
      since it's not a date/time function it can't return correct int value for
      it. Nevertheless Item_datetime_cache was chosen to cache coalesce's result
      and that led to a wrong result.
      
      Now Item_datetime_cache is used only for those function that could return
      correct int representation of DATETIME values.
     @ mysql-test/r/type_datetime.result
        Added a test case for the bug#57095.
     @ mysql-test/t/type_datetime.test
        Added a test case for the bug#57095.
     @ sql/item.cc
        Bug#57095: Wrongly chosen expression cache type led to a wrong result.
        Now Item_datetime_cache is used only for those function that could return
        correct int representation of DATETIME values.

    modified:
      mysql-test/r/type_datetime.result
      mysql-test/t/type_datetime.test
      sql/item.cc
=== modified file 'mysql-test/r/type_datetime.result'
--- a/mysql-test/r/type_datetime.result	2010-09-07 06:45:00 +0000
+++ b/mysql-test/r/type_datetime.result	2010-10-01 11:38:16 +0000
@@ -680,5 +680,17 @@ id	select_type	table	type	possible_keys	
 1	SIMPLE	t2	const	PRIMARY	PRIMARY	8	const	1	Using index
 DROP TABLE t1,t2;
 #
+# Bug#57095: Wrongly chosen expression cache type led to a wrong
+#            result.
+#
+CREATE TABLE t1 (`b` datetime );
+INSERT INTO t1 VALUES ('2010-01-01 00:00:00'), ('2010-01-01 00:00:00');
+SELECT * FROM t1 WHERE b <= coalesce(NULL, now());
+b
+2010-01-01 00:00:00
+2010-01-01 00:00:00
+DROP TABLE t1;
+#
+#
 # End of 5.5 tests
 #

=== modified file 'mysql-test/t/type_datetime.test'
--- a/mysql-test/t/type_datetime.test	2010-09-07 06:45:00 +0000
+++ b/mysql-test/t/type_datetime.test	2010-10-01 11:38:16 +0000
@@ -485,5 +485,15 @@ explain select * from t2 where f1=STR_TO
 DROP TABLE t1,t2;
 
 --echo #
+--echo # Bug#57095: Wrongly chosen expression cache type led to a wrong
+--echo #            result.
+--echo #
+CREATE TABLE t1 (`b` datetime );
+INSERT INTO t1 VALUES ('2010-01-01 00:00:00'), ('2010-01-01 00:00:00');
+SELECT * FROM t1 WHERE b <= coalesce(NULL, now());
+DROP TABLE t1;
+--echo #
+
+--echo #
 --echo # End of 5.5 tests
 --echo #

=== modified file 'sql/item.cc'
--- a/sql/item.cc	2010-09-24 13:18:45 +0000
+++ b/sql/item.cc	2010-10-01 11:38:16 +0000
@@ -7356,9 +7356,11 @@ Item_cache* Item_cache::get_cache(const 
   case DECIMAL_RESULT:
     return new Item_cache_decimal();
   case STRING_RESULT:
-    if (item->field_type() == MYSQL_TYPE_DATE ||
-        item->field_type() == MYSQL_TYPE_DATETIME ||
-        item->field_type() == MYSQL_TYPE_TIME)
+    /* 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 ||
+         item->field_type() == MYSQL_TYPE_TIME) &&
+        (const_cast<Item*>(item))->result_as_longlong())
       return new Item_cache_datetime(item->field_type());
     return new Item_cache_str(item);
   case ROW_RESULT:


Attachment: [text/bzr-bundle] bzr/epotemkin@mysql.com-20101001113816-0yo0di35t1yj1hz2.bundle
Thread
bzr commit into mysql-5.5-bugteam branch (epotemkin:3213) Bug#57095Evgeny Potemkin1 Oct
  • Re: bzr commit into mysql-5.5-bugteam branch (epotemkin:3213) Bug#57095Øystein Grøvlen6 Oct
    • Re: bzr commit into mysql-5.5-bugteam branch (epotemkin:3213) Bug#57095Evgeny Potemkin7 Oct
      • Re: bzr commit into mysql-5.5-bugteam branch (epotemkin:3213) Bug#57095Roy Lyseng7 Oct
      • Re: bzr commit into mysql-5.5-bugteam branch (epotemkin:3213) Bug#57095Øystein Grøvlen7 Oct