Commit 37925c6c authored by Igor Babaev's avatar Igor Babaev

Fixed bug mdev-9924.

Supported queries with window functions when GROUP BY could be
optimized away.
parent e688d814
...@@ -3075,3 +3075,24 @@ select count(distinct s) from (select sum(d) as s from t group by a) Z where s > ...@@ -3075,3 +3075,24 @@ select count(distinct s) from (select sum(d) as s from t group by a) Z where s >
count(distinct s) count(distinct s)
1 1
drop table t; drop table t;
#
# MDEV-9924: window function in query with group by optimized away
#
create table t1 (i int);
insert into t1 values (2),(3),(1);
select row_number() over () from t1 group by 1+2;
row_number() over ()
1
select max(i), row_number() over () from t1 group by 1+2;
max(i) row_number() over ()
3 1
select rank() over (order by max(i)) from t1 group by 1+2;
rank() over (order by max(i))
1
select i, row_number() over () from t1 group by 1+2;
i row_number() over ()
2 1
select i, rank() over (order by i) rnk from t1 group by 1+2;
i rnk
2 1
drop table t1;
...@@ -1793,3 +1793,19 @@ select count(distinct s) from (select sum(d) over(partition by a) as s from t) Z ...@@ -1793,3 +1793,19 @@ select count(distinct s) from (select sum(d) over(partition by a) as s from t) Z
select count(distinct s) from (select sum(d) as s from t group by a) Z where s > 0; select count(distinct s) from (select sum(d) as s from t group by a) Z where s > 0;
drop table t; drop table t;
--echo #
--echo # MDEV-9924: window function in query with group by optimized away
--echo #
create table t1 (i int);
insert into t1 values (2),(3),(1);
select row_number() over () from t1 group by 1+2;
select max(i), row_number() over () from t1 group by 1+2;
select rank() over (order by max(i)) from t1 group by 1+2;
select i, row_number() over () from t1 group by 1+2;
select i, rank() over (order by i) rnk from t1 group by 1+2;
drop table t1;
...@@ -2226,6 +2226,9 @@ bool JOIN::make_aggr_tables_info() ...@@ -2226,6 +2226,9 @@ bool JOIN::make_aggr_tables_info()
sort_and_group_aggr_tab= NULL; sort_and_group_aggr_tab= NULL;
if (group_optimized_away)
implicit_grouping= true;
bool implicit_grouping_with_window_funcs= implicit_grouping && bool implicit_grouping_with_window_funcs= implicit_grouping &&
select_lex->have_window_funcs(); select_lex->have_window_funcs();
...@@ -2574,7 +2577,7 @@ bool JOIN::make_aggr_tables_info() ...@@ -2574,7 +2577,7 @@ bool JOIN::make_aggr_tables_info()
tmp_table_param.copy_field= tmp_table_param.copy_field_end=0; tmp_table_param.copy_field= tmp_table_param.copy_field_end=0;
first_record= sort_and_group=0; first_record= sort_and_group=0;
if (!group_optimized_away) if (!group_optimized_away || implicit_grouping_with_window_funcs)
{ {
group= false; group= false;
} }
......
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