MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:Tor Didriksen Date:October 28 2009 12:49pm
Subject:bzr commit into mysql-6.0-codebase-bugfixing branch (tor.didriksen:3683)
Bug#48060
View as plain text  
#At file:///export/home/didrik/mysqldev-6.0-codebase/6.0-codebase-bf-valgrind/ based on revid:alik@stripped

 3683 Tor Didriksen	2009-10-28 [merge]
      Merge fix for Bug#48060 from my:next-mr-bugfixing

    modified:
      sql/item_sum.cc
      sql/item_sum.h
      sql/opt_sum.cc
      sql/sql_select.cc
      sql/sql_yacc.yy
=== modified file 'sql/item_sum.cc'
--- a/sql/item_sum.cc	2009-10-23 06:24:37 +0000
+++ b/sql/item_sum.cc	2009-10-28 12:48:31 +0000
@@ -557,6 +557,11 @@ void Item_sum::update_used_tables ()
 
 int Item_sum::set_aggregator(Aggregator::Aggregator_type aggregator)
 {
+  if (aggr)
+  {
+    DBUG_ASSERT(aggregator == aggr->Aggrtype());
+    return FALSE;
+  }
   switch (aggregator)
   {
   case Aggregator::DISTINCT_AGGREGATOR:
@@ -729,12 +734,12 @@ bool Aggregator_distinct::setup(THD *thd
       if (list.push_back(item))
         return TRUE;                              // End of memory
       if (item->const_item() && item->is_null())
-        always_null=1;
+        always_null= true;
     }
     if (always_null)
       return FALSE;
-    count_field_types(select_lex,tmp_table_param,list,0);
-    tmp_table_param->force_copy_fields= item_sum->force_copy_fields;
+    count_field_types(select_lex, tmp_table_param, list, 0);
+    tmp_table_param->force_copy_fields= item_sum->has_force_copy_fields();
     DBUG_ASSERT(table == 0);
     /*
       Make create_tmp_table() convert BIT columns to BIGINT.
@@ -836,7 +841,8 @@ bool Aggregator_distinct::setup(THD *thd
   {
     List<Create_field> field_list;
     Create_field field_def;                              /* field definition */
-    DBUG_ENTER("Item_sum_distinct::setup");
+    Item *arg;
+    DBUG_ENTER("Aggregator_distinct::setup");
     /* It's legal to call setup() more than once when in a subquery */
     if (tree)
       DBUG_RETURN(FALSE);
@@ -854,11 +860,12 @@ bool Aggregator_distinct::setup(THD *thd
 
     DBUG_ASSERT(item_sum->get_arg(0)->fixed);
 
-    if (item_sum->get_arg(0)->const_item())
+    arg= item_sum->get_arg(0);
+    if (arg->const_item())
     {
-      (void) item_sum->get_arg(0)->val_int();
-      if (item_sum->get_arg(0)->null_value)
-        always_null=1;
+      (void) arg->val_int();
+      if (arg->null_value)
+        always_null= true;
     }
 
     if (always_null)

=== modified file 'sql/item_sum.h'
--- a/sql/item_sum.h	2009-10-26 14:02:26 +0000
+++ b/sql/item_sum.h	2009-10-28 12:48:31 +0000
@@ -302,13 +302,14 @@ class st_select_lex;
 
 class Item_sum :public Item_result_field
 {
-public:
+protected:
   /**
     Aggregator class instance. Not set initially. Allocated only after
     it is determined if the incoming data are already distinct.
   */
   Aggregator *aggr;
 
+private:
   /**
     Used in making ROLLUP. Set for the ROLLUP copies of the original
     Item_sum and passed to create_tmp_field() to cause it to work
@@ -324,6 +325,11 @@ public:
   */
   bool with_distinct;
 
+public:
+
+  bool has_force_copy_fields() const { return force_copy_fields; }
+  bool has_with_distinct()     const { return with_distinct; }
+
   enum Sumfunctype
   { COUNT_FUNC, COUNT_DISTINCT_FUNC, SUM_FUNC, SUM_DISTINCT_FUNC, AVG_FUNC,
     AVG_DISTINCT_FUNC, MIN_FUNC, MAX_FUNC, STD_FUNC,
@@ -446,12 +452,12 @@ public:  
     may be initialized to 0 by clear() and to NULL by
     no_rows_in_result().
   */
-  void no_rows_in_result()
+  virtual void no_rows_in_result()
   {
     if (!aggr)
-     set_aggregator(with_distinct ?
-                    Aggregator::DISTINCT_AGGREGATOR :
-                    Aggregator::SIMPLE_AGGREGATOR);
+      set_aggregator(with_distinct ?
+                     Aggregator::DISTINCT_AGGREGATOR :
+                     Aggregator::SIMPLE_AGGREGATOR);
     reset();
   }
   virtual void make_unique() { force_copy_fields= TRUE; }
@@ -506,11 +512,12 @@ public:  
   */
 
   int set_aggregator(Aggregator::Aggregator_type aggregator);
+
   virtual void clear()= 0;
   virtual bool add()= 0;
-  virtual bool setup(THD *thd) {return 0;}
+  virtual bool setup(THD *thd) { return false; }
 
-  void cleanup ();
+  virtual void cleanup ();
   Item *get_arg(int i) { return args[i]; }
   Item *set_arg(int i, THD *thd, Item *new_val);
   uint get_arg_count() { return arg_count; }
@@ -531,9 +538,6 @@ class Unique;
 class Aggregator_distinct : public Aggregator
 {
   friend class Item_sum_sum;
-  friend class Item_sum_count;
-  friend class Item_sum_avg;
-protected:
 
   /* 
     flag to prevent consecutive runs of endup(). Normally in endup there are 
@@ -565,7 +569,7 @@ protected:
   uint32 *field_lengths;
 
   /*
-    used in conjunction with 'table' to support the access to Field classes 
+    Used in conjunction with 'table' to support the access to Field classes 
     for COUNT(DISTINCT). Needed by copy_fields()/copy_funcs().
   */
   TMP_TABLE_PARAM *tmp_table_param;
@@ -635,7 +639,6 @@ public:
 
 class Item_sum_num :public Item_sum
 {
-  friend class Aggregator_distinct;
 protected:
   /*
    val_xxx() functions may be called several times during the execution of a 
@@ -690,14 +693,14 @@ protected:
   void fix_length_and_dec();
 
 public:
-  Item_sum_sum(Item *item_par, bool distinct= FALSE) :Item_sum_num(item_par) 
+  Item_sum_sum(Item *item_par, bool distinct) :Item_sum_num(item_par) 
   {
     set_distinct(distinct);
   }
   Item_sum_sum(THD *thd, Item_sum_sum *item);
   enum Sumfunctype sum_func () const 
   { 
-    return with_distinct ? SUM_DISTINCT_FUNC : SUM_FUNC; 
+    return has_with_distinct() ? SUM_DISTINCT_FUNC : SUM_FUNC; 
   }
   void clear();
   bool add();
@@ -711,7 +714,7 @@ public:
   void no_rows_in_result() {}
   const char *func_name() const 
   { 
-    return with_distinct ? "sum(distinct " : "sum("; 
+    return has_with_distinct() ? "sum(distinct " : "sum("; 
   }
   Item *copy_or_same(THD* thd);
 };
@@ -750,7 +753,7 @@ class Item_sum_count :public Item_sum_in
   {}
   enum Sumfunctype sum_func () const 
   { 
-    return with_distinct ? COUNT_DISTINCT_FUNC : COUNT_FUNC; 
+    return has_with_distinct() ? COUNT_DISTINCT_FUNC : COUNT_FUNC; 
   }
   void no_rows_in_result() { count=0; }
   void make_const(longlong count_arg) 
@@ -763,7 +766,7 @@ class Item_sum_count :public Item_sum_in
   void update_field();
   const char *func_name() const 
   { 
-    return with_distinct ? "count(distinct " : "count(";
+    return has_with_distinct() ? "count(distinct " : "count(";
   }
   Item *copy_or_same(THD* thd);
 };
@@ -804,7 +807,7 @@ public:
   uint prec_increment;
   uint f_precision, f_scale, dec_bin_size;
 
-  Item_sum_avg(Item *item_par, bool distinct= FALSE) 
+  Item_sum_avg(Item *item_par, bool distinct) 
     :Item_sum_sum(item_par, distinct), count(0) 
   {}
   Item_sum_avg(THD *thd, Item_sum_avg *item)
@@ -814,7 +817,7 @@ public:
   void fix_length_and_dec();
   enum Sumfunctype sum_func () const 
   {
-    return with_distinct ? AVG_DISTINCT_FUNC : AVG_FUNC;
+    return has_with_distinct() ? AVG_DISTINCT_FUNC : AVG_FUNC;
   }
   void clear();
   bool add();
@@ -830,7 +833,7 @@ public:
   void no_rows_in_result() {}
   const char *func_name() const 
   { 
-    return with_distinct ? "avg(distinct " : "avg("; 
+    return has_with_distinct() ? "avg(distinct " : "avg("; 
   }
   Item *copy_or_same(THD* thd);
   Field *create_tmp_field(bool group, TABLE *table, uint convert_blob_length);

=== modified file 'sql/opt_sum.cc'
--- a/sql/opt_sum.cc	2009-10-19 18:36:44 +0000
+++ b/sql/opt_sum.cc	2009-10-28 12:48:31 +0000
@@ -355,9 +355,9 @@ int opt_sum_query(TABLE_LIST *tables, Li
           const_result= 0;
           break;
         }
-        item_sum->set_aggregator (item_sum->with_distinct ? 
-                                  Aggregator::DISTINCT_AGGREGATOR :
-                                  Aggregator::SIMPLE_AGGREGATOR);
+        item_sum->set_aggregator(item_sum->has_with_distinct() ? 
+                                 Aggregator::DISTINCT_AGGREGATOR :
+                                 Aggregator::SIMPLE_AGGREGATOR);
         if (!count)
         {
           /* If count == 0, then we know that is_exact_count == TRUE. */
@@ -445,9 +445,9 @@ int opt_sum_query(TABLE_LIST *tables, Li
           const_result= 0;
           break;
         }
-        item_sum->set_aggregator (item_sum->with_distinct ? 
-                                  Aggregator::DISTINCT_AGGREGATOR :
-                                  Aggregator::SIMPLE_AGGREGATOR);
+        item_sum->set_aggregator(item_sum->has_with_distinct() ? 
+                                 Aggregator::DISTINCT_AGGREGATOR :
+                                 Aggregator::SIMPLE_AGGREGATOR);
         if (!count)
         {
           /* If count != 1, then we know that is_exact_count == TRUE. */

=== modified file 'sql/sql_select.cc'
--- a/sql/sql_select.cc	2009-10-25 13:41:27 +0000
+++ b/sql/sql_select.cc	2009-10-28 12:48:31 +0000
@@ -2773,8 +2773,10 @@ JOIN::exec()
 
     if (curr_join->make_sum_func_list(*curr_all_fields, *curr_fields_list,
 				      1, TRUE) || 
-        prepare_sum_aggregators (curr_join->sum_funcs, !curr_join->join_tab ||
-                                !curr_join->join_tab->is_using_agg_loose_index_scan()) ||
+        prepare_sum_aggregators(curr_join->sum_funcs,
+                                !curr_join->join_tab ||
+                                !curr_join->join_tab->
+                                  is_using_agg_loose_index_scan()) ||
         setup_sum_funcs(curr_join->thd, curr_join->sum_funcs) ||
         thd->is_fatal_error)
       DBUG_VOID_RETURN;
@@ -5769,7 +5771,7 @@ is_indexed_agg_distinct(JOIN *join, List
       join->select_lex->olap == ROLLUP_TYPE)  /* Check (B3) for ROLLUP */
     return false;
 
-  if (join->make_sum_func_list(join->all_fields, join->fields_list, 1))
+  if (join->make_sum_func_list(join->all_fields, join->fields_list, true))
     return false;
 
   for (sum_item_ptr= join->sum_funcs; *sum_item_ptr; sum_item_ptr++)
@@ -20775,10 +20777,10 @@ static bool setup_sum_funcs(THD *thd, It
 static bool prepare_sum_aggregators(Item_sum **func_ptr, bool need_distinct)
 {
   Item_sum *func;
-  DBUG_ENTER("setup_sum_funcs");
+  DBUG_ENTER("prepare_sum_aggregators");
   while ((func= *(func_ptr++)))
   {
-    if (func->set_aggregator(need_distinct && func->with_distinct ?
+    if (func->set_aggregator(need_distinct && func->has_with_distinct() ?
                              Aggregator::DISTINCT_AGGREGATOR :
                              Aggregator::SIMPLE_AGGREGATOR))
       DBUG_RETURN(TRUE);

=== modified file 'sql/sql_yacc.yy'
--- a/sql/sql_yacc.yy	2009-10-27 10:03:00 +0000
+++ b/sql/sql_yacc.yy	2009-10-28 12:48:31 +0000
@@ -8752,7 +8752,7 @@ udf_expr:
 sum_expr:
           AVG_SYM '(' in_sum_expr ')'
           {
-            $$= new (YYTHD->mem_root) Item_sum_avg($3);
+            $$= new (YYTHD->mem_root) Item_sum_avg($3, FALSE);
             if ($$ == NULL)
               MYSQL_YYABORT;
           }
@@ -8860,7 +8860,7 @@ sum_expr:
           }
         | SUM_SYM '(' in_sum_expr ')'
           {
-            $$= new (YYTHD->mem_root) Item_sum_sum($3);
+            $$= new (YYTHD->mem_root) Item_sum_sum($3, FALSE);
             if ($$ == NULL)
               MYSQL_YYABORT;
           }


Attachment: [text/bzr-bundle] bzr/tor.didriksen@sun.com-20091028124831-l34xkirry2fu5gtd.bundle
Thread
bzr commit into mysql-6.0-codebase-bugfixing branch (tor.didriksen:3683)Bug#48060Tor Didriksen28 Oct