Skip to content

Commit 4ebdef2

Browse files
committed
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.
1 parent f381e73 commit 4ebdef2

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

mysql-test/r/win.result

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3029,3 +3029,29 @@ show warnings;
30293029
Level Code Message
30303030
set sql_mode=@sql_mode_save;
30313031
drop table t1;
3032+
#
3033+
# MDEV-12336: several functions over a window function
3034+
#
3035+
create table t1 (name varchar(10), cnt int);
3036+
insert into t1 values ('Fred', 23), ('Fred', 35), ('Joe', 10);
3037+
select q.name, q.row_cnt,
3038+
round( 100 * ( q.row_cnt /
3039+
sum(q.row_cnt) over
3040+
(
3041+
order by q.name
3042+
rows between
3043+
unbounded preceding and
3044+
unbounded following
3045+
)
3046+
),2
3047+
) pct_of_total
3048+
from
3049+
(
3050+
select name, count(*) row_cnt, sum(cnt) sum_cnt
3051+
from t1
3052+
group by 1
3053+
) q;
3054+
name row_cnt pct_of_total
3055+
Fred 2 66.67
3056+
Joe 1 33.33
3057+
drop table t1;

mysql-test/t/win.test

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1830,3 +1830,29 @@ set sql_mode=@sql_mode_save;
18301830

18311831
drop table t1;
18321832

1833+
--echo #
1834+
--echo # MDEV-12336: several functions over a window function
1835+
--echo #
1836+
1837+
create table t1 (name varchar(10), cnt int);
1838+
insert into t1 values ('Fred', 23), ('Fred', 35), ('Joe', 10);
1839+
1840+
select q.name, q.row_cnt,
1841+
round( 100 * ( q.row_cnt /
1842+
sum(q.row_cnt) over
1843+
(
1844+
order by q.name
1845+
rows between
1846+
unbounded preceding and
1847+
unbounded following
1848+
)
1849+
),2
1850+
) pct_of_total
1851+
from
1852+
(
1853+
select name, count(*) row_cnt, sum(cnt) sum_cnt
1854+
from t1
1855+
group by 1
1856+
) q;
1857+
1858+
drop table t1;

sql/item.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1986,6 +1986,9 @@ void Item::split_sum_func2(THD *thd, Ref_ptr_array ref_pointer_array,
19861986
&ref_pointer_array[el], 0, name))))
19871987
return; // fatal_error is set
19881988
}
1989+
else if (type() == FUNC_ITEM &&
1990+
((Item_func *) this)->with_window_func)
1991+
return;
19891992
else
19901993
{
19911994
if (!(item_ref= (new (thd->mem_root)

0 commit comments

Comments
 (0)