Bug #29555 INcorrect comparison of casted time values
Submitted: 4 Jul 2007 18:55 Modified: 26 Jul 2007 18:24
Reporter: Peter Brawley (Basic Quality Contributor) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: General Severity:S3 (Non-critical)
Version:5.1.19, 4.1, 5.0 OS:Any
Assigned to: Evgeny Potemkin CPU Architecture:Any
Tags: qc

[4 Jul 2007 18:55] Peter Brawley
Description:
Reported on a forum in 4.1, replicated in 5.1:

-- Incorrect:
select cast('100:55:50' as time) < cast('24:00:00' as time);
+------------------------------------------------------+
| cast('100:55:50' as time) < cast('24:00:00' as time) |
+------------------------------------------------------+
|                                                    1 |
+------------------------------------------------------+

-- Incorrect:
select cast('100:55:50' as time) < cast('024:00:00' as time);
+-------------------------------------------------------+
| cast('100:55:50' as time) < cast('024:00:00' as time) |
+-------------------------------------------------------+
|                                                     1 |
+-------------------------------------------------------+

-- Correct:
select cast('300:55:50' as time) < cast('240:00:00' as time);
+-------------------------------------------------------+
| cast('300:55:50' as time) < cast('240:00:00' as time) |
+-------------------------------------------------------+
|                                                     0 |
+-------------------------------------------------------+

How to repeat:
As above
[4 Jul 2007 20:20] Sveta Smirnova
Thank you for the report.

Verified as described.
[11 Jul 2007 14:42] 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/30703

ChangeSet@1.2527, 2007-07-11 18:36:33+04:00, evgen@moonbone.local +3 -0
  Bug#29555: Comapring time values as strings may lead to a wrong result.
  
  Time values were compared as strings. This leads to a wrong comparison
  result when comparing values one of which is under 100 hours and another is
  over 100 hours.
  
  Now when the Arg_comparator::set_cmp_func function sees that both items to
  compare are of TIME type then it sets up comparator to the
  Arg_comparator::compare_e_int or the Arg_comparator::compare_int_unsigned
  functions to compare them.
[11 Jul 2007 19:21] 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/30735

ChangeSet@1.2527, 2007-07-11 23:18:02+04:00, evgen@moonbone.local +3 -0
  Bug#29555: Comparing time values as strings may lead to a wrong result.
  
  Time values were compared as strings. This led to a wrong comparison
  result when comparing values one of which is under 100 hours and another is
  over 100 hours.
  
  Now when the Arg_comparator::set_cmp_func function sees that both items to
  compare are of the TIME type it sets the comparator to the
  Arg_comparator::compare_e_int or the Arg_comparator::compare_int_unsigned
  functions.
[15 Jul 2007 17:55] 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/30942

ChangeSet@1.2526, 2007-07-15 21:51:36+04:00, evgen@moonbone.local +4 -0
  Extended fix for the bug#29555.
  
  The get_time_value function is added. It is used to obtain TIME values both
  from items the can return time as an integer and from items that can return
  time only as a string.
  The Arg_comparator::compare_datetime function now uses pointer to a getter
  function to obtain values to compare. Now this function is also used for
  comparison of TIME values.
  The get_value_func variable is added to the Arg_comparator class.
  It points to a getter function for the DATE/DATETIME/TIME comparator.
[17 Jul 2007 21:21] Valeriy Kravchuk
Bug #29822 was marked as a duplicate of this one.
[20 Jul 2007 23:46] Bugs System
Pushed into 5.1.21-beta
[20 Jul 2007 23:49] Bugs System
Pushed into 5.0.48
[26 Jul 2007 18:24] Peter Lavin
Thank you for your bug report. This issue has been committed to our source repository of that product and will be incorporated into the next release.

If necessary, you can access the source repository and build the latest available version, including the bug fix. More information about accessing the source trees is available at

    http://dev.mysql.com/doc/en/installing-source.html

Added to the changelogs for versions 5.0 and 5.1.