Bug #28208 Comparison of curdate() or now() with string sometimes fails
Submitted: 2 May 2007 22:07 Modified: 12 Jun 2007 14:45
Reporter: Pete Harlan (Candidate Quality Contributor) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Data Types Severity:S2 (Serious)
Version:5.0.42-bk, 5.1 OS:Linux (Debian Etch x86_64)
Assigned to: Evgeny Potemkin CPU Architecture:Any
Tags: regression

[2 May 2007 22:07] Pete Harlan
Description:
If d is a date equal to curtime(), left(d,10) shows unequal to curtime().  Similar behavior is exhibited for datetimes.  This is a regression from 4.1, which compares correctly.

How to repeat:
create table foo (d date);

insert into foo (d) values (curdate());

select d, 
       curdate(), 
       d = curdate(), 
       '2007-05-02' = curdate(), 
       left(d,10), 
       left(d,10) = curdate(),
       left(d,10) = concat(curdate()),
       left(d,10) = d
from foo;

drop table foo;

create table foo (d datetime);

insert into foo (d) values (now());

select d, 
       now(), 
       d = now(), 
       left(d,19), 
       left(d,19) = now(),
       left(d,19) = concat(now()),
       left(d,19) = d
from foo;

drop table foo;

This outputs:

*************************** 1. row ***************************
                             d: 2007-05-02
                     curdate(): 2007-05-02
                 d = curdate(): 1
      '2007-05-02' = curdate(): 1
                    left(d,10): 2007-05-02
        left(d,10) = curdate(): 0
left(d,10) = concat(curdate()): 1
                left(d,10) = d: 1
*************************** 1. row ***************************
                         d: 2007-05-02 15:04:00
                     now(): 2007-05-02 15:04:00
                 d = now(): 1
                left(d,19): 2007-05-02 15:04:00
        left(d,19) = now(): 0
left(d,19) = concat(now()): 1
            left(d,19) = d: 1

The rows whose values are "0" should be "1".
[3 May 2007 6:38] Sveta Smirnova
Thank you for the report.

Verified as described.
[15 May 2007 19:40] 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/26734

ChangeSet@1.2487, 2007-05-15 23:37:18+04:00, evgen@moonbone.local +3 -0
  Bug#28208: Wrong result of a non-const STRING function with a const DATETIME
  function.
  
  A wrong  condition was used to check that the
  Arg_comparator::can_compare_as_dates() function calculated the value of the
  string constant. When comparing a non-const STRING function with a constant
  DATETIME function it leads to saving an arbitrary value as a cached value of
  the DATETIME function.
  
  Now the Arg_comparator::set_cmp_func() funcion initializes the const_value
  variable to the impossible DATETIME value (-1) and this const_value is
  cached only if it was changed by the Arg_comparator::can_compare_as_dates()
  function.
[15 May 2007 20:32] 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/26737

ChangeSet@1.2487, 2007-05-16 00:30:12+04:00, evgen@moonbone.local +3 -0
  Bug#28208: Wrong result of a non-const STRING function with a const DATETIME
  function.
  
  A wrong  condition was used to check that the
  Arg_comparator::can_compare_as_dates() function calculated the value of the
  string constant. When comparing a non-const STRING function with a constant
  DATETIME function it leads to saving an arbitrary value as a cached value of
  the DATETIME function.
  
  Now the Arg_comparator::set_cmp_func() function initializes the const_value
  variable to the impossible DATETIME value (-1) and this const_value is
  cached only if it was changed by the Arg_comparator::can_compare_as_dates()
  function.
[20 May 2007 17:11] Bugs System
Pushed into 5.0.44
[20 May 2007 17:12] Bugs System
Pushed into 5.1.19-beta
[12 Jun 2007 14:45] 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

Noted in changelogs 5.0.44 and 5.1.19-beta.