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.
This commit is contained in:
Igor Babaev 2017-03-28 15:08:50 -07:00
parent f381e73f7d
commit 4ebdef2bcd
3 changed files with 55 additions and 0 deletions

View file

@ -3029,3 +3029,29 @@ show warnings;
Level Code Message
set sql_mode=@sql_mode_save;
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;

View file

@ -1830,3 +1830,29 @@ set sql_mode=@sql_mode_save;
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;

View file

@ -1986,6 +1986,9 @@ void Item::split_sum_func2(THD *thd, Ref_ptr_array ref_pointer_array,
&ref_pointer_array[el], 0, name))))
return; // fatal_error is set
}
else if (type() == FUNC_ITEM &&
((Item_func *) this)->with_window_func)
return;
else
{
if (!(item_ref= (new (thd->mem_root)