diff -Narup ./024_mariadb-10.0.15-log_result_errors/sql/ha_partition.cc ./026_mariadb-10.0.15-direct_aggregate/sql/ha_partition.cc
--- ./024_mariadb-10.0.15-log_result_errors/sql/ha_partition.cc	2014-11-29 17:05:41.677420762 +0900
+++ ./026_mariadb-10.0.15-direct_aggregate/sql/ha_partition.cc	2014-11-29 17:06:05.893380488 +0900
@@ -4264,7 +4264,6 @@ int ha_partition::write_row(uchar * buf)
   sql_mode_t saved_sql_mode= thd->variables.sql_mode;
   bool saved_auto_inc_field_not_null= table->auto_increment_field_not_null;
   DBUG_ENTER("ha_partition::write_row");
-  DBUG_ASSERT(buf == m_rec0);
 
   /*
     If we have an auto_increment column and we are writing a changed row
@@ -7632,6 +7631,13 @@ void ha_partition::return_top_record(uch
   memcpy(buf, rec_buffer, m_rec_length);
   m_last_part= part_id;
   m_top_entry= part_id;
+  m_file[part_id]->return_record_by_parent();
+}
+
+
+void ha_partition::return_record_by_parent()
+{
+  m_file[m_last_part]->return_record_by_parent();
 }
 
 
diff -Narup ./024_mariadb-10.0.15-log_result_errors/sql/ha_partition.h ./026_mariadb-10.0.15-direct_aggregate/sql/ha_partition.h
--- ./024_mariadb-10.0.15-log_result_errors/sql/ha_partition.h	2014-11-29 17:05:41.679796954 +0900
+++ ./026_mariadb-10.0.15-direct_aggregate/sql/ha_partition.h	2014-11-29 17:06:05.895380498 +0900
@@ -339,6 +339,7 @@ public:
      m_part_info= part_info;
      m_is_sub_partitioned= part_info->is_sub_partitioned();
   }
+  virtual void return_record_by_parent();
   /*
     -------------------------------------------------------------------------
     MODULE create/delete handler object
diff -Narup ./024_mariadb-10.0.15-log_result_errors/sql/handler.h ./026_mariadb-10.0.15-direct_aggregate/sql/handler.h
--- ./024_mariadb-10.0.15-log_result_errors/sql/handler.h	2014-11-29 17:05:31.714411758 +0900
+++ ./026_mariadb-10.0.15-direct_aggregate/sql/handler.h	2014-11-29 17:06:05.900398804 +0900
@@ -42,6 +42,7 @@
 #define HANDLER_HAS_TOP_TABLE_FIELDS
 #define HANDLER_HAS_DIRECT_UPDATE_ROWS
 #define HANDLER_HAS_NEED_INFO_FOR_AUTO_INC
+#define HANDLER_HAS_DIRECT_AGGREGATE
 #define INFO_KIND_UPDATE_FIELDS 101
 #define INFO_KIND_UPDATE_VALUES 102
 #define INFO_KIND_FORCE_LIMIT_BEGIN 103
@@ -3319,6 +3320,7 @@ public:
     return 0;
   }
   virtual void set_part_info(partition_info *part_info) {return;}
+  virtual void return_record_by_parent() {return;}
 
   virtual ulong index_flags(uint idx, uint part, bool all_parts) const =0;
 
diff -Narup ./024_mariadb-10.0.15-log_result_errors/sql/item.h ./026_mariadb-10.0.15-direct_aggregate/sql/item.h
--- ./024_mariadb-10.0.15-log_result_errors/sql/item.h	2014-11-22 06:02:57.000000000 +0900
+++ ./026_mariadb-10.0.15-direct_aggregate/sql/item.h	2014-11-29 17:06:05.905797113 +0900
@@ -4546,6 +4546,7 @@ public:
   }
 
   virtual void store(Item *item);
+  virtual Item *get_item() { return example; }
   virtual bool cache_value()= 0;
   bool basic_const_item() const
   { return MY_TEST(example && example->basic_const_item()); }
diff -Narup ./024_mariadb-10.0.15-log_result_errors/sql/item_sum.cc ./026_mariadb-10.0.15-direct_aggregate/sql/item_sum.cc
--- ./024_mariadb-10.0.15-log_result_errors/sql/item_sum.cc	2014-11-22 06:02:53.000000000 +0900
+++ ./026_mariadb-10.0.15-direct_aggregate/sql/item_sum.cc	2014-11-29 17:06:05.911796903 +0900
@@ -1339,7 +1339,7 @@ Field *Item_sum_hybrid::create_tmp_field
 */
 Item_sum_sum::Item_sum_sum(THD *thd, Item_sum_sum *item) 
   :Item_sum_num(thd, item), hybrid_type(item->hybrid_type),
-   curr_dec_buff(item->curr_dec_buff)
+   direct_added(FALSE), curr_dec_buff(item->curr_dec_buff)
 {
   /* TODO: check if the following assignments are really needed */
   if (hybrid_type == DECIMAL_RESULT)
@@ -1357,6 +1357,15 @@ Item *Item_sum_sum::copy_or_same(THD* th
 }
 
 
+void Item_sum_sum::cleanup()
+{
+  DBUG_ENTER("Item_sum_sum::cleanup");
+  direct_added= FALSE;
+  Item_sum_num::cleanup();
+  DBUG_VOID_RETURN;
+}
+
+
 void Item_sum_sum::clear()
 {
   DBUG_ENTER("Item_sum_sum::clear");
@@ -1412,11 +1421,49 @@ void Item_sum_sum::fix_length_and_dec()
 }
 
 
+void Item_sum_sum::direct_add(my_decimal *add_sum_decimal)
+{
+  DBUG_ENTER("Item_sum_sum::direct_add");
+  DBUG_PRINT("info",("add_sum_decimal = %p", add_sum_decimal));
+  direct_added= TRUE;
+  if (add_sum_decimal)
+  {
+    direct_sum_is_null= FALSE;
+    direct_sum_decimal= *add_sum_decimal;
+  } else {
+    direct_sum_is_null= TRUE;
+  }
+  DBUG_VOID_RETURN;
+}
+
+
+void Item_sum_sum::direct_add(double add_sum_real, bool add_sum_is_null)
+{
+  DBUG_ENTER("Item_sum_sum::direct_add");
+  DBUG_PRINT("info",("add_sum_real = %f", add_sum_real));
+  direct_added= TRUE;
+  direct_sum_is_null= add_sum_is_null;
+  direct_sum_real= add_sum_real;
+  DBUG_VOID_RETURN;
+}
+
+
 bool Item_sum_sum::add()
 {
   DBUG_ENTER("Item_sum_sum::add");
   if (hybrid_type == DECIMAL_RESULT)
   {
+    if (direct_added)
+    {
+      if (!direct_sum_is_null)
+      {
+        my_decimal_add(E_DEC_FATAL_ERROR, dec_buffs + (curr_dec_buff^1),
+                       &direct_sum_decimal, dec_buffs + curr_dec_buff);
+        curr_dec_buff^= 1;
+        null_value= 0;
+      }
+      direct_added= FALSE;
+    } else {
     my_decimal value;
     const my_decimal *val= aggr->arg_val_decimal(&value);
     if (!aggr->arg_is_null(true))
@@ -1426,12 +1473,23 @@ bool Item_sum_sum::add()
       curr_dec_buff^= 1;
       null_value= 0;
     }
+    }
   }
   else
   {
+    if (direct_added)
+    {
+      if (!direct_sum_is_null)
+      {
+        sum+= direct_sum_real;
+        null_value= 0;
+      }
+      direct_added= FALSE;
+    } else {
     sum+= aggr->arg_val_real();
     if (!aggr->arg_is_null(true))
       null_value= 0;
+    }
   }
   DBUG_RETURN(0);
 }
@@ -1610,30 +1668,51 @@ bool Aggregator_distinct::arg_is_null(bo
 
 Item *Item_sum_count::copy_or_same(THD* thd)
 {
-  return new (thd->mem_root) Item_sum_count(thd, this);
+  DBUG_ENTER("Item_sum_count::copy_or_same");
+  DBUG_RETURN(new (thd->mem_root) Item_sum_count(thd, this));
+}
+
+
+void Item_sum_count::direct_add(longlong add_count)
+{
+  DBUG_ENTER("Item_sum_count::direct_add");
+  DBUG_PRINT("info",("add_count = %lld", add_count));
+  direct_counted= TRUE;
+  direct_count= add_count;
+  DBUG_VOID_RETURN;
 }
 
 
 void Item_sum_count::clear()
 {
+  DBUG_ENTER("Item_sum_count::clear");
   count= 0;
+  DBUG_VOID_RETURN;
 }
 
 
 bool Item_sum_count::add()
 {
+  DBUG_ENTER("Item_sum_count::add");
+  if (direct_counted)
+  {
+    count += direct_count;
+    direct_counted= FALSE;
+  } else {
   if (aggr->arg_is_null(false))
-    return 0;
+    DBUG_RETURN(0);
   count++;
-  return 0;
+  }
+  DBUG_RETURN(0);
 }
 
 longlong Item_sum_count::val_int()
 {
+  DBUG_ENTER("Item_sum_count::val_int");
   DBUG_ASSERT(fixed == 1);
   if (aggr)
     aggr->endup();
-  return (longlong) count;
+  DBUG_RETURN((longlong) count);
 }
 
 
@@ -1641,6 +1720,7 @@ void Item_sum_count::cleanup()
 {
   DBUG_ENTER("Item_sum_count::cleanup");
   count= 0;
+  direct_counted= FALSE;
   Item_sum_int::cleanup();
   DBUG_VOID_RETURN;
 }
@@ -2027,6 +2107,17 @@ void Item_sum_hybrid::clear()
   null_value= 1;
 }
 
+
+void Item_sum_hybrid::direct_add(Item *item)
+{
+  DBUG_ENTER("Item_sum_hybrid::direct_add");
+  DBUG_PRINT("info",("item = %p", item));
+  direct_added= TRUE;
+  direct_item= item;
+  DBUG_VOID_RETURN;
+}
+
+
 double Item_sum_hybrid::val_real()
 {
   DBUG_ASSERT(fixed == 1);
@@ -2079,6 +2170,7 @@ void Item_sum_hybrid::cleanup()
 {
   DBUG_ENTER("Item_sum_hybrid::cleanup");
   Item_sum::cleanup();
+  direct_added= FALSE;
   forced_const= FALSE;
   if (cmp)
     delete cmp;
@@ -2125,6 +2217,15 @@ Item *Item_sum_min::copy_or_same(THD* th
 
 bool Item_sum_min::add()
 {
+  DBUG_ENTER("Item_sum_min::add");
+  DBUG_PRINT("info",("this = %p", this));
+  Item *tmp_item;
+  if (direct_added)
+  {
+    tmp_item= arg_cache->get_item();
+    arg_cache->store(direct_item);
+  }
+  DBUG_PRINT("info",("null_value = %s", null_value ? "TRUE" : "FALSE"));
   /* args[0] < value */
   arg_cache->cache_value();
   if (!arg_cache->null_value &&
@@ -2134,7 +2235,12 @@ bool Item_sum_min::add()
     value->cache_value();
     null_value= 0;
   }
-  return 0;
+  if (direct_added)
+  {
+    arg_cache->store(tmp_item);
+    direct_added= FALSE;
+  }
+  DBUG_RETURN(0);
 }
 
 
@@ -2148,6 +2254,15 @@ Item *Item_sum_max::copy_or_same(THD* th
 
 bool Item_sum_max::add()
 {
+  DBUG_ENTER("Item_sum_max::add");
+  DBUG_PRINT("info",("this = %p", this));
+  Item *tmp_item;
+  if (direct_added)
+  {
+    tmp_item= arg_cache->get_item();
+    arg_cache->store(direct_item);
+  }
+  DBUG_PRINT("info",("null_value = %s", null_value ? "TRUE" : "FALSE"));
   /* args[0] > value */
   arg_cache->cache_value();
   if (!arg_cache->null_value &&
@@ -2157,7 +2272,12 @@ bool Item_sum_max::add()
     value->cache_value();
     null_value= 0;
   }
-  return 0;
+  if (direct_added)
+  {
+    arg_cache->store(tmp_item);
+    direct_added= FALSE;
+  }
+  DBUG_RETURN(0);
 }
 
 
@@ -2242,6 +2362,12 @@ void Item_sum_num::reset_field()
 
 void Item_sum_hybrid::reset_field()
 {
+  Item *tmp_item;
+  if (direct_added)
+  {
+    tmp_item= value->get_item();
+    value->store(direct_item);
+  }
   switch(hybrid_type) {
   case STRING_RESULT:
   {
@@ -2320,6 +2446,11 @@ void Item_sum_hybrid::reset_field()
   case IMPOSSIBLE_RESULT:
     DBUG_ASSERT(0);
   }
+  if (direct_added)
+  {
+    value->store(tmp_item);
+    direct_added= FALSE;
+  }
 }
 
 
@@ -2328,33 +2459,65 @@ void Item_sum_sum::reset_field()
   DBUG_ASSERT (aggr->Aggrtype() != Aggregator::DISTINCT_AGGREGATOR);
   if (hybrid_type == DECIMAL_RESULT)
   {
+    if (direct_added)
+    {
+      if (!direct_sum_is_null)
+      {
+        result_field->store_decimal(&direct_sum_decimal);
+      } else {
+        result_field->store_decimal(&decimal_zero);
+      }
+    } else {
     my_decimal value, *arg_val= args[0]->val_decimal(&value);
     if (!arg_val)                               // Null
       arg_val= &decimal_zero;
     result_field->store_decimal(arg_val);
+    }
   }
   else
   {
     DBUG_ASSERT(hybrid_type == REAL_RESULT);
+    if (direct_added)
+    {
+      float8store(result_field->ptr, direct_sum_real);
+    } else {
     double nr= args[0]->val_real();			// Nulls also return 0
     float8store(result_field->ptr, nr);
+    }
   }
+  if (direct_added)
+  {
+    if (!direct_sum_is_null)
+    {
+      result_field->set_notnull();
+    } else {
+      result_field->set_null();
+    }
+    direct_added= FALSE;
+  } else {
   if (args[0]->null_value)
     result_field->set_null();
   else
     result_field->set_notnull();
+  }
 }
 
 
 void Item_sum_count::reset_field()
 {
+  DBUG_ENTER("Item_sum_count::reset_field");
   uchar *res=result_field->ptr;
   longlong nr=0;
   DBUG_ASSERT (aggr->Aggrtype() != Aggregator::DISTINCT_AGGREGATOR);
 
-  if (!args[0]->maybe_null || !args[0]->is_null())
+  if (direct_counted)
+  {
+    nr = direct_count;
+    direct_counted= FALSE;
+  } else if (!args[0]->maybe_null || !args[0]->is_null())
     nr=1;
   int8store(res,nr);
+  DBUG_VOID_RETURN;
 }
 
 
@@ -2418,6 +2581,26 @@ void Item_sum_sum::update_field()
   DBUG_ASSERT (aggr->Aggrtype() != Aggregator::DISTINCT_AGGREGATOR);
   if (hybrid_type == DECIMAL_RESULT)
   {
+    if (direct_added)
+    {
+      if (!direct_sum_is_null)
+      {
+        if (!result_field->is_null())
+        {
+          my_decimal field_value,
+                     *field_val= result_field->val_decimal(&field_value);
+          my_decimal_add(E_DEC_FATAL_ERROR, dec_buffs, &direct_sum_decimal,
+                         field_val);
+          result_field->store_decimal(dec_buffs);
+        }
+        else
+        {
+          result_field->store_decimal(&direct_sum_decimal);
+          result_field->set_notnull();
+        }
+      }
+      direct_added= FALSE;
+    } else {
     my_decimal value, *arg_val= args[0]->val_decimal(&value);
     if (!args[0]->null_value)
     {
@@ -2434,6 +2617,7 @@ void Item_sum_sum::update_field()
         result_field->set_notnull();
       }
     }
+    }
   }
   else
   {
@@ -2441,12 +2625,22 @@ void Item_sum_sum::update_field()
     uchar *res=result_field->ptr;
 
     float8get(old_nr,res);
+    if (direct_added)
+    {
+      if (!direct_sum_is_null)
+      {
+        old_nr+= direct_sum_real;
+        result_field->set_notnull();
+      }
+      direct_added= FALSE;
+    } else {
     nr= args[0]->val_real();
     if (!args[0]->null_value)
     {
       old_nr+=nr;
       result_field->set_notnull();
     }
+    }
     float8store(res,old_nr);
   }
 }
@@ -2454,13 +2648,19 @@ void Item_sum_sum::update_field()
 
 void Item_sum_count::update_field()
 {
+  DBUG_ENTER("Item_sum_count::update_field");
   longlong nr;
   uchar *res=result_field->ptr;
 
   nr=sint8korr(res);
-  if (!args[0]->maybe_null || !args[0]->is_null())
+  if (direct_counted)
+  {
+    nr += direct_count;
+    direct_counted= FALSE;
+  } else if (!args[0]->maybe_null || !args[0]->is_null())
     nr++;
   int8store(res,nr);
+  DBUG_VOID_RETURN;
 }
 
 
@@ -2509,6 +2709,12 @@ void Item_sum_avg::update_field()
 
 void Item_sum_hybrid::update_field()
 {
+  Item *tmp_item;
+  if (direct_added)
+  {
+    tmp_item= value->get_item();
+    value->store(direct_item);
+  }
   switch (hybrid_type) {
   case STRING_RESULT:
     min_max_update_str_field();
@@ -2522,6 +2728,11 @@ void Item_sum_hybrid::update_field()
   default:
     min_max_update_real_field();
   }
+  if (direct_added)
+  {
+    value->store(tmp_item);
+    direct_added= FALSE;
+  }
 }
 
 
diff -Narup ./024_mariadb-10.0.15-log_result_errors/sql/item_sum.h ./026_mariadb-10.0.15-direct_aggregate/sql/item_sum.h
--- ./024_mariadb-10.0.15-log_result_errors/sql/item_sum.h	2014-11-29 17:02:32.059795158 +0900
+++ ./026_mariadb-10.0.15-direct_aggregate/sql/item_sum.h	2014-11-29 17:06:05.918796497 +0900
@@ -491,6 +491,7 @@ public:  
   Item *get_arg(uint i) { return args[i]; }
   Item *set_arg(uint i, THD *thd, Item *new_val);
   uint get_arg_count() const { return arg_count; }
+  virtual Item **get_args() { return fixed ? orig_args : args; }
 
   /* Initialization of distinct related members */
   void init_aggregator()
@@ -725,13 +726,18 @@ class Item_sum_sum :public Item_sum_num
 {
 protected:
   Item_result hybrid_type;
+  bool direct_added;
+  bool direct_sum_is_null;
+  double direct_sum_real;
   double sum;
+  my_decimal direct_sum_decimal;
   my_decimal dec_buffs[2];
   uint curr_dec_buff;
   void fix_length_and_dec();
 
 public:
-  Item_sum_sum(Item *item_par, bool distinct) :Item_sum_num(item_par) 
+  Item_sum_sum(Item *item_par, bool distinct) :Item_sum_num(item_par),
+    direct_added(FALSE)
   {
     set_distinct(distinct);
   }
@@ -740,6 +746,9 @@ public:
   { 
     return has_with_distinct() ? SUM_DISTINCT_FUNC : SUM_FUNC; 
   }
+  void cleanup();
+  void direct_add(my_decimal *add_sum_decimal);
+  void direct_add(double add_sum_real, bool add_sum_is_null);
   void clear();
   bool add();
   double val_real();
@@ -760,17 +769,22 @@ public:
 
 class Item_sum_count :public Item_sum_int
 {
+  bool direct_counted;
+  longlong direct_count;
   longlong count;
 
   friend class Aggregator_distinct;
 
+  public:
+  void direct_add(longlong add_count);
+  private:
   void clear();
   bool add();
   void cleanup();
 
   public:
   Item_sum_count(Item *item_par)
-    :Item_sum_int(item_par),count(0)
+    :Item_sum_int(item_par),direct_counted(FALSE),count(0)
   {}
 
   /**
@@ -782,12 +796,12 @@ class Item_sum_count :public Item_sum_in
   */
 
   Item_sum_count(List<Item> &list)
-    :Item_sum_int(list),count(0)
+    :Item_sum_int(list),direct_counted(FALSE),count(0)
   {
     set_distinct(TRUE);
   }
   Item_sum_count(THD *thd, Item_sum_count *item)
-    :Item_sum_int(thd, item), count(item->count)
+    :Item_sum_int(thd, item), direct_counted(FALSE), count(item->count)
   {}
   enum Sumfunctype sum_func () const 
   { 
@@ -1027,6 +1041,8 @@ class Item_cache;
 class Item_sum_hybrid :public Item_sum
 {
 protected:
+  bool direct_added;
+  Item *direct_item;
   Item_cache *value, *arg_cache;
   Arg_comparator *cmp;
   Item_result hybrid_type;
@@ -1037,18 +1053,19 @@ protected:
 
   public:
   Item_sum_hybrid(Item *item_par,int sign)
-    :Item_sum(item_par), value(0), arg_cache(0), cmp(0),
+    :Item_sum(item_par), direct_added(FALSE), value(0), arg_cache(0), cmp(0),
     hybrid_type(INT_RESULT), hybrid_field_type(MYSQL_TYPE_LONGLONG),
     cmp_sign(sign), was_values(TRUE)
   { collation.set(&my_charset_bin); }
   Item_sum_hybrid(THD *thd, Item_sum_hybrid *item)
-    :Item_sum(thd, item), value(item->value), arg_cache(0),
+    :Item_sum(thd, item), direct_added(FALSE), value(item->value), arg_cache(0),
     hybrid_type(item->hybrid_type), hybrid_field_type(item->hybrid_field_type),
     cmp_sign(item->cmp_sign), was_values(item->was_values)
   { }
   bool fix_fields(THD *, Item **);
   void setup_hybrid(Item *item, Item *value_arg);
   void clear();
+  void direct_add(Item *item);
   double val_real();
   longlong val_int();
   my_decimal *val_decimal(my_decimal *);
