Item_sum_hybrid::fix_fields(THD *thd, Item **ref)
{
  DBUG_ASSERT(fixed == 0);

  Item *item= args[0];

  if (init_sum_func_check(thd))
    return TRUE;

  // 'item' can be changed during fix_fields
  if ((!item->fixed && item->fix_fields(thd, args)) ||
      (item= args[0])->check_cols(1))
    return TRUE;
  Type_std_attributes::set(args[0]);
  with_subselect= args[0]->with_subselect;
  with_param= args[0]->with_param;
  with_window_func|= args[0]->with_window_func;

  Item *item2= item->real_item();
  if (item2->type() == Item::FIELD_ITEM)
    set_handler_by_field_type(((Item_field*) item2)->field->type());
  else if (item->cmp_type() == TIME_RESULT)
    set_handler_by_field_type(item2->field_type());
  else
    set_handler_by_result_type(item2->result_type(),
                               max_length, collation.collation);

  switch (Item_sum_hybrid::result_type()) {
  case INT_RESULT:
  case DECIMAL_RESULT:
  case STRING_RESULT:
    break;
  case REAL_RESULT:
    max_length= float_length(decimals);
    break;
  case ROW_RESULT:
  case TIME_RESULT:
    DBUG_ASSERT(0);
  };
  if (!is_window_func_sum_expr())
    setup_hybrid(thd, args[0], NULL);
  /* MIN/MAX can return NULL for empty set independent of the used column */
  maybe_null= 1;
  result_field=0;
  null_value=1;
  if (fix_length_and_dec() ||
      check_sum_func(thd, ref))
    return TRUE;

  orig_args[0]= args[0];
  fixed= 1;
  return FALSE;
}
Item_sum_hybrid::fix_fields(THD *thd, Item **ref)
{
  DBUG_ASSERT(fixed == 0);

  Item *item= args[0];

  if (init_sum_func_check(thd))
    return TRUE;

   
  if ((!item->fixed && item->fix_fields(thd, args)) ||
      (item= args[0])->check_cols(1))
    return TRUE;
  Type_std_attributes::set(args[0]);
  with_subselect= args[0]->with_subselect;
  with_param= args[0]->with_param;
  with_window_func|= args[0]->with_window_func;

  Item *item2= item->real_item();
  if (item2->type() == Item::FIELD_ITEM)
    set_handler_by_field_type(((Item_field*) item2)->field->type());
  else if (item->cmp_type() == TIME_RESULT)
    set_handler_by_field_type(item2->field_type());
  else
    set_handler_by_result_type(item2->result_type(),
                               max_length, collation.collation);

  switch (Item_sum_hybrid::result_type()) {
  case INT_RESULT:
  case DECIMAL_RESULT:
  case STRING_RESULT:
    break;
  case REAL_RESULT:
    max_length= float_length(decimals);
    break;
  case ROW_RESULT:
  case TIME_RESULT:
    DBUG_ASSERT(0);
  };
  if (!is_window_func_sum_expr())
    setup_hybrid(thd, args[0], NULL);
   
  maybe_null= 1;
  result_field=0;
  null_value=1;
  if (fix_length_and_dec() ||
      check_sum_func(thd, ref))
    return TRUE;

  orig_args[0]= args[0];
  fixed= 1;
  return FALSE;
}