mirror of
https://github.com/MariaDB/server.git
synced 2025-01-16 12:02:42 +01:00
MDEV-10669: Crash in SELECT with window function used
Make sure to call split_sum_func on all items that contain window functions, so that all the column references are set up correctly.
This commit is contained in:
parent
2857ff3c98
commit
5cb568786a
3 changed files with 40 additions and 1 deletions
|
@ -2211,3 +2211,28 @@ a b simple_sum sum_and_const sum_and_sum
|
|||
3.0000000000 2 5.5000000000 6.5000000000 11.5000000000
|
||||
4.5000000000 2 10.0000000000 11.0000000000 18.0000000000
|
||||
drop table t;
|
||||
#
|
||||
# MDEV-10669: Crash in SELECT with window function used
|
||||
#
|
||||
create table t(a decimal(35,10), b int);
|
||||
insert into t(a,b) values(1,1);
|
||||
insert into t(a,b) values(2,1);
|
||||
insert into t(a,b) values(0,1);
|
||||
SELECT (CASE WHEN sum(t.a) over (partition by t.b)=0 THEN null ELSE null END) AS a FROM t;
|
||||
a
|
||||
NULL
|
||||
NULL
|
||||
NULL
|
||||
SELECT ifnull(((t.a) / CASE WHEN sum(t.a) over(partition by t.b) =0 then null else null end) ,0) from t;
|
||||
ifnull(((t.a) / CASE WHEN sum(t.a) over(partition by t.b) =0 then null else null end) ,0)
|
||||
0.00000000000000
|
||||
0.00000000000000
|
||||
0.00000000000000
|
||||
SELECT sum(t.a) over (partition by t.b order by a),
|
||||
sqrt(ifnull((sum(t.a) over (partition by t.b order by a)), 0))
|
||||
from t;
|
||||
sum(t.a) over (partition by t.b order by a) sqrt(ifnull((sum(t.a) over (partition by t.b order by a)), 0))
|
||||
1.0000000000 1
|
||||
3.0000000000 1.7320508075688772
|
||||
0.0000000000 0
|
||||
drop table t;
|
||||
|
|
|
@ -1357,3 +1357,17 @@ select a, b,
|
|||
from t
|
||||
order by t.b, t.a;
|
||||
drop table t;
|
||||
|
||||
--echo #
|
||||
--echo # MDEV-10669: Crash in SELECT with window function used
|
||||
--echo #
|
||||
create table t(a decimal(35,10), b int);
|
||||
insert into t(a,b) values(1,1);
|
||||
insert into t(a,b) values(2,1);
|
||||
insert into t(a,b) values(0,1);
|
||||
SELECT (CASE WHEN sum(t.a) over (partition by t.b)=0 THEN null ELSE null END) AS a FROM t;
|
||||
SELECT ifnull(((t.a) / CASE WHEN sum(t.a) over(partition by t.b) =0 then null else null end) ,0) from t;
|
||||
SELECT sum(t.a) over (partition by t.b order by a),
|
||||
sqrt(ifnull((sum(t.a) over (partition by t.b order by a)), 0))
|
||||
from t;
|
||||
drop table t;
|
||||
|
|
|
@ -1870,7 +1870,7 @@ void Item::split_sum_func2(THD *thd, Ref_ptr_array ref_pointer_array,
|
|||
((Item_sum *) this)->ref_by)
|
||||
return;
|
||||
}
|
||||
else if (type() == WINDOW_FUNC_ITEM)
|
||||
else if (type() == WINDOW_FUNC_ITEM || with_window_func)
|
||||
{
|
||||
/*
|
||||
Skip the else part, window functions are very special functions:
|
||||
|
|
Loading…
Reference in a new issue