Loading mysql-test/r/analyse.result +3 −3 Original line number Diff line number Diff line Loading @@ -107,7 +107,7 @@ insert into t1 values(1.1); insert into t1 values(2.2); select * from t1 procedure analyse(); Field_name Min_value Max_value Min_length Max_length Empties_or_zeros Nulls Avg_value_or_avg_length Std Optimal_fieldtype test.t1.df 1.1 2.2 8 8 0 0 1.650000000 0.55000 ENUM('1.1','2.2') NOT NULL test.t1.df 1.1 2.2 13 13 0 0 1.65000 0.55000 ENUM('1.1','2.2') NOT NULL drop table t1; create table t1 (d double); insert into t1 values (100000); Loading Loading @@ -138,6 +138,6 @@ insert into t2 values (1, 'USA'),(2,'India'), (3,'Finland'); select product, sum(profit),avg(profit) from t1 group by product with rollup procedure analyse(); Field_name Min_value Max_value Min_length Max_length Empties_or_zeros Nulls Avg_value_or_avg_length Std Optimal_fieldtype test.t1.product Computer TV 2 8 0 0 4.2500 NULL ENUM('Computer','Phone','TV') NOT NULL sum(profit) 10 6900 11 11 0 0 1946 2867.6719 ENUM('10','275','600','6900') NOT NULL avg(profit) 10.000000000 1380.000000000 21 21 0 0 394.687500000 570.20033144 ENUM('10.0000','68.7500','120.0000','1380.0000') NOT NULL sum(profit) 10 6900 11 11 0 0 1946.2500 2867.6719 ENUM('10','275','600','6900') NOT NULL avg(profit) 10.0000 1380.0000 16 16 0 0 394.68750000 570.20033144 ENUM('10.0000','68.7500','120.0000','1380.0000') NOT NULL drop table t1,t2; mysql-test/t/disabled.def +1 −0 Original line number Diff line number Diff line Loading @@ -16,3 +16,4 @@ rpl_until : Unstable test case, bug#12429 rpl_deadlock : Unstable test case, bug#12429 kill : Unstable test case, bug#9712 archive_gis : The test fails on 32bit Linux user_var : Ramil should fix this soon sql/sql_analyse.cc +14 −3 Original line number Diff line number Diff line Loading @@ -466,7 +466,9 @@ void field_real::add() void field_decimal::add() { /*TODO - remove rounding stuff after decimal_div returns proper frac */ my_decimal dec_buf, *dec= item->val_decimal(&dec_buf); my_decimal rounded; uint length; TREE_ELEMENT *element; Loading @@ -476,6 +478,9 @@ void field_decimal::add() return; } my_decimal_round(E_DEC_FATAL_ERROR, dec, item->decimals, FALSE,&rounded); dec= &rounded; length= my_decimal_string_length(dec); if (decimal_is_zero(dec)) Loading Loading @@ -1021,10 +1026,16 @@ String *field_decimal::avg(String *s, ha_rows rows) s->set((double) 0.0, 1,my_thd_charset); return s; } my_decimal num, avg_val; my_decimal num, avg_val, rounded_avg; int prec_increment= current_thd->variables.div_precincrement; int2my_decimal(E_DEC_FATAL_ERROR, rows - nulls, FALSE, &num); my_decimal_div(E_DEC_FATAL_ERROR, &avg_val, sum+cur_sum, &num, 0); my_decimal2string(E_DEC_FATAL_ERROR, &avg_val, 0, 0, '0', s); my_decimal_div(E_DEC_FATAL_ERROR, &avg_val, sum+cur_sum, &num, prec_increment); /* TODO remove this after decimal_div returns proper frac */ my_decimal_round(E_DEC_FATAL_ERROR, &avg_val, min(sum[cur_sum].frac + prec_increment, DECIMAL_MAX_SCALE), FALSE,&rounded_avg); my_decimal2string(E_DEC_FATAL_ERROR, &rounded_avg, 0, 0, '0', s); return s; } Loading Loading
mysql-test/r/analyse.result +3 −3 Original line number Diff line number Diff line Loading @@ -107,7 +107,7 @@ insert into t1 values(1.1); insert into t1 values(2.2); select * from t1 procedure analyse(); Field_name Min_value Max_value Min_length Max_length Empties_or_zeros Nulls Avg_value_or_avg_length Std Optimal_fieldtype test.t1.df 1.1 2.2 8 8 0 0 1.650000000 0.55000 ENUM('1.1','2.2') NOT NULL test.t1.df 1.1 2.2 13 13 0 0 1.65000 0.55000 ENUM('1.1','2.2') NOT NULL drop table t1; create table t1 (d double); insert into t1 values (100000); Loading Loading @@ -138,6 +138,6 @@ insert into t2 values (1, 'USA'),(2,'India'), (3,'Finland'); select product, sum(profit),avg(profit) from t1 group by product with rollup procedure analyse(); Field_name Min_value Max_value Min_length Max_length Empties_or_zeros Nulls Avg_value_or_avg_length Std Optimal_fieldtype test.t1.product Computer TV 2 8 0 0 4.2500 NULL ENUM('Computer','Phone','TV') NOT NULL sum(profit) 10 6900 11 11 0 0 1946 2867.6719 ENUM('10','275','600','6900') NOT NULL avg(profit) 10.000000000 1380.000000000 21 21 0 0 394.687500000 570.20033144 ENUM('10.0000','68.7500','120.0000','1380.0000') NOT NULL sum(profit) 10 6900 11 11 0 0 1946.2500 2867.6719 ENUM('10','275','600','6900') NOT NULL avg(profit) 10.0000 1380.0000 16 16 0 0 394.68750000 570.20033144 ENUM('10.0000','68.7500','120.0000','1380.0000') NOT NULL drop table t1,t2;
mysql-test/t/disabled.def +1 −0 Original line number Diff line number Diff line Loading @@ -16,3 +16,4 @@ rpl_until : Unstable test case, bug#12429 rpl_deadlock : Unstable test case, bug#12429 kill : Unstable test case, bug#9712 archive_gis : The test fails on 32bit Linux user_var : Ramil should fix this soon
sql/sql_analyse.cc +14 −3 Original line number Diff line number Diff line Loading @@ -466,7 +466,9 @@ void field_real::add() void field_decimal::add() { /*TODO - remove rounding stuff after decimal_div returns proper frac */ my_decimal dec_buf, *dec= item->val_decimal(&dec_buf); my_decimal rounded; uint length; TREE_ELEMENT *element; Loading @@ -476,6 +478,9 @@ void field_decimal::add() return; } my_decimal_round(E_DEC_FATAL_ERROR, dec, item->decimals, FALSE,&rounded); dec= &rounded; length= my_decimal_string_length(dec); if (decimal_is_zero(dec)) Loading Loading @@ -1021,10 +1026,16 @@ String *field_decimal::avg(String *s, ha_rows rows) s->set((double) 0.0, 1,my_thd_charset); return s; } my_decimal num, avg_val; my_decimal num, avg_val, rounded_avg; int prec_increment= current_thd->variables.div_precincrement; int2my_decimal(E_DEC_FATAL_ERROR, rows - nulls, FALSE, &num); my_decimal_div(E_DEC_FATAL_ERROR, &avg_val, sum+cur_sum, &num, 0); my_decimal2string(E_DEC_FATAL_ERROR, &avg_val, 0, 0, '0', s); my_decimal_div(E_DEC_FATAL_ERROR, &avg_val, sum+cur_sum, &num, prec_increment); /* TODO remove this after decimal_div returns proper frac */ my_decimal_round(E_DEC_FATAL_ERROR, &avg_val, min(sum[cur_sum].frac + prec_increment, DECIMAL_MAX_SCALE), FALSE,&rounded_avg); my_decimal2string(E_DEC_FATAL_ERROR, &rounded_avg, 0, 0, '0', s); return s; } Loading