MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:ramil Date:November 17 2007 6:13am
Subject:bk commit into 5.1 tree (ramil:1.2619) BUG#32021
View as plain text  
Below is the list of changes that have just been committed into a local
5.1 repository of ram. When ram does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet@stripped, 2007-11-17 10:13:43+04:00, ramil@stripped +4 -0
  Fix for bug #32021: Using Date 000-00-01 in WHERE causes wrong result
  
  Problem: caching 00000000-00000099 dates as integer values we're 
  improperly shifting them up twice in the get_datetime_value().
  
  Fix: don't shift cached DATETIME values up for the second time.

  mysql-test/r/type_date.result@stripped, 2007-11-17 10:13:41+04:00, ramil@stripped +7 -0
    Fix for bug #32021: Using Date 000-00-01 in WHERE causes wrong result
      - test result.

  mysql-test/t/type_date.test@stripped, 2007-11-17 10:13:41+04:00, ramil@stripped +10 -0
    Fix for bug #32021: Using Date 000-00-01 in WHERE causes wrong result
      - test case.

  sql/item.h@stripped, 2007-11-17 10:13:41+04:00, ramil@stripped +16 -1
    Fix for bug #32021: Using Date 000-00-01 in WHERE causes wrong result
      - Item_cache::field_type() method added.
      - new Item_cache(enum_field_types) and Item_cache_int(enum_field_types) 
        constructors added.

  sql/item_cmpfunc.cc@stripped, 2007-11-17 10:13:41+04:00, ramil@stripped +6 -3
    Fix for bug #32021: Using Date 000-00-01 in WHERE causes wrong result
      - don't shift cached DATETIME values for the second time in the get_datetime_value():
          creating new Item_cache_int set DATETIME filed type,
          check the type before shifting.

diff -Nrup a/mysql-test/r/type_date.result b/mysql-test/r/type_date.result
--- a/mysql-test/r/type_date.result	2007-05-24 20:33:54 +05:00
+++ b/mysql-test/r/type_date.result	2007-11-17 10:13:41 +04:00
@@ -145,3 +145,10 @@ d	dt	ts
 0000-00-00	0000-00-00 00:00:00	0000-00-00 00:00:00
 2001-11-11	2001-11-11 00:00:00	2001-11-11 00:00:00
 drop table t1;
+create table t1 (a date, primary key (a))engine=memory;
+insert into t1 values ('0000-01-01'), ('0000-00-01'), ('0001-01-01');
+select * from t1 where a between '0000-00-01' and '0000-00-02';
+a
+0000-00-01
+drop table t1;
+End of 5.1 tests
diff -Nrup a/mysql-test/t/type_date.test b/mysql-test/t/type_date.test
--- a/mysql-test/t/type_date.test	2007-05-24 20:33:54 +05:00
+++ b/mysql-test/t/type_date.test	2007-11-17 10:13:41 +04:00
@@ -139,3 +139,13 @@ insert into t1 values (9912101,9912101,9
 insert into t1 values (11111,11111,11111);
 select * from t1;
 drop table t1;
+
+#
+# Bug#32021: Using Date 000-00-01 in WHERE causes wrong result
+#
+create table t1 (a date, primary key (a))engine=memory;
+insert into t1 values ('0000-01-01'), ('0000-00-01'), ('0001-01-01');
+select * from t1 where a between '0000-00-01' and '0000-00-02';
+drop table t1;
+
+--echo End of 5.1 tests
diff -Nrup a/sql/item.h b/sql/item.h
--- a/sql/item.h	2007-09-14 22:15:53 +05:00
+++ b/sql/item.h	2007-11-17 10:13:41 +04:00
@@ -2614,8 +2614,20 @@ class Item_cache: public Item
 protected:
   Item *example;
   table_map used_table_map;
+  enum enum_field_types cached_field_type;
 public:
-  Item_cache(): example(0), used_table_map(0) {fixed= 1; null_value= 1;}
+  Item_cache(): 
+    example(0), used_table_map(0), cached_field_type(MYSQL_TYPE_STRING) 
+  {
+    fixed= 1; 
+    null_value= 1;
+  }
+  Item_cache(enum_field_types field_type_arg):
+    example(0), used_table_map(0), cached_field_type(field_type_arg)
+  {
+    fixed= 1;
+    null_value= 1;
+  }
 
   void set_used_tables(table_map map) { used_table_map= map; }
 
@@ -2631,6 +2643,7 @@ public:
   };
   virtual void store(Item *)= 0;
   enum Type type() const { return CACHE_ITEM; }
+  enum_field_types field_type() const { return cached_field_type; }
   static Item_cache* get_cache(Item_result type);
   table_map used_tables() const { return used_table_map; }
   virtual void keep_array() {}
@@ -2646,6 +2659,8 @@ protected:
   longlong value;
 public:
   Item_cache_int(): Item_cache(), value(0) {}
+  Item_cache_int(enum_field_types field_type_arg): 
+    Item_cache(field_type_arg), value(0) {}
 
   void store(Item *item);
   void store(Item *item, longlong val_arg);
diff -Nrup a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc
--- a/sql/item_cmpfunc.cc	2007-11-06 14:07:17 +04:00
+++ b/sql/item_cmpfunc.cc	2007-11-17 10:13:41 +04:00
@@ -897,12 +897,15 @@ get_datetime_value(THD *thd, Item ***ite
   {
     value= item->val_int();
     *is_null= item->null_value;
+    enum_field_types f_type= item->field_type();
     /*
       Item_date_add_interval may return MYSQL_TYPE_STRING as the result
       field type. To detect that the DATE value has been returned we
-      compare it with 1000000L - any DATE value should be less than it.
+      compare it with 100000000L - any DATE value should be less than it.
+      Don't shift cached DATETIME values up for the second time.
     */
-    if (item->field_type() == MYSQL_TYPE_DATE || value < 100000000L)
+    if (f_type == MYSQL_TYPE_DATE || 
+        (f_type != MYSQL_TYPE_DATETIME && value < 100000000L))
       value*= 1000000L;
   }
   else
@@ -933,7 +936,7 @@ get_datetime_value(THD *thd, Item ***ite
   if (item->const_item() && cache_arg && (item->type() != Item::FUNC_ITEM ||
       ((Item_func*)item)->functype() != Item_func::GUSERVAR_FUNC))
   {
-    Item_cache_int *cache= new Item_cache_int();
+    Item_cache_int *cache= new Item_cache_int(MYSQL_TYPE_DATETIME);
     /* Mark the cache as non-const to prevent re-caching. */
     cache->set_used_tables(1);
     cache->store(item, value);
Thread
bk commit into 5.1 tree (ramil:1.2619) BUG#32021ramil17 Nov