Commit 4ebdef2b authored by Igor Babaev's avatar Igor Babaev

Fixed bug mdev-12336.

The function Item::split_sum_func2() incorrectly processed the function
items with window functions that were not window functions themselfes
and were used as arguments of other functions.
parent f381e73f
...@@ -3029,3 +3029,29 @@ show warnings; ...@@ -3029,3 +3029,29 @@ show warnings;
Level Code Message Level Code Message
set sql_mode=@sql_mode_save; set sql_mode=@sql_mode_save;
drop table t1; drop table t1;
#
# MDEV-12336: several functions over a window function
#
create table t1 (name varchar(10), cnt int);
insert into t1 values ('Fred', 23), ('Fred', 35), ('Joe', 10);
select q.name, q.row_cnt,
round( 100 * ( q.row_cnt /
sum(q.row_cnt) over
(
order by q.name
rows between
unbounded preceding and
unbounded following
)
),2
) pct_of_total
from
(
select name, count(*) row_cnt, sum(cnt) sum_cnt
from t1
group by 1
) q;
name row_cnt pct_of_total
Fred 2 66.67
Joe 1 33.33
drop table t1;
...@@ -1830,3 +1830,29 @@ set sql_mode=@sql_mode_save; ...@@ -1830,3 +1830,29 @@ set sql_mode=@sql_mode_save;
drop table t1; drop table t1;
--echo #
--echo # MDEV-12336: several functions over a window function
--echo #
create table t1 (name varchar(10), cnt int);
insert into t1 values ('Fred', 23), ('Fred', 35), ('Joe', 10);
select q.name, q.row_cnt,
round( 100 * ( q.row_cnt /
sum(q.row_cnt) over
(
order by q.name
rows between
unbounded preceding and
unbounded following
)
),2
) pct_of_total
from
(
select name, count(*) row_cnt, sum(cnt) sum_cnt
from t1
group by 1
) q;
drop table t1;
...@@ -1986,6 +1986,9 @@ void Item::split_sum_func2(THD *thd, Ref_ptr_array ref_pointer_array, ...@@ -1986,6 +1986,9 @@ void Item::split_sum_func2(THD *thd, Ref_ptr_array ref_pointer_array,
&ref_pointer_array[el], 0, name)))) &ref_pointer_array[el], 0, name))))
return; // fatal_error is set return; // fatal_error is set
} }
else if (type() == FUNC_ITEM &&
((Item_func *) this)->with_window_func)
return;
else else
{ {
if (!(item_ref= (new (thd->mem_root) if (!(item_ref= (new (thd->mem_root)
......
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