Commit f8adc47b authored by Sergei Golubchik's avatar Sergei Golubchik

MDEV-19071 Wrong results when using STDDEV_SAMP() and view

parent 6710fe4b
...@@ -2552,5 +2552,19 @@ DROP TABLE t1; ...@@ -2552,5 +2552,19 @@ DROP TABLE t1;
# #
SET STATEMENT sql_mode=ONLY_FULL_GROUP_BY FOR EXECUTE IMMEDIATE 'ALTER TABLE mysql.time_zone_transition ORDER BY Time_zone_id, Transition_time'; SET STATEMENT sql_mode=ONLY_FULL_GROUP_BY FOR EXECUTE IMMEDIATE 'ALTER TABLE mysql.time_zone_transition ORDER BY Time_zone_id, Transition_time';
# #
# MDEV-19071 Wrong results when using STDDEV_SAMP() and view
#
create table t1(i int);
insert into t1 values (1),(2),(3),(4),(5);
create view v1 as select stddev_samp(i),stddev_pop(i),stddev(i),std(i) from t1;
show create view v1;
View Create View character_set_client collation_connection
v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select stddev_samp(`t1`.`i`) AS `stddev_samp(i)`,std(`t1`.`i`) AS `stddev_pop(i)`,std(`t1`.`i`) AS `stddev(i)`,std(`t1`.`i`) AS `std(i)` from `t1` latin1 latin1_swedish_ci
select * from v1;
stddev_samp(i) stddev_pop(i) stddev(i) std(i)
1.5811 1.4142 1.4142 1.4142
drop view v1;
drop table t1;
#
# End of 10.3 tests # End of 10.3 tests
# #
...@@ -1789,6 +1789,17 @@ DROP TABLE t1; ...@@ -1789,6 +1789,17 @@ DROP TABLE t1;
SET STATEMENT sql_mode=ONLY_FULL_GROUP_BY FOR EXECUTE IMMEDIATE 'ALTER TABLE mysql.time_zone_transition ORDER BY Time_zone_id, Transition_time'; SET STATEMENT sql_mode=ONLY_FULL_GROUP_BY FOR EXECUTE IMMEDIATE 'ALTER TABLE mysql.time_zone_transition ORDER BY Time_zone_id, Transition_time';
--echo #
--echo # MDEV-19071 Wrong results when using STDDEV_SAMP() and view
--echo #
create table t1(i int);
insert into t1 values (1),(2),(3),(4),(5);
create view v1 as select stddev_samp(i),stddev_pop(i),stddev(i),std(i) from t1;
show create view v1;
select * from v1;
drop view v1;
drop table t1;
--echo # --echo #
--echo # End of 10.3 tests --echo # End of 10.3 tests
--echo # --echo #
...@@ -129,7 +129,7 @@ create table t1 (a int, b int generated always as (stddev_pop(a)) virtual); ...@@ -129,7 +129,7 @@ create table t1 (a int, b int generated always as (stddev_pop(a)) virtual);
ERROR HY000: Function or expression 'std()' cannot be used in the GENERATED ALWAYS AS clause of `b` ERROR HY000: Function or expression 'std()' cannot be used in the GENERATED ALWAYS AS clause of `b`
# STDDEV_SAMP() # STDDEV_SAMP()
create table t1 (a int, b int generated always as (stddev_samp(a)) virtual); create table t1 (a int, b int generated always as (stddev_samp(a)) virtual);
ERROR HY000: Function or expression 'std()' cannot be used in the GENERATED ALWAYS AS clause of `b` ERROR HY000: Function or expression 'stddev_samp()' cannot be used in the GENERATED ALWAYS AS clause of `b`
# STDDEV() # STDDEV()
create table t1 (a int, b int generated always as (stddev(a)) virtual); create table t1 (a int, b int generated always as (stddev(a)) virtual);
ERROR HY000: Function or expression 'std()' cannot be used in the GENERATED ALWAYS AS clause of `b` ERROR HY000: Function or expression 'std()' cannot be used in the GENERATED ALWAYS AS clause of `b`
......
...@@ -131,7 +131,7 @@ create table t1 (a int, b int generated always as (stddev_pop(a)) virtual); ...@@ -131,7 +131,7 @@ create table t1 (a int, b int generated always as (stddev_pop(a)) virtual);
ERROR HY000: Function or expression 'std()' cannot be used in the GENERATED ALWAYS AS clause of `b` ERROR HY000: Function or expression 'std()' cannot be used in the GENERATED ALWAYS AS clause of `b`
# STDDEV_SAMP() # STDDEV_SAMP()
create table t1 (a int, b int generated always as (stddev_samp(a)) virtual); create table t1 (a int, b int generated always as (stddev_samp(a)) virtual);
ERROR HY000: Function or expression 'std()' cannot be used in the GENERATED ALWAYS AS clause of `b` ERROR HY000: Function or expression 'stddev_samp()' cannot be used in the GENERATED ALWAYS AS clause of `b`
# STDDEV() # STDDEV()
create table t1 (a int, b int generated always as (stddev(a)) virtual); create table t1 (a int, b int generated always as (stddev(a)) virtual);
ERROR HY000: Function or expression 'std()' cannot be used in the GENERATED ALWAYS AS clause of `b` ERROR HY000: Function or expression 'std()' cannot be used in the GENERATED ALWAYS AS clause of `b`
......
...@@ -191,7 +191,7 @@ create or replace table t1 (a int, b int as (stddev_pop(a))); ...@@ -191,7 +191,7 @@ create or replace table t1 (a int, b int as (stddev_pop(a)));
ERROR HY000: Function or expression 'std()' cannot be used in the GENERATED ALWAYS AS clause of `b` ERROR HY000: Function or expression 'std()' cannot be used in the GENERATED ALWAYS AS clause of `b`
# STDDEV_SAMP() # STDDEV_SAMP()
create or replace table t1 (a int, b int as (stddev_samp(a))); create or replace table t1 (a int, b int as (stddev_samp(a)));
ERROR HY000: Function or expression 'std()' cannot be used in the GENERATED ALWAYS AS clause of `b` ERROR HY000: Function or expression 'stddev_samp()' cannot be used in the GENERATED ALWAYS AS clause of `b`
# STDDEV() # STDDEV()
create or replace table t1 (a int, b int as (stddev(a))); create or replace table t1 (a int, b int as (stddev(a)));
ERROR HY000: Function or expression 'std()' cannot be used in the GENERATED ALWAYS AS clause of `b` ERROR HY000: Function or expression 'std()' cannot be used in the GENERATED ALWAYS AS clause of `b`
......
...@@ -1038,7 +1038,7 @@ class Item_sum_std :public Item_sum_variance ...@@ -1038,7 +1038,7 @@ class Item_sum_std :public Item_sum_variance
enum Sumfunctype sum_func () const { return STD_FUNC; } enum Sumfunctype sum_func () const { return STD_FUNC; }
double val_real(); double val_real();
Item *result_item(THD *thd, Field *field); Item *result_item(THD *thd, Field *field);
const char *func_name() const { return "std("; } const char *func_name() const { return sample ? "stddev_samp(" : "std("; }
Item *copy_or_same(THD* thd); Item *copy_or_same(THD* thd);
Item *get_copy(THD *thd) Item *get_copy(THD *thd)
{ return get_item_copy<Item_sum_std>(thd, this); } { return get_item_copy<Item_sum_std>(thd, this); }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment