Skip to content

Commit

Permalink
Clean-up: Item_sum_variance and Item_variance_field had hybrid type
Browse files Browse the repository at this point in the history
infrastructure, though in fact they always return REAL result.
Removing hybrid type artifacts.
  • Loading branch information
Alexander Barkov committed Oct 8, 2015
1 parent de1a48e commit 174a0b9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 62 deletions.
39 changes: 1 addition & 38 deletions sql/item_sum.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1829,7 +1829,7 @@ static double variance_fp_recurrence_result(double s, ulonglong count, bool is_s


Item_sum_variance::Item_sum_variance(THD *thd, Item_sum_variance *item):
Item_sum_num(thd, item), hybrid_type(item->hybrid_type),
Item_sum_num(thd, item),
count(item->count), sample(item->sample),
prec_increment(item->prec_increment)
{
Expand All @@ -1850,7 +1850,6 @@ void Item_sum_variance::fix_length_and_dec()
type of the result is an implementation-defined aproximate numeric
type.
*/
hybrid_type= REAL_RESULT;

switch (args[0]->result_type()) {
case REAL_RESULT:
Expand Down Expand Up @@ -2712,29 +2711,6 @@ double Item_std_field::val_real()
}


my_decimal *Item_std_field::val_decimal(my_decimal *dec_buf)
{
/*
We can't call val_decimal_from_real() for DECIMAL_RESULT as
Item_variance_field::val_real() would cause an infinite loop
*/
my_decimal tmp_dec, *dec;
double nr;
if (hybrid_type == REAL_RESULT)
return val_decimal_from_real(dec_buf);

dec= Item_variance_field::val_decimal(dec_buf);
if (!dec)
return 0;
my_decimal2double(E_DEC_FATAL_ERROR, dec, &nr);
DBUG_ASSERT(nr >= 0.0);
nr= sqrt(nr);
double2my_decimal(E_DEC_FATAL_ERROR, nr, &tmp_dec);
my_decimal_round(E_DEC_FATAL_ERROR, &tmp_dec, decimals, FALSE, dec_buf);
return dec_buf;
}


Item_variance_field::Item_variance_field(THD *thd, Item_sum_variance *item):
Item_result_field(thd)
{
Expand All @@ -2745,25 +2721,12 @@ Item_variance_field::Item_variance_field(THD *thd, Item_sum_variance *item):
field=item->result_field;
maybe_null=1;
sample= item->sample;
prec_increment= item->prec_increment;
if ((hybrid_type= item->hybrid_type) == DECIMAL_RESULT)
{
f_scale0= item->f_scale0;
f_precision0= item->f_precision0;
dec_bin_size0= item->dec_bin_size0;
f_scale1= item->f_scale1;
f_precision1= item->f_precision1;
dec_bin_size1= item->dec_bin_size1;
}
}


double Item_variance_field::val_real()
{
// fix_fields() never calls for this Item
if (hybrid_type == DECIMAL_RESULT)
return val_real_from_decimal();

double recurrence_s;
ulonglong count;
float8get(recurrence_s, (field->ptr + sizeof(double)));
Expand Down
30 changes: 6 additions & 24 deletions sql/item_sum.h
Original file line number Diff line number Diff line change
Expand Up @@ -826,11 +826,11 @@ class Item_sum_avg;

class Item_avg_field :public Item_result_field
{
public:
Field *field;
Item_result hybrid_type;
uint f_precision, f_scale, dec_bin_size;
uint prec_increment;
public:
Item_avg_field(THD *thd, Item_result res_type, Item_sum_avg *item);
enum Type type() const { return FIELD_AVG_ITEM; }
double val_real();
Expand Down Expand Up @@ -898,14 +898,9 @@ class Item_sum_variance;

class Item_variance_field :public Item_result_field
{
public:
Field *field;
Item_result hybrid_type;
uint f_precision0, f_scale0;
uint f_precision1, f_scale1;
uint dec_bin_size0, dec_bin_size1;
uint sample;
uint prec_increment;
public:
Item_variance_field(THD *thd, Item_sum_variance *item);
enum Type type() const {return FIELD_VARIANCE_ITEM; }
double val_real();
Expand All @@ -916,12 +911,8 @@ class Item_variance_field :public Item_result_field
my_decimal *val_decimal(my_decimal *dec_buf)
{ return val_decimal_from_real(dec_buf); }
bool is_null() { update_null_value(); return null_value; }
enum_field_types field_type() const
{
return hybrid_type == DECIMAL_RESULT ?
MYSQL_TYPE_NEWDECIMAL : MYSQL_TYPE_DOUBLE;
}
enum Item_result result_type () const { return hybrid_type; }
enum_field_types field_type() const { return MYSQL_TYPE_DOUBLE; }
enum Item_result result_type () const { return REAL_RESULT; }
bool check_vcol_func_processor(uchar *int_arg)
{
return trace_unsupported_by_check_vcol_func_processor("var_field");
Expand Down Expand Up @@ -954,18 +945,13 @@ class Item_sum_variance : public Item_sum_num
void fix_length_and_dec();

public:
Item_result hybrid_type;
int cur_dec;
double recurrence_m, recurrence_s; /* Used in recurrence relation. */
ulonglong count;
uint f_precision0, f_scale0;
uint f_precision1, f_scale1;
uint dec_bin_size0, dec_bin_size1;
uint sample;
uint prec_increment;

Item_sum_variance(THD *thd, Item *item_par, uint sample_arg):
Item_sum_num(thd, item_par), hybrid_type(REAL_RESULT), count(0),
Item_sum_num(thd, item_par), count(0),
sample(sample_arg)
{}
Item_sum_variance(THD *thd, Item_sum_variance *item);
Expand All @@ -983,6 +969,7 @@ class Item_sum_variance : public Item_sum_num
Item *copy_or_same(THD* thd);
Field *create_tmp_field(bool group, TABLE *table, uint convert_blob_length);
enum Item_result result_type () const { return REAL_RESULT; }
enum_field_types field_type() const { return MYSQL_TYPE_DOUBLE;}
void cleanup()
{
count= 0;
Expand All @@ -998,9 +985,6 @@ class Item_std_field :public Item_variance_field
Item_std_field(THD *thd, Item_sum_std *item);
enum Type type() const { return FIELD_STD_ITEM; }
double val_real();
my_decimal *val_decimal(my_decimal *);
enum Item_result result_type () const { return REAL_RESULT; }
enum_field_types field_type() const { return MYSQL_TYPE_DOUBLE;}
};

/*
Expand All @@ -1020,8 +1004,6 @@ class Item_sum_std :public Item_sum_variance
Item *result_item(THD *thd, Field *field);
const char *func_name() const { return "std("; }
Item *copy_or_same(THD* thd);
enum Item_result result_type () const { return REAL_RESULT; }
enum_field_types field_type() const { return MYSQL_TYPE_DOUBLE;}
};

// This class is a string or number function depending on num_func
Expand Down

0 comments on commit 174a0b9

Please sign in to comment.