MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:Gleb Shchepa Date:December 8 2009 12:13pm
Subject:bzr commit into mysql-5.1-bugteam branch (gshchepa:3237) Bug#49480
View as plain text  
#At file:///mnt/sda7/work/49480/ based on revid:satya.bn@stripped

 3237 Gleb Shchepa	2009-12-08
      Bug #49480: WHERE using YEAR columns returns unexpected results
      
      A few problems were found in the fix for bug 43668:
      1) Comparison of the YEAR column with NULL always returned TRUE;
      2) Comparison of the YEAR column with constants always returned
         unpredictable result;
      3) Unnecessary conversion warnings when comparing a non-integer
         constant with a NULL value in the YEAR column;
      
      The problems described above have been resolved.
      
      Also a comparison problem of two YEAR columns has been solved
      (not a regression).
     @ mysql-test/r/type_year.result
        Test case for bug #49480.
     @ mysql-test/t/type_year.test
        Test case for bug #49480.
     @ sql/item_cmpfunc.cc
        - The get_year_value() function has been modified to make its
          return value compatible with the get_datetime_value() return
          value (i.e. to convert numeric values into the YYYY0000000000
          (YYYY-00-00 00:00:00) form.
          As far as:
          a) we have no direct way to distinguish YEAR(2) from YEAR(4) and
          b) zero value returned by val_int() means 2000 for YEAR(2) and
             0000 for YEAR(4),
          a var_str() trick has been added to return acceptable year
          value (before the regression the YEAR(2) comparison with 0
          was incorrect and after the regression it was fixed, but
          the YEAR(4) comparison was broken).
        
        - The Arg_comparator::set_cmp_func method has been modified to
          use the get_year_value function if get_datetime_value() is not
          applicable.
          From now only 2 cases have a special processing there:
          * both comparing items have MYSQL_TYPE_YEAR field type or
          * one item have is MYSQL_TYPE_YEAR and other one is
            is_datetime()-compliant.
        
        - New helper function try_year_cmp_func() has been
          added for the better code readability to call from
          Arg_comparator::set_cmp_func().
        
        - The Arg_comparator::compare_year method has been removed
          since get_year_value() is compatible with the old
          Arg_comparator::compare_datetime method that doesn't have
          problems #1-#3 (see whole patch entry commentary).
     @ sql/item_cmpfunc.h
        - New helper function try_year_cmp_func() has been
          added for the better code readability to call from
          Arg_comparator::set_cmp_func().
        
        - Unnecessary Arg_comparator::year_as_datetime and
          Arg_comparator::compare_year() declarations have been
          removed.

    modified:
      mysql-test/r/type_year.result
      mysql-test/t/type_year.test
      sql/item_cmpfunc.cc
      sql/item_cmpfunc.h
=== modified file 'mysql-test/r/type_year.result'
--- a/mysql-test/r/type_year.result	2007-03-29 04:08:30 +0000
+++ b/mysql-test/r/type_year.result	2009-12-08 12:13:13 +0000
@@ -46,3 +46,446 @@ a
 2001
 drop table t1;
 End of 5.0 tests
+#
+# Bug #49480: WHERE using YEAR columns returns unexpected results
+#
+CREATE TABLE t2(yy YEAR(2));
+CREATE TABLE t4(yyyy YEAR(4));
+INSERT INTO t2 VALUES (NULL),(0),('0'),(69),(70),(99),(1901),(1999),(2000),(2001),(2155);
+INSERT INTO t4 VALUES (NULL),(0),('0'),(69),(70),(99),(1901),(1999),(2000),(2001),(2155);
+SELECT * FROM t2 ORDER BY yy;
+yy
+NULL
+01
+70
+99
+99
+00
+00
+00
+01
+69
+55
+SELECT * FROM t4 ORDER BY yyyy;
+yyyy
+NULL
+0000
+1901
+1970
+1999
+1999
+2000
+2000
+2001
+2069
+2155
+# Comparison of YEAR(2) with YEAR(4)
+SELECT * FROM t2, t4 WHERE yy = yyyy;
+yy	yyyy
+00	2000
+00	2000
+00	2000
+69	2069
+70	1970
+99	1999
+99	1999
+99	1999
+99	1999
+00	2000
+00	2000
+00	2000
+01	2001
+01	2001
+SELECT * FROM t2, t4 WHERE yy < yyyy;
+yy	yyyy
+70	2000
+99	2000
+99	2000
+00	2069
+00	2069
+70	2069
+99	2069
+01	2069
+99	2069
+00	2069
+01	2069
+55	2069
+70	1999
+70	1999
+70	2000
+99	2000
+99	2000
+00	2001
+00	2001
+70	2001
+99	2001
+99	2001
+00	2001
+00	2155
+00	2155
+69	2155
+70	2155
+99	2155
+01	2155
+99	2155
+00	2155
+01	2155
+55	2155
+SELECT * FROM t2, t4 WHERE yy > yyyy;
+yy	yyyy
+00	0000
+00	0000
+69	0000
+70	0000
+99	0000
+01	0000
+99	0000
+00	0000
+01	0000
+55	0000
+69	2000
+01	2000
+01	2000
+55	2000
+00	1970
+00	1970
+69	1970
+99	1970
+01	1970
+99	1970
+00	1970
+01	1970
+55	1970
+00	1999
+00	1999
+69	1999
+01	1999
+00	1999
+01	1999
+55	1999
+00	1901
+00	1901
+69	1901
+70	1901
+99	1901
+01	1901
+99	1901
+00	1901
+01	1901
+55	1901
+00	1999
+00	1999
+69	1999
+01	1999
+00	1999
+01	1999
+55	1999
+69	2000
+01	2000
+01	2000
+55	2000
+69	2001
+55	2001
+# Comparison of YEAR(2) with YEAR(2)
+SELECT * FROM t2 a, t2 b WHERE a.yy = b.yy;
+yy	yy
+00	00
+00	00
+00	00
+00	00
+00	00
+00	00
+69	69
+70	70
+99	99
+99	99
+01	01
+01	01
+99	99
+99	99
+00	00
+00	00
+00	00
+01	01
+01	01
+55	55
+SELECT * FROM t2 a, t2 b WHERE a.yy < b.yy;
+yy	yy
+70	00
+99	00
+99	00
+70	00
+99	00
+99	00
+00	69
+00	69
+70	69
+99	69
+01	69
+99	69
+00	69
+01	69
+55	69
+70	99
+00	01
+00	01
+70	01
+99	01
+99	01
+00	01
+70	99
+70	00
+99	00
+99	00
+00	01
+00	01
+70	01
+99	01
+99	01
+00	01
+00	55
+00	55
+70	55
+99	55
+01	55
+99	55
+00	55
+01	55
+# Comparison of YEAR(4) with YEAR(4)
+SELECT * FROM t4 a, t4 b WHERE a.yyyy = b.yyyy;
+yyyy	yyyy
+0000	0000
+2000	2000
+2000	2000
+2069	2069
+1970	1970
+1999	1999
+1999	1999
+1901	1901
+1999	1999
+1999	1999
+2000	2000
+2000	2000
+2001	2001
+2155	2155
+SELECT * FROM t4 a, t4 b WHERE a.yyyy < b.yyyy;
+yyyy	yyyy
+0000	2000
+1970	2000
+1999	2000
+1901	2000
+1999	2000
+0000	2069
+2000	2069
+1970	2069
+1999	2069
+1901	2069
+1999	2069
+2000	2069
+2001	2069
+0000	1970
+1901	1970
+0000	1999
+1970	1999
+1901	1999
+0000	1901
+0000	1999
+1970	1999
+1901	1999
+0000	2000
+1970	2000
+1999	2000
+1901	2000
+1999	2000
+0000	2001
+2000	2001
+1970	2001
+1999	2001
+1901	2001
+1999	2001
+2000	2001
+0000	2155
+2000	2155
+2069	2155
+1970	2155
+1999	2155
+1901	2155
+1999	2155
+2000	2155
+2001	2155
+# Comparison with constants:
+SELECT * FROM t2 WHERE yy = NULL;
+yy
+SELECT * FROM t4 WHERE yyyy = NULL;
+yyyy
+SELECT * FROM t2 WHERE yy < NULL;
+yy
+SELECT * FROM t2 WHERE yy > NULL;
+yy
+SELECT * FROM t2 WHERE yy = NOW();
+yy
+SELECT * FROM t4 WHERE yyyy = NOW();
+yyyy
+SELECT * FROM t2 WHERE yy = 99;
+yy
+99
+99
+SELECT * FROM t2 WHERE 99 = yy;
+yy
+99
+99
+SELECT * FROM t4 WHERE yyyy = 99;
+yyyy
+1999
+1999
+SELECT * FROM t2 WHERE yy = 'test';
+yy
+00
+00
+00
+Warnings:
+Warning	1292	Truncated incorrect DOUBLE value: 'test'
+SELECT * FROM t4 WHERE yyyy = 'test';
+yyyy
+0000
+Warnings:
+Warning	1292	Truncated incorrect DOUBLE value: 'test'
+SELECT * FROM t2 WHERE yy = '1999';
+yy
+99
+99
+SELECT * FROM t4 WHERE yyyy = '1999';
+yyyy
+1999
+1999
+SELECT * FROM t2 WHERE yy = 1999;
+yy
+99
+99
+SELECT * FROM t4 WHERE yyyy = 1999;
+yyyy
+1999
+1999
+SELECT * FROM t2 WHERE yy = 1999.1;
+yy
+99
+99
+SELECT * FROM t4 WHERE yyyy = 1999.1;
+yyyy
+1999
+1999
+SELECT * FROM t2 WHERE yy = 1998.9;
+yy
+99
+99
+SELECT * FROM t4 WHERE yyyy = 1998.9;
+yyyy
+1999
+1999
+# Coverage tests for YEAR with zero/2000 constants:
+SELECT * FROM t2 WHERE yy = 0;
+yy
+00
+00
+00
+SELECT * FROM t2 WHERE yy = '0';
+yy
+00
+00
+00
+SELECT * FROM t2 WHERE yy = '0000';
+yy
+00
+00
+00
+SELECT * FROM t2 WHERE yy = '2000';
+yy
+00
+00
+00
+SELECT * FROM t2 WHERE yy = 2000;
+yy
+00
+00
+00
+SELECT * FROM t4 WHERE yyyy = 0;
+yyyy
+0000
+SELECT * FROM t4 WHERE yyyy = '0';
+yyyy
+2000
+2000
+SELECT * FROM t4 WHERE yyyy = '0000';
+yyyy
+0000
+SELECT * FROM t4 WHERE yyyy = '2000';
+yyyy
+2000
+2000
+SELECT * FROM t4 WHERE yyyy = 2000;
+yyyy
+2000
+2000
+# Comparison with constants those are out of YEAR range
+# (coverage test for backward compatibility)
+SELECT COUNT(yy) FROM t2;
+COUNT(yy)
+10
+SELECT COUNT(yyyy) FROM t4;
+COUNT(yyyy)
+10
+SELECT COUNT(*) FROM t2 WHERE yy = -1;
+COUNT(*)
+0
+SELECT COUNT(*) FROM t4 WHERE yyyy > -1;
+COUNT(*)
+10
+SELECT COUNT(*) FROM t2 WHERE yy > -1000000000000000000;
+COUNT(*)
+10
+SELECT COUNT(*) FROM t4 WHERE yyyy > -1000000000000000000;
+COUNT(*)
+10
+SELECT COUNT(*) FROM t2 WHERE yy < 2156;
+COUNT(*)
+10
+SELECT COUNT(*) FROM t4 WHERE yyyy < 2156;
+COUNT(*)
+10
+SELECT COUNT(*) FROM t2 WHERE yy < 1000000000000000000;
+COUNT(*)
+10
+SELECT COUNT(*) FROM t4 WHERE yyyy < 1000000000000000000;
+COUNT(*)
+10
+SELECT * FROM t2 WHERE yy < 123;
+yy
+00
+00
+69
+70
+99
+01
+99
+00
+01
+55
+SELECT * FROM t2 WHERE yy > 123;
+yy
+SELECT * FROM t4 WHERE yyyy < 123;
+yyyy
+0000
+SELECT * FROM t4 WHERE yyyy > 123;
+yyyy
+2000
+2069
+1970
+1999
+1901
+1999
+2000
+2001
+2155
+DROP TABLE t2, t4;
+#
+End of 5.1 tests

=== modified file 'mysql-test/t/type_year.test'
--- a/mysql-test/t/type_year.test	2007-03-29 04:08:30 +0000
+++ b/mysql-test/t/type_year.test	2009-12-08 12:13:13 +0000
@@ -30,3 +30,102 @@ select * from t1;
 drop table t1;
 
 --echo End of 5.0 tests
+
+--echo #
+--echo # Bug #49480: WHERE using YEAR columns returns unexpected results
+--echo #
+
+CREATE TABLE t2(yy YEAR(2));
+CREATE TABLE t4(yyyy YEAR(4));
+
+INSERT INTO t2 VALUES (NULL),(0),('0'),(69),(70),(99),(1901),(1999),(2000),(2001),(2155);
+INSERT INTO t4 VALUES (NULL),(0),('0'),(69),(70),(99),(1901),(1999),(2000),(2001),(2155);
+
+SELECT * FROM t2 ORDER BY yy;
+SELECT * FROM t4 ORDER BY yyyy;
+
+--echo # Comparison of YEAR(2) with YEAR(4)
+
+SELECT * FROM t2, t4 WHERE yy = yyyy;
+SELECT * FROM t2, t4 WHERE yy < yyyy;
+SELECT * FROM t2, t4 WHERE yy > yyyy;
+
+--echo # Comparison of YEAR(2) with YEAR(2)
+
+SELECT * FROM t2 a, t2 b WHERE a.yy = b.yy;
+SELECT * FROM t2 a, t2 b WHERE a.yy < b.yy;
+
+--echo # Comparison of YEAR(4) with YEAR(4)
+
+SELECT * FROM t4 a, t4 b WHERE a.yyyy = b.yyyy;
+SELECT * FROM t4 a, t4 b WHERE a.yyyy < b.yyyy;
+
+--echo # Comparison with constants:
+
+SELECT * FROM t2 WHERE yy = NULL;
+SELECT * FROM t4 WHERE yyyy = NULL;
+SELECT * FROM t2 WHERE yy < NULL;
+SELECT * FROM t2 WHERE yy > NULL;
+
+SELECT * FROM t2 WHERE yy = NOW();
+SELECT * FROM t4 WHERE yyyy = NOW();
+
+SELECT * FROM t2 WHERE yy = 99;
+SELECT * FROM t2 WHERE 99 = yy;
+SELECT * FROM t4 WHERE yyyy = 99; 
+
+SELECT * FROM t2 WHERE yy = 'test';
+SELECT * FROM t4 WHERE yyyy = 'test';
+
+SELECT * FROM t2 WHERE yy = '1999';
+SELECT * FROM t4 WHERE yyyy = '1999';
+
+SELECT * FROM t2 WHERE yy = 1999;
+SELECT * FROM t4 WHERE yyyy = 1999;
+
+SELECT * FROM t2 WHERE yy = 1999.1;
+SELECT * FROM t4 WHERE yyyy = 1999.1;
+
+SELECT * FROM t2 WHERE yy = 1998.9;
+SELECT * FROM t4 WHERE yyyy = 1998.9;
+
+--echo # Coverage tests for YEAR with zero/2000 constants:
+
+SELECT * FROM t2 WHERE yy = 0;
+SELECT * FROM t2 WHERE yy = '0';
+SELECT * FROM t2 WHERE yy = '0000';
+SELECT * FROM t2 WHERE yy = '2000';
+SELECT * FROM t2 WHERE yy = 2000;
+
+SELECT * FROM t4 WHERE yyyy = 0;
+SELECT * FROM t4 WHERE yyyy = '0';
+SELECT * FROM t4 WHERE yyyy = '0000';
+SELECT * FROM t4 WHERE yyyy = '2000';
+SELECT * FROM t4 WHERE yyyy = 2000;
+
+--echo # Comparison with constants those are out of YEAR range
+--echo # (coverage test for backward compatibility)
+
+SELECT COUNT(yy) FROM t2;
+SELECT COUNT(yyyy) FROM t4;
+
+SELECT COUNT(*) FROM t2 WHERE yy = -1;
+SELECT COUNT(*) FROM t4 WHERE yyyy > -1;
+SELECT COUNT(*) FROM t2 WHERE yy > -1000000000000000000;
+SELECT COUNT(*) FROM t4 WHERE yyyy > -1000000000000000000;
+
+SELECT COUNT(*) FROM t2 WHERE yy < 2156;
+SELECT COUNT(*) FROM t4 WHERE yyyy < 2156;
+SELECT COUNT(*) FROM t2 WHERE yy < 1000000000000000000;
+SELECT COUNT(*) FROM t4 WHERE yyyy < 1000000000000000000;
+
+SELECT * FROM t2 WHERE yy < 123;
+SELECT * FROM t2 WHERE yy > 123;
+SELECT * FROM t4 WHERE yyyy < 123;
+SELECT * FROM t4 WHERE yyyy > 123;
+
+DROP TABLE t2, t4;
+
+--echo #
+
+--echo End of 5.1 tests

=== modified file 'sql/item_cmpfunc.cc'
--- a/sql/item_cmpfunc.cc	2009-11-25 09:52:03 +0000
+++ b/sql/item_cmpfunc.cc	2009-12-08 12:13:13 +0000
@@ -956,40 +956,9 @@ int Arg_comparator::set_cmp_func(Item_re
     if (agg_item_set_converter(coll, owner->func_name(),
                                b, 1, MY_COLL_CMP_CONV, 1))
       return 1;
-  } else if (type != ROW_RESULT && ((*a)->field_type() == MYSQL_TYPE_YEAR ||
-             (*b)->field_type() == MYSQL_TYPE_YEAR))
-  {
-    is_nulls_eq= is_owner_equal_func();
-    year_as_datetime= FALSE;
-
-    if ((*a)->is_datetime())
-    {
-      year_as_datetime= TRUE;
-      get_value_a_func= &get_datetime_value;
-    } else if ((*a)->field_type() == MYSQL_TYPE_YEAR)
-      get_value_a_func= &get_year_value;
-    else
-    {
-      /*
-        Because convert_constant_item is called only for EXECUTE in PS mode
-        the value of get_value_x_func set in PREPARE might be not
-        valid for EXECUTE.
-      */
-      get_value_a_func= NULL;
-    }
-
-    if ((*b)->is_datetime())
-    {
-      year_as_datetime= TRUE;
-      get_value_b_func= &get_datetime_value;
-    } else if ((*b)->field_type() == MYSQL_TYPE_YEAR)
-      get_value_b_func= &get_year_value;
-    else
-      get_value_b_func= NULL;
-
-    func= &Arg_comparator::compare_year;
-    return 0;
   }
+  else if (try_year_cmp_func(type))
+    return 0;
 
   a= cache_converted_constant(thd, a, &a_cache, type);
   b= cache_converted_constant(thd, b, &b_cache, type);
@@ -997,6 +966,42 @@ int Arg_comparator::set_cmp_func(Item_re
 }
 
 
+/*
+  Helper function to call from Arg_comparator::set_cmp_func()
+*/
+
+bool Arg_comparator::try_year_cmp_func(Item_result type)
+{
+  if (type == ROW_RESULT)
+    return FALSE;
+
+  bool a_is_year= (*a)->field_type() == MYSQL_TYPE_YEAR;
+  bool b_is_year= (*b)->field_type() == MYSQL_TYPE_YEAR;
+
+  if (a_is_year && b_is_year)
+  {
+    get_value_a_func= &get_year_value;
+    get_value_b_func= &get_year_value;
+  }
+  else if (a_is_year && (*b)->is_datetime())
+  {
+    get_value_a_func= &get_year_value;
+    get_value_b_func= &get_datetime_value;
+  }
+  else if (b_is_year && (*a)->is_datetime())
+  {
+    get_value_b_func= &get_year_value;
+    get_value_a_func= &get_datetime_value;
+  }
+  else
+    return FALSE;
+
+  is_nulls_eq= is_owner_equal_func();
+  func= &Arg_comparator::compare_datetime;
+
+  return TRUE;
+}
+
 /**
   Convert and cache a constant.
 
@@ -1147,7 +1152,7 @@ get_datetime_value(THD *thd, Item ***ite
 
 
 /*
-  Retrieves YEAR value of 19XX form from given item.
+  Retrieves YEAR value of 19XX-00-00 00:00:00 form from given item.
 
   SYNOPSIS
     get_year_value()
@@ -1159,7 +1164,9 @@ get_datetime_value(THD *thd, Item ***ite
 
   DESCRIPTION
     Retrieves the YEAR value of 19XX form from given item for comparison by the
-    compare_year() function.
+    compare_datetime() function.
+    Converts year to DATETIME of form YYYY-00-00 00:00:00 for the compatibility
+    with the get_datetime_value function result.
 
   RETURN
     obtained value
@@ -1177,14 +1184,26 @@ get_year_value(THD *thd, Item ***item_ar
   if (*is_null)
     return ~(ulonglong) 0;
 
-  /*
-    Coerce value to the 19XX form in order to correctly compare
-    YEAR(2) & YEAR(4) types.
-  */
-  if (value < 70)
-    value+= 100;
-  if (value <= 1900)
-    value+= 1900;
+  if (value == 0)
+  {
+    /*
+      As far as:
+      a) we have no direct way to distinguish YEAR(2) from YEAR(4) and
+      b) zero value returned by val_int() means 2000 for YEAR(2) and
+         0000 for YEAR(4),
+      there is a var_str() trick to return acceptable year value
+    */
+    String buf;
+    item->val_str(&buf);
+    value= buf.length() == 2 ? 2000 : 0;
+  }
+  else if (value < YY_PART_YEAR)
+    value+= 2000; // map [00..69] to [2000..2069]
+  else if (value < 100)
+    value+= 1900; // map [70..99] to [1970.1999]
+
+  /* Convert year to DATETIME of form YYYY-00-00 00:00:00 (YYYY0000000000). */
+  value*= 10000000000LL;
 
   return value;
 }
@@ -1615,67 +1634,6 @@ int Arg_comparator::compare_e_row()
 }
 
 
-/**
-  Compare values as YEAR.
-
-  @details
-    Compare items as YEAR for EQUAL_FUNC and for other comparison functions.
-    The YEAR values of form 19XX are obtained with help of the get_year_value()
-    function.
-    If one of arguments is of DATE/DATETIME type its value is obtained
-    with help of the get_datetime_value function. In this case YEAR values
-    prior to comparison are converted to the ulonglong YYYY-00-00 00:00:00
-    DATETIME form.
-    If an argument type neither YEAR nor DATE/DATEIME then val_int function
-    is used to obtain value for comparison.
-
-  RETURN
-    If is_nulls_eq is TRUE:
-       1    if items are equal or both are null
-       0    otherwise
-    If is_nulls_eq is FALSE:
-      -1   a < b
-       0   a == b or at least one of items is null
-       1   a > b
-    See the table:
-    is_nulls_eq | 1 | 1 | 1 | 1 | 0 | 0 | 0 | 0 |
-    a_is_null   | 1 | 0 | 1 | 0 | 1 | 0 | 1 | 0 |
-    b_is_null   | 1 | 1 | 0 | 0 | 1 | 1 | 0 | 0 |
-    result      | 1 | 0 | 0 |0/1| 0 | 0 | 0 |-1/0/1|
-*/
-
-int Arg_comparator::compare_year()
-{
-  bool a_is_null, b_is_null;
-  ulonglong val1= get_value_a_func ?
-                    (*get_value_a_func)(thd, &a, &a_cache, *b, &a_is_null) :
-                    (*a)->val_int();
-  ulonglong val2= get_value_b_func ?
-                    (*get_value_b_func)(thd, &b, &b_cache, *a, &b_is_null) :
-                    (*b)->val_int();
-  if (!(*a)->null_value)
-  {
-    if (!(*b)->null_value)
-    {
-      if (set_null)
-        owner->null_value= 0;
-      /* Convert year to DATETIME of form YYYY-00-00 00:00:00 when necessary. */
-      if((*a)->field_type() == MYSQL_TYPE_YEAR && year_as_datetime)
-        val1*= 10000000000LL;
-      if((*b)->field_type() == MYSQL_TYPE_YEAR && year_as_datetime)
-        val2*= 10000000000LL;
-
-      if (val1 < val2)	return is_nulls_eq ? 0 : -1;
-      if (val1 == val2)   return is_nulls_eq ? 1 : 0;
-      return is_nulls_eq ? 0 : 1;
-    }
-  }
-  if (set_null)
-    owner->null_value= is_nulls_eq ? 0 : 1;
-  return (is_nulls_eq && (*a)->null_value == (*b)->null_value) ? 1 : 0;
-}
-
-
 void Item_func_truth::fix_length_and_dec()
 {
   maybe_null= 0;

=== modified file 'sql/item_cmpfunc.h'
--- a/sql/item_cmpfunc.h	2009-11-24 15:26:13 +0000
+++ b/sql/item_cmpfunc.h	2009-12-08 12:13:13 +0000
@@ -42,24 +42,22 @@ class Arg_comparator: public Sql_alloc
   bool is_nulls_eq;                // TRUE <=> compare for the EQUAL_FUNC
   bool set_null;                   // TRUE <=> set owner->null_value
                                    //   when one of arguments is NULL.
-  bool year_as_datetime;           // TRUE <=> convert YEAR value to
-                                   // the YYYY-00-00 00:00:00 DATETIME
-                                   // format. See compare_year.
   enum enum_date_cmp_type { CMP_DATE_DFLT= 0, CMP_DATE_WITH_DATE,
                             CMP_DATE_WITH_STR, CMP_STR_WITH_DATE };
   longlong (*get_value_a_func)(THD *thd, Item ***item_arg, Item **cache_arg,
                                Item *warn_item, bool *is_null);
   longlong (*get_value_b_func)(THD *thd, Item ***item_arg, Item **cache_arg,
                                Item *warn_item, bool *is_null);
+  bool try_year_cmp_func(Item_result type);
 public:
   DTCollation cmp_collation;
   /* Allow owner function to use string buffers. */
   String value1, value2;
 
   Arg_comparator(): thd(0), a_cache(0), b_cache(0), set_null(0),
-    year_as_datetime(0), get_value_a_func(0), get_value_b_func(0) {};
+    get_value_a_func(0), get_value_b_func(0) {};
   Arg_comparator(Item **a1, Item **a2): a(a1), b(a2), thd(0),
-    a_cache(0), b_cache(0), set_null(0), year_as_datetime(0),
+    a_cache(0), b_cache(0), set_null(0),
     get_value_a_func(0), get_value_b_func(0) {};
 
   int set_compare_func(Item_result_field *owner, Item_result type);
@@ -101,7 +99,6 @@ public:
   int compare_real_fixed();
   int compare_e_real_fixed();
   int compare_datetime();        // compare args[0] & args[1] as DATETIMEs
-  int compare_year();
 
   static enum enum_date_cmp_type can_compare_as_dates(Item *a, Item *b,
                                                       ulonglong *const_val_arg);


Attachment: [text/bzr-bundle] bzr/gshchepa@mysql.com-20091208121313-lc5p1ptnx3ux2jfw.bundle
Thread
bzr commit into mysql-5.1-bugteam branch (gshchepa:3237) Bug#49480Gleb Shchepa8 Dec