MySQL Lists are EOL. Please join:

List:Internals« Previous MessageNext Message »
From:eugene Date:September 7 2005 6:38pm
Subject:bk commit into 5.0 tree (evgen:1.1958) BUG#12922
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of evgen. When evgen 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
  1.1958 05/09/07 22:38:36 evgen@stripped +4 -0
  Fix bug #12922 if(sum(),...) with group from view returns wrong results
  
  Fields of view represented by Item_direct_view_ref. When complex expression
  such as if(sum()>...,...) is splited in simpler parts by refs was ignored.
  Beside this direct ref doesn't use it's result_field and thus can't store
  it's result in tmp table which is needed for sum() ... group.
  All this results in reported bug.
  
  Item::split_sum_func2() now converts Item_direct_view_ref to Item_ref to
  make fields from view being storable in tmp table.

  mysql-test/r/view.result
    1.108 05/09/07 22:38:15 evgen@stripped +9 -0
    Test case for bug#12922 if(sum(),...) with group from view returns wrong results

  mysql-test/t/view.test
    1.103 05/09/07 22:38:07 evgen@stripped +10 -0
    Test case for bug#12922 if(sum(),...) with group from view returns wrong results

  sql/item.cc
    1.172 05/09/07 22:37:46 evgen@stripped +9 -7
    Fix bug #12922 if(sum(),...) with group from view returns wrong results
     Item::split_sum_func2() now converts Item_direct_view_ref to Item_ref to make fields from view being storable in tmp table.

  sql/item.h
    1.167 05/09/07 22:37:36 evgen@stripped +4 -0
    Fix bug #12922 if(sum(),...) with group from view returns wrong results
    Added function ref_type() to distinguish Item_ref subclasses

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	evgen
# Host:	moonbone.local
# Root:	/work/12922-bug-5.0-mysql

--- 1.171/sql/item.cc	2005-09-02 18:06:09 +04:00
+++ 1.172/sql/item.cc	2005-09-07 22:37:46 +04:00
@@ -1022,9 +1022,9 @@
     /* Will split complicated items and ignore simple ones */
     split_sum_func(thd, ref_pointer_array, fields);
   }
-  else if ((type() == SUM_FUNC_ITEM ||
-            (used_tables() & ~PARAM_TABLE_BIT)) &&
-           type() != REF_ITEM)
+  else if ((type() == SUM_FUNC_ITEM || (used_tables() & ~PARAM_TABLE_BIT)) &&
+           (type() != REF_ITEM ||
+           ((Item_ref*)this)->ref_type() == Item_ref::VIEW_REF))
   {
     /*
       Replace item with a reference so that we can easily calculate
@@ -1033,15 +1033,17 @@
       The test above is to ensure we don't do a reference for things
       that are constants (PARAM_TABLE_BIT is in effect a constant)
       or already referenced (for example an item in HAVING)
+      Exception is Item_direct_view_ref which we need to convert to
+      Item_ref to allow fields from view being stored in tmp table.
     */
     uint el= fields.elements;
-    Item *new_item;    
-    ref_pointer_array[el]= this;
+    Item *new_item, *real_item= real_item();
+
+    ref_pointer_array[el]= real_item;
     if (!(new_item= new Item_ref(&thd->lex->current_select->context,
                                  ref_pointer_array + el, 0, name)))
       return;                                   // fatal_error is set
-    fields.push_front(this);
-    ref_pointer_array[el]= this;
+    fields.push_front(real_item);
     thd->change_item_tree(ref, new_item);
   }
 }

--- 1.166/sql/item.h	2005-08-29 21:16:51 +04:00
+++ 1.167/sql/item.h	2005-09-07 22:37:36 +04:00
@@ -1537,6 +1537,7 @@
 protected:
   void set_properties();
 public:
+  enum Ref_Type { REF, DIRECT_REF, VIEW_REF };
   Field *result_field;			 /* Save result here */
   Item **ref;
   Item_ref(Name_resolution_context *context_arg,
@@ -1617,6 +1618,7 @@
   void cleanup();
   Item_field *filed_for_view_update()
     { return (*ref)->filed_for_view_update(); }
+  virtual Ref_Type ref_type() { return REF; }
 };
 
 
@@ -1641,6 +1643,7 @@
   bool val_bool();
   bool is_null();
   bool get_date(TIME *ltime,uint fuzzydate);
+  virtual Ref_Type ref_type() { return DIRECT_REF; }
 };
 
 /*
@@ -1660,6 +1663,7 @@
 
   bool fix_fields(THD *, Item **);
   bool eq(const Item *item, bool binary_cmp) const;
+  virtual Ref_Type ref_type() { return VIEW_REF; }
 };
 
 

--- 1.107/mysql-test/r/view.result	2005-09-01 23:42:19 +04:00
+++ 1.108/mysql-test/r/view.result	2005-09-07 22:38:15 +04:00
@@ -2151,3 +2151,12 @@
 strcmp(f1,'a')
 drop view v1;
 drop table t1;
+create table t1 (f1 int, f2 int,f3 int);
+insert into t1 values (1,10,20),(2,0,0);
+create view v1 as select * from t1;
+select if(sum(f1)>1,f2,f3) from v1 group by f1;
+if(sum(f1)>1,f2,f3)
+20
+0
+drop view v1;
+drop table t1;

--- 1.102/mysql-test/t/view.test	2005-09-02 10:50:09 +04:00
+++ 1.103/mysql-test/t/view.test	2005-09-07 22:38:07 +04:00
@@ -2018,3 +2018,13 @@
 select * from v1;
 drop view v1;
 drop table t1;
+
+#
+# Bug #12922 if(sum(),...) with group from view returns wrong results 
+#
+create table t1 (f1 int, f2 int,f3 int);
+insert into t1 values (1,10,20),(2,0,0);
+create view v1 as select * from t1;
+select if(sum(f1)>1,f2,f3) from v1 group by f1;
+drop view v1;
+drop table t1;
Thread
bk commit into 5.0 tree (evgen:1.1958) BUG#12922eugene7 Sep