Bug #42664 Sign ignored for TIME types when not comparing as longlong
Submitted: 6 Feb 2009 19:11 Modified: 7 Mar 2010 12:53
Reporter: Tatiana Azundris Nuernberg Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Data Types Severity:S3 (Non-critical)
Version:5.0+ OS:Any
Assigned to: Tatiana Azundris Nuernberg CPU Architecture:Any

[6 Feb 2009 19:11] Tatiana Azundris Nuernberg
Description:
We lose sight of sign when SELECTing in TIME.
Cherry blossoms fall.

How to repeat:
CREATE TABLE t1 (f1 TIME);
INSERT INTO t1 VALUES ('24:00:00');
SELECT      '24:00:00' = (SELECT f1 FROM t1);
SELECT CAST('24:00:00' AS TIME) = (SELECT f1 FROM t1);
SELECT CAST('-24:00:00' AS TIME) = (SELECT f1 FROM t1);
TRUNCATE t1;
INSERT INTO t1 VALUES ('-24:00:00');
SELECT CAST('24:00:00' AS TIME) = (SELECT f1 FROM t1);
SELECT CAST('-24:00:00' AS TIME) = (SELECT f1 FROM t1);
SELECT '-24:00:00' = (SELECT f1 FROM t1);
DROP TABLE t1;

Suggested fix:
this goes through item_cmpfunc.cc:get_time_value,
through the non-longlong path.

probably need to fix

    value= !*is_null ? (longlong) TIME_to_ulonglong_datetime(&ltime) : 0;

to read

    value= !*is_null ? (longlong) TIME_to_ulonglong_datetime(&ltime) *
    (ltime.neg ? -1 : 1) : 0;

but that alone will not suffice.  Investigate.
[6 Feb 2009 19:50] MySQL Verification Team
Thank you for the bug report.
[9 Feb 2009 18:45] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/65648

2740 Tatiana A. Nurnberg	2009-02-09
      Bug#42664: Sign ignored for TIME types when not comparing as longlong
      
      Another code-path dropped sign of TIME, presuming all time is positive.
      
      Minds sign now. Patch depends on ChangeSet for 42661.
[9 Apr 2009 15:27] Georgi Kodinov
OK to push
[15 Apr 2009 16:34] Tatiana Azundris Nuernberg
patch queued for 6.0.11 in -bugteam
[6 May 2009 14:12] Bugs System
Pushed into 6.0.12-alpha (revid:svoj@sun.com-20090506125450-yokcmvqf2g7jhujq) (version source revid:azundris@mysql.com-20090414213640-3grwghkd2fkijx9m) (merge vers: 6.0.11-alpha) (pib:6)
[12 May 2009 1:40] Paul DuBois
Noted in 6.0.12 changelog.

Comparison of TIME values could lose the sign of operands.
[4 Nov 2009 10:29] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/89286

2908 Magne Mahre	2009-11-04
      Bug#42664: Sign ignored for TIME types when not comparing as longlong
            
      Another code-path dropped sign of TIME, presuming all time is positive.
            
      Minds sign now. Patch depends on ChangeSet for 42661.
     @ mysql-test/r/type_time.result
        Show we now no longer ignore sign of TIME-type
        in this code-path.
     @ mysql-test/t/type_time.test
        Show we now no longer ignore sign of TIME-type
        in this code-path.
     @ sql/item_cmpfunc.cc
        TIME_to_ulonglong() (somewhat obviously) loses sign
        of its argument, so we put it back in where needed.
[4 Nov 2009 10:30] Magne Mæhre
Backported to 5.6.0  (6.0-codebase revid: 1810.3898.2)
[20 Nov 2009 12:54] Bugs System
Pushed into 5.6.0-beta (revid:davi.arnaut@sun.com-20091119234808-xbjpkwaxjt5x5c0b) (version source revid:jon.hauglid@sun.com-20090928163426-2lg1gofzz44xzzxf) (merge vers: 6.0.14-alpha) (pib:13)
[20 Nov 2009 12:58] Bugs System
Pushed into 6.0.14-alpha (revid:kostja@sun.com-20091120124947-yi6h2jbgw0kbciwm) (version source revid:jon.hauglid@sun.com-20090928163426-2lg1gofzz44xzzxf) (merge vers: 6.0.14-alpha) (pib:13)
[20 Nov 2009 23:44] Paul DuBois
Noted in 5.6.0 changelog.
[6 Mar 2010 11:07] Bugs System
Pushed into 5.5.3-m3 (revid:alik@sun.com-20100306103849-hha31z2enhh7jwt3) (version source revid:jon.hauglid@sun.com-20090928163426-2lg1gofzz44xzzxf) (merge vers: 6.0.14-alpha) (pib:16)
[7 Mar 2010 12:53] Paul DuBois
Moved 5.6.0 changelog entry to 5.5.3.