Commit 77885935 authored by Daniel Black's avatar Daniel Black

MDEV-19052 Range-type window frame supports only numeric datatype

When there is no bounds on the upper or lower part of the window,
it doesn't matter if the type is numeric.

It also doesn't matter how many ORDER BY items there are in the
query.

Reviewers: Sergei Petrunia and Oleg Smirnov
parent 26f31bdd
......@@ -1247,15 +1247,10 @@ insert into t1 values (1,1,'foo');
insert into t1 values (2,2,'bar');
select
count(*) over (order by a,b
range between unbounded preceding and current row) as count
range between 1 preceding and current row) as count
from t1;
ERROR HY000: RANGE-type frame requires ORDER BY clause with single sort key
select
count(*) over (order by c
range between unbounded preceding and current row) as count
from t1;
ERROR HY000: Numeric datatype is required for RANGE-type frame
select
count(*) over (order by a
range between 'abcd' preceding and current row) as count
from t1;
......@@ -1277,6 +1272,59 @@ rows between current row and 3.14 following) as count
from t1;
ERROR HY000: Integer is required for ROWS-type frame
#
# MDEV-19052 Range-type window frame supports only numeric datatype
#
select
count(*) over (order by c
range between unbounded preceding and current row)
from t1;
count(*) over (order by c
range between unbounded preceding and current row)
1
2
select
count(*) over (order by c
range between current row and unbounded following)
from t1;
count(*) over (order by c
range between current row and unbounded following)
2
1
select
count(*) over (order by c
range between unbounded preceding and unbounded following)
from t1;
count(*) over (order by c
range between unbounded preceding and unbounded following)
2
2
create table t2 (a int, b varchar(5));
insert into t2 values (1,'a'), (2, 'b'), (3, 'c');
select sum(a) over (order by b range between unbounded preceding and current row) from t2;
sum(a) over (order by b range between unbounded preceding and current row)
1
3
6
insert into t1 values (3,3,'goo');
insert into t1 values (3,1,'har');
insert into t1 values (1,4,'har');
select a, b, sum(b) over (order by a, b desc range between unbounded preceding and current row) from t1;
a b sum(b) over (order by a, b desc range between unbounded preceding and current row)
1 4 4
1 1 5
2 2 7
3 3 10
3 1 11
select a, b, sum(b) over (order by a desc, b range between unbounded preceding and current row) from t1;
a b sum(b) over (order by a desc, b range between unbounded preceding and current row)
3 1 1
3 3 4
2 2 6
1 1 7
1 4 11
drop table t2;
delete from t1 where a >= 3 or b = 4;
#
# EXCLUDE clause is parsed but not supported
#
select
......
......@@ -784,13 +784,7 @@ insert into t1 values (2,2,'bar');
--error ER_RANGE_FRAME_NEEDS_SIMPLE_ORDERBY
select
count(*) over (order by a,b
range between unbounded preceding and current row) as count
from t1;
--error ER_WRONG_TYPE_FOR_RANGE_FRAME
select
count(*) over (order by c
range between unbounded preceding and current row) as count
range between 1 preceding and current row) as count
from t1;
--error ER_WRONG_TYPE_FOR_RANGE_FRAME
......@@ -818,6 +812,41 @@ select
rows between current row and 3.14 following) as count
from t1;
--echo #
--echo # MDEV-19052 Range-type window frame supports only numeric datatype
--echo #
select
count(*) over (order by c
range between unbounded preceding and current row)
from t1;
select
count(*) over (order by c
range between current row and unbounded following)
from t1;
select
count(*) over (order by c
range between unbounded preceding and unbounded following)
from t1;
create table t2 (a int, b varchar(5));
insert into t2 values (1,'a'), (2, 'b'), (3, 'c');
select sum(a) over (order by b range between unbounded preceding and current row) from t2;
insert into t1 values (3,3,'goo');
insert into t1 values (3,1,'har');
insert into t1 values (1,4,'har');
select a, b, sum(b) over (order by a, b desc range between unbounded preceding and current row) from t1;
select a, b, sum(b) over (order by a desc, b range between unbounded preceding and current row) from t1;
drop table t2;
delete from t1 where a >= 3 or b = 4;
--echo #
--echo # EXCLUDE clause is parsed but not supported
--echo #
......@@ -843,6 +872,9 @@ select
exclude group) as count
from t1;
# EXCLUDE NO OTHERS means 'don't exclude anything'
select
count(*) over (order by a
......
......@@ -1253,15 +1253,10 @@ insert into t1 values (1,1,'foo');
insert into t1 values (2,2,'bar');
select
count(*) over (order by a,b
range between unbounded preceding and current row) as count
range between 1 preceding and current row) as count
from t1;
ERROR HY000: RANGE-type frame requires ORDER BY clause with single sort key
select
count(*) over (order by c
range between unbounded preceding and current row) as count
from t1;
ERROR HY000: Numeric datatype is required for RANGE-type frame
select
count(*) over (order by a
range between 'abcd' preceding and current row) as count
from t1;
......@@ -1283,6 +1278,59 @@ rows between current row and 3.14 following) as count
from t1;
ERROR HY000: Integer is required for ROWS-type frame
#
# MDEV-19052 Range-type window frame supports only numeric datatype
#
select
count(*) over (order by c
range between unbounded preceding and current row)
from t1;
count(*) over (order by c
range between unbounded preceding and current row)
1
2
select
count(*) over (order by c
range between current row and unbounded following)
from t1;
count(*) over (order by c
range between current row and unbounded following)
2
1
select
count(*) over (order by c
range between unbounded preceding and unbounded following)
from t1;
count(*) over (order by c
range between unbounded preceding and unbounded following)
2
2
create table t2 (a int, b varchar(5));
insert into t2 values (1,'a'), (2, 'b'), (3, 'c');
select sum(a) over (order by b range between unbounded preceding and current row) from t2;
sum(a) over (order by b range between unbounded preceding and current row)
1
3
6
insert into t1 values (3,3,'goo');
insert into t1 values (3,1,'har');
insert into t1 values (1,4,'har');
select a, b, sum(b) over (order by a, b desc range between unbounded preceding and current row) from t1;
a b sum(b) over (order by a, b desc range between unbounded preceding and current row)
1 4 4
1 1 5
2 2 7
3 3 10
3 1 11
select a, b, sum(b) over (order by a desc, b range between unbounded preceding and current row) from t1;
a b sum(b) over (order by a desc, b range between unbounded preceding and current row)
3 1 1
3 3 4
2 2 6
1 1 7
1 4 11
drop table t2;
delete from t1 where a >= 3 or b = 4;
#
# EXCLUDE clause is parsed but not supported
#
select
......
......@@ -262,9 +262,12 @@ setup_windows(THD *thd, Ref_ptr_array ref_pointer_array, TABLE_LIST *tables,
For "win_func() OVER (ORDER BY order_list RANGE BETWEEN ...)",
- ORDER BY order_list must not be ommitted
- the list must have a single element.
But it really only matters if the frame is bounded.
*/
if (win_spec->window_frame &&
win_spec->window_frame->units == Window_frame::UNITS_RANGE)
win_spec->window_frame->units == Window_frame::UNITS_RANGE &&
!(win_spec->window_frame->top_bound->is_unbounded() &&
win_spec->window_frame->bottom_bound->is_unbounded()))
{
if (win_spec->order_list->elements != 1)
{
......
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