Skip to content

Commit 174a0b9

Browse files
author
Alexander Barkov
committed
Clean-up: Item_sum_variance and Item_variance_field had hybrid type
infrastructure, though in fact they always return REAL result. Removing hybrid type artifacts.
1 parent de1a48e commit 174a0b9

File tree

2 files changed

+7
-62
lines changed

2 files changed

+7
-62
lines changed

sql/item_sum.cc

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,7 +1829,7 @@ static double variance_fp_recurrence_result(double s, ulonglong count, bool is_s
18291829

18301830

18311831
Item_sum_variance::Item_sum_variance(THD *thd, Item_sum_variance *item):
1832-
Item_sum_num(thd, item), hybrid_type(item->hybrid_type),
1832+
Item_sum_num(thd, item),
18331833
count(item->count), sample(item->sample),
18341834
prec_increment(item->prec_increment)
18351835
{
@@ -1850,7 +1850,6 @@ void Item_sum_variance::fix_length_and_dec()
18501850
type of the result is an implementation-defined aproximate numeric
18511851
type.
18521852
*/
1853-
hybrid_type= REAL_RESULT;
18541853

18551854
switch (args[0]->result_type()) {
18561855
case REAL_RESULT:
@@ -2712,29 +2711,6 @@ double Item_std_field::val_real()
27122711
}
27132712

27142713

2715-
my_decimal *Item_std_field::val_decimal(my_decimal *dec_buf)
2716-
{
2717-
/*
2718-
We can't call val_decimal_from_real() for DECIMAL_RESULT as
2719-
Item_variance_field::val_real() would cause an infinite loop
2720-
*/
2721-
my_decimal tmp_dec, *dec;
2722-
double nr;
2723-
if (hybrid_type == REAL_RESULT)
2724-
return val_decimal_from_real(dec_buf);
2725-
2726-
dec= Item_variance_field::val_decimal(dec_buf);
2727-
if (!dec)
2728-
return 0;
2729-
my_decimal2double(E_DEC_FATAL_ERROR, dec, &nr);
2730-
DBUG_ASSERT(nr >= 0.0);
2731-
nr= sqrt(nr);
2732-
double2my_decimal(E_DEC_FATAL_ERROR, nr, &tmp_dec);
2733-
my_decimal_round(E_DEC_FATAL_ERROR, &tmp_dec, decimals, FALSE, dec_buf);
2734-
return dec_buf;
2735-
}
2736-
2737-
27382714
Item_variance_field::Item_variance_field(THD *thd, Item_sum_variance *item):
27392715
Item_result_field(thd)
27402716
{
@@ -2745,25 +2721,12 @@ Item_variance_field::Item_variance_field(THD *thd, Item_sum_variance *item):
27452721
field=item->result_field;
27462722
maybe_null=1;
27472723
sample= item->sample;
2748-
prec_increment= item->prec_increment;
2749-
if ((hybrid_type= item->hybrid_type) == DECIMAL_RESULT)
2750-
{
2751-
f_scale0= item->f_scale0;
2752-
f_precision0= item->f_precision0;
2753-
dec_bin_size0= item->dec_bin_size0;
2754-
f_scale1= item->f_scale1;
2755-
f_precision1= item->f_precision1;
2756-
dec_bin_size1= item->dec_bin_size1;
2757-
}
27582724
}
27592725

27602726

27612727
double Item_variance_field::val_real()
27622728
{
27632729
// fix_fields() never calls for this Item
2764-
if (hybrid_type == DECIMAL_RESULT)
2765-
return val_real_from_decimal();
2766-
27672730
double recurrence_s;
27682731
ulonglong count;
27692732
float8get(recurrence_s, (field->ptr + sizeof(double)));

sql/item_sum.h

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -826,11 +826,11 @@ class Item_sum_avg;
826826

827827
class Item_avg_field :public Item_result_field
828828
{
829-
public:
830829
Field *field;
831830
Item_result hybrid_type;
832831
uint f_precision, f_scale, dec_bin_size;
833832
uint prec_increment;
833+
public:
834834
Item_avg_field(THD *thd, Item_result res_type, Item_sum_avg *item);
835835
enum Type type() const { return FIELD_AVG_ITEM; }
836836
double val_real();
@@ -898,14 +898,9 @@ class Item_sum_variance;
898898

899899
class Item_variance_field :public Item_result_field
900900
{
901-
public:
902901
Field *field;
903-
Item_result hybrid_type;
904-
uint f_precision0, f_scale0;
905-
uint f_precision1, f_scale1;
906-
uint dec_bin_size0, dec_bin_size1;
907902
uint sample;
908-
uint prec_increment;
903+
public:
909904
Item_variance_field(THD *thd, Item_sum_variance *item);
910905
enum Type type() const {return FIELD_VARIANCE_ITEM; }
911906
double val_real();
@@ -916,12 +911,8 @@ class Item_variance_field :public Item_result_field
916911
my_decimal *val_decimal(my_decimal *dec_buf)
917912
{ return val_decimal_from_real(dec_buf); }
918913
bool is_null() { update_null_value(); return null_value; }
919-
enum_field_types field_type() const
920-
{
921-
return hybrid_type == DECIMAL_RESULT ?
922-
MYSQL_TYPE_NEWDECIMAL : MYSQL_TYPE_DOUBLE;
923-
}
924-
enum Item_result result_type () const { return hybrid_type; }
914+
enum_field_types field_type() const { return MYSQL_TYPE_DOUBLE; }
915+
enum Item_result result_type () const { return REAL_RESULT; }
925916
bool check_vcol_func_processor(uchar *int_arg)
926917
{
927918
return trace_unsupported_by_check_vcol_func_processor("var_field");
@@ -954,18 +945,13 @@ class Item_sum_variance : public Item_sum_num
954945
void fix_length_and_dec();
955946

956947
public:
957-
Item_result hybrid_type;
958-
int cur_dec;
959948
double recurrence_m, recurrence_s; /* Used in recurrence relation. */
960949
ulonglong count;
961-
uint f_precision0, f_scale0;
962-
uint f_precision1, f_scale1;
963-
uint dec_bin_size0, dec_bin_size1;
964950
uint sample;
965951
uint prec_increment;
966952

967953
Item_sum_variance(THD *thd, Item *item_par, uint sample_arg):
968-
Item_sum_num(thd, item_par), hybrid_type(REAL_RESULT), count(0),
954+
Item_sum_num(thd, item_par), count(0),
969955
sample(sample_arg)
970956
{}
971957
Item_sum_variance(THD *thd, Item_sum_variance *item);
@@ -983,6 +969,7 @@ class Item_sum_variance : public Item_sum_num
983969
Item *copy_or_same(THD* thd);
984970
Field *create_tmp_field(bool group, TABLE *table, uint convert_blob_length);
985971
enum Item_result result_type () const { return REAL_RESULT; }
972+
enum_field_types field_type() const { return MYSQL_TYPE_DOUBLE;}
986973
void cleanup()
987974
{
988975
count= 0;
@@ -998,9 +985,6 @@ class Item_std_field :public Item_variance_field
998985
Item_std_field(THD *thd, Item_sum_std *item);
999986
enum Type type() const { return FIELD_STD_ITEM; }
1000987
double val_real();
1001-
my_decimal *val_decimal(my_decimal *);
1002-
enum Item_result result_type () const { return REAL_RESULT; }
1003-
enum_field_types field_type() const { return MYSQL_TYPE_DOUBLE;}
1004988
};
1005989

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

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

0 commit comments

Comments
 (0)