diff options
author | Igor Babaev <igor@askmonty.org> | 2017-03-28 14:48:54 -0700 |
---|---|---|
committer | Igor Babaev <igor@askmonty.org> | 2017-03-29 08:46:00 -0700 |
commit | f381e73f7da7ae97536cb334b95c1e99dbb7a06f (patch) | |
tree | f1391961c8d5498342996c30ac5e23fb09237246 | |
parent | d9bab412e99adce6f9f81c141a42a2d66c77189e (diff) | |
download | mariadb-git-f381e73f7da7ae97536cb334b95c1e99dbb7a06f.tar.gz |
Fixed bug mdev-11907.
With the current design the function copy_funcs() should ignore
the items with window functions from the array **func_ptr.
-rw-r--r-- | mysql-test/r/win.result | 109 | ||||
-rw-r--r-- | mysql-test/t/win.test | 21 | ||||
-rw-r--r-- | sql/sql_select.cc | 3 |
3 files changed, 45 insertions, 88 deletions
diff --git a/mysql-test/r/win.result b/mysql-test/r/win.result index f0a9aea0419..d48bb34d982 100644 --- a/mysql-test/r/win.result +++ b/mysql-test/r/win.result @@ -2270,17 +2270,6 @@ pk c CNT 8 2 0.5000 9 2 0.6667 10 2 1.0000 -Warnings: -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 create view v1 as select pk, c, c/count(*) over (partition by c order by pk rows between 1 preceding and 2 following) as CNT from t1; @@ -2299,17 +2288,6 @@ pk c CNT 8 2 0.5000 9 2 0.6667 10 2 1.0000 -Warnings: -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 select pk, c, c/count(*) over w1 as CNT from t1 window w1 as (partition by c order by pk rows between 1 preceding and 2 following); pk c CNT @@ -2323,17 +2301,6 @@ pk c CNT 8 2 0.5000 9 2 0.6667 10 2 1.0000 -Warnings: -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 create view v2 as select pk, c, c/count(*) over w1 as CNT from t1 window w1 as (partition by c order by pk rows between 1 preceding and 2 following); show create view v2; @@ -2351,17 +2318,6 @@ pk c CNT 8 2 0.5000 9 2 0.6667 10 2 1.0000 -Warnings: -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 select pk, c, c/count(*) over w1 as CNT from t1 window w1 as (partition by c order by pk rows unbounded preceding); pk c CNT @@ -2375,17 +2331,6 @@ pk c CNT 8 2 0.5000 9 2 0.4000 10 2 0.3333 -Warnings: -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 create view v3 as select pk, c, c/count(*) over w1 as CNT from t1 window w1 as (partition by c order by pk rows unbounded preceding); show create view v3; @@ -2403,17 +2348,6 @@ pk c CNT 8 2 0.5000 9 2 0.4000 10 2 0.3333 -Warnings: -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 select pk, c, c/count(*) over (partition by c order by pk range between 3 preceding and current row) as CNT from t1; @@ -2428,17 +2362,6 @@ pk c CNT 8 2 0.5000 9 2 0.5000 10 2 0.5000 -Warnings: -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 create view v4 as select pk, c, c/count(*) over (partition by c order by pk range between 3 preceding and current row) as CNT from t1; @@ -2457,17 +2380,6 @@ pk c CNT 8 2 0.5000 9 2 0.5000 10 2 0.5000 -Warnings: -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 -Warning 1365 Division by 0 drop view v1,v2,v3,v4; drop table t0,t1; # @@ -3096,3 +3008,24 @@ select i, rank() over (order by i) rnk from t1 group by 1+2; i rnk 2 1 drop table t1; +# +# MDEV-11907: window function as the second operand of division +# +create table t1 (pk int, c int); +insert into t1 values (1,1),(2,1),(3,1),(4,1),(5,2); +set @sql_mode_save= @@sql_mode; +set sql_mode='ERROR_FOR_DIVISION_BY_ZERO'; +select pk, c, c/count(*) over +(partition by c order by pk +rows between 1 preceding and 2 following) as CNT +from t1; +pk c CNT +1 1 0.3333 +2 1 0.2500 +3 1 0.3333 +4 1 0.5000 +5 2 2.0000 +show warnings; +Level Code Message +set sql_mode=@sql_mode_save; +drop table t1; diff --git a/mysql-test/t/win.test b/mysql-test/t/win.test index ec083733f77..3cd17ae179d 100644 --- a/mysql-test/t/win.test +++ b/mysql-test/t/win.test @@ -1809,3 +1809,24 @@ select i, row_number() over () from t1 group by 1+2; select i, rank() over (order by i) rnk from t1 group by 1+2; drop table t1; + +--echo # +--echo # MDEV-11907: window function as the second operand of division +--echo # + +create table t1 (pk int, c int); +insert into t1 values (1,1),(2,1),(3,1),(4,1),(5,2); + +set @sql_mode_save= @@sql_mode; +set sql_mode='ERROR_FOR_DIVISION_BY_ZERO'; + +select pk, c, c/count(*) over + (partition by c order by pk + rows between 1 preceding and 2 following) as CNT +from t1; +show warnings; + +set sql_mode=@sql_mode_save; + +drop table t1; + diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 5633881f53e..6f84b4a5762 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -23338,6 +23338,9 @@ copy_funcs(Item **func_ptr, const THD *thd) Item *func; for (; (func = *func_ptr) ; func_ptr++) { + if (func->type() == Item::FUNC_ITEM && + ((Item_func *) func)->with_window_func) + continue; func->save_in_result_field(1); /* Need to check the THD error state because Item::val_xxx() don't |